glib-File-Utilities.html   [plain text]


<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>File Utilities</title><meta name="generator" content="DocBook XSL Stylesheets V1.65.1"><link rel="home" href="index.html" title="GLib Reference Manual"><link rel="up" href="glib-utilities.html" title="GLib Utilities"><link rel="previous" href="glib-Spawning-Processes.html" title="Spawning Processes"><link rel="next" href="glib-Shell-related-Utilities.html" title="Shell-related Utilities"><link rel="chapter" href="glib.html" title="GLib Overview"><link rel="refentry" href="glib-building.html" title="Compiling the GLib package"><link rel="refentry" href="glib-cross-compiling.html" title="Cross-compiling the GLib package"><link rel="refentry" href="glib-compiling.html" title="Compiling GLib Applications"><link rel="refentry" href="glib-running.html" title="Running GLib Applications"><link rel="refentry" href="glib-changes.html" title="Changes to GLib"><link rel="refentry" href="glib-resources.html" title="Mailing lists and bug reports"><link rel="chapter" href="glib-fundamentals.html" title="GLib Fundamentals"><link rel="refentry" href="glib-Basic-Types.html" title="Basic Types"><link rel="refentry" href="glib-Limits-of-Basic-Types.html" title="Limits of Basic Types"><link rel="refentry" href="glib-Standard-Macros.html" title="Standard Macros"><link rel="refentry" href="glib-Type-Conversion-Macros.html" title="Type Conversion Macros"><link rel="refentry" href="glib-Byte-Order-Macros.html" title="Byte Order Macros"><link rel="refentry" href="glib-Numerical-Definitions.html" title="Numerical Definitions"><link rel="refentry" href="glib-Miscellaneous-Macros.html" title="Miscellaneous Macros"><link rel="refentry" href="glib-Atomic-Operations.html" title="Atomic Operations"><link rel="chapter" href="glib-core.html" title="GLib Core Application Support"><link rel="refentry" href="glib-The-Main-Event-Loop.html" title="The Main Event Loop"><link rel="refentry" href="glib-Threads.html" title="
Threads"><link rel="refentry" href="glib-Thread-Pools.html" title="Thread Pools"><link rel="refentry" href="glib-Asynchronous-Queues.html" title="Asynchronous Queues"><link rel="refentry" href="glib-Dynamic-Loading-of-Modules.html" title="Dynamic Loading of Modules"><link rel="refentry" href="glib-Memory-Allocation.html" title="Memory Allocation"><link rel="refentry" href="glib-IO-Channels.html" title="IO Channels"><link rel="refentry" href="glib-Error-Reporting.html" title="Error Reporting"><link rel="refentry" href="glib-Warnings-and-Assertions.html" title="Message Output and Debugging Functions"><link rel="refentry" href="glib-Message-Logging.html" title="Message Logging"><link rel="chapter" href="glib-utilities.html" title="GLib Utilities"><link rel="refentry" href="glib-String-Utility-Functions.html" title="String Utility Functions"><link rel="refentry" href="glib-Character-Set-Conversion.html" title="Character Set Conversion"><link rel="refentry" href="glib-Unicode-Manipulation.html" title="Unicode Manipulation"><link rel="refentry" href="glib-I18N.html" title="Internationalization"><link rel="refentry" href="glib-Date-and-Time-Functions.html" title="Date and Time Functions"><link rel="refentry" href="glib-Random-Numbers.html" title="Random Numbers"><link rel="refentry" href="glib-Hook-Functions.html" title="Hook Functions"><link rel="refentry" href="glib-Miscellaneous-Utility-Functions.html" title="Miscellaneous Utility Functions"><link rel="refentry" href="glib-Lexical-Scanner.html" title="Lexical Scanner"><link rel="refentry" href="glib-Automatic-String-Completion.html" title="Automatic String Completion"><link rel="refentry" href="glib-Timers.html" title="Timers"><link rel="refentry" href="glib-Spawning-Processes.html" title="Spawning Processes"><link rel="refentry" href="glib-File-Utilities.html" title="File Utilities"><link rel="refentry" href="glib-Shell-related-Utilities.html" title="Shell-related Utilities"><link rel="refentry" href="glib-Glob-style-pattern-matching.html" title="Glob-style pattern matching"><link rel="refentry" href="glib-Simple-XML-Subset-Parser.html" title="Simple XML Subset Parser"><link rel="refentry" href="glib-Windows-Compatability-Functions.html" title="Windows Compatibility Functions"><link rel="chapter" href="glib-data-types.html" title="GLib Data Types"><link rel="refentry" href="glib-Memory-Chunks.html" title="Memory Chunks"><link rel="refentry" href="glib-Doubly-Linked-Lists.html" title="Doubly-Linked Lists"><link rel="refentry" href="glib-Singly-Linked-Lists.html" title="Singly-Linked Lists"><link rel="refentry" href="glib-Double-ended-Queues.html" title="Double-ended Queues"><link rel="refentry" href="glib-Trash-Stacks.html" title="Trash Stacks"><link rel="refentry" href="glib-Hash-Tables.html" title="Hash Tables"><link rel="refentry" href="glib-Strings.html" title="Strings"><link rel="refentry" href="glib-String-Chunks.html" title="String Chunks"><link rel="refentry" href="glib-Arrays.html" title="Arrays"><link rel="refentry" href="glib-Pointer-Arrays.html" title="Pointer Arrays"><link rel="refentry" href="glib-Byte-Arrays.html" title="Byte Arrays"><link rel="refentry" href="glib-Balanced-Binary-Trees.html" title="Balanced Binary Trees"><link rel="refentry" href="glib-N-ary-Trees.html" title="N-ary Trees"><link rel="refentry" href="glib-Quarks.html" title="Quarks"><link rel="refentry" href="glib-Keyed-Data-Lists.html" title="Keyed Data Lists"><link rel="refentry" href="glib-Datasets.html" title="Datasets"><link rel="refentry" href="glib-Relations-and-Tuples.html" title="Relations and Tuples"><link rel="refentry" href="glib-Caches.html" title="Caches"><link rel="refentry" href="glib-Memory-Allocators.html" title="Memory Allocators"><link rel="chapter" href="tools.html" title="GLib Tools"><link rel="refentry" href="glib-gettextize.html" title="glib-gettextize"><link rel="index" href="ix01.html" title="Index"><link rel="section" href="glib-File-Utilities.html#id3213450" title="Description"><link rel="section" href="glib-File-Utilities.html#id3213460" title="Details"><meta name="generator" content="GTK-Doc V1.2 (XML mode)"><link rel="stylesheet" href="style.css" type="text/css"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table class="navigation" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2"><tr valign="middle"><td><a accesskey="p" href="glib-Spawning-Processes.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td><td><a accesskey="u" href="glib-utilities.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td><td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td><th width="100%" align="center">GLib Reference Manual</th><td><a accesskey="n" href="glib-Shell-related-Utilities.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td></tr></table><div class="refentry" lang="en"><a name="glib-File-Utilities"></a><div class="titlepage"><div></div><div></div></div><div class="refnamediv"><h2><span class="refentrytitle">File Utilities</span></h2><p>File Utilities &#8212; various file-related functions.</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">

#include &lt;glib.h&gt;


enum        <a href="glib-File-Utilities.html#GFileError">GFileError</a>;
#define     <a href="glib-File-Utilities.html#G-FILE-ERROR-CAPS">G_FILE_ERROR</a>
enum        <a href="glib-File-Utilities.html#GFileTest">GFileTest</a>;
<a href="glib-File-Utilities.html#GFileError">GFileError</a>  <a href="glib-File-Utilities.html#g-file-error-from-errno">g_file_error_from_errno</a>         (<a href="glib-Basic-Types.html#gint">gint</a> err_no);
<a href="glib-Basic-Types.html#gboolean">gboolean</a>    <a href="glib-File-Utilities.html#g-file-get-contents">g_file_get_contents</a>             (const <a href="glib-Basic-Types.html#gchar">gchar</a> *filename,
                                             <a href="glib-Basic-Types.html#gchar">gchar</a> **contents,
                                             <a href="glib-Basic-Types.html#gsize">gsize</a> *length,
                                             <a href="glib-Error-Reporting.html#GError">GError</a> **error);
<a href="glib-Basic-Types.html#gboolean">gboolean</a>    <a href="glib-File-Utilities.html#g-file-test">g_file_test</a>                     (const <a href="glib-Basic-Types.html#gchar">gchar</a> *filename,
                                             <a href="glib-File-Utilities.html#GFileTest">GFileTest</a> test);
<a href="glib-Basic-Types.html#gint">gint</a>        <a href="glib-File-Utilities.html#g-mkstemp">g_mkstemp</a>                       (<a href="glib-Basic-Types.html#gchar">gchar</a> *tmpl);
<a href="glib-Basic-Types.html#gint">gint</a>        <a href="glib-File-Utilities.html#g-file-open-tmp">g_file_open_tmp</a>                 (const <a href="glib-Basic-Types.html#gchar">gchar</a> *tmpl,
                                             <a href="glib-Basic-Types.html#gchar">gchar</a> **name_used,
                                             <a href="glib-Error-Reporting.html#GError">GError</a> **error);
<a href="glib-Basic-Types.html#gchar">gchar</a>*      <a href="glib-File-Utilities.html#g-file-read-link">g_file_read_link</a>                (const <a href="glib-Basic-Types.html#gchar">gchar</a> *filename,
                                             <a href="glib-Error-Reporting.html#GError">GError</a> **error);

struct      <a href="glib-File-Utilities.html#GDir">GDir</a>;
<a href="glib-File-Utilities.html#GDir">GDir</a>*       <a href="glib-File-Utilities.html#g-dir-open">g_dir_open</a>                      (const <a href="glib-Basic-Types.html#gchar">gchar</a> *path,
                                             <a href="glib-Basic-Types.html#guint">guint</a> flags,
                                             <a href="glib-Error-Reporting.html#GError">GError</a> **error);
G_CONST_RETURN <a href="glib-Basic-Types.html#gchar">gchar</a>* <a href="glib-File-Utilities.html#g-dir-read-name">g_dir_read_name</a>       (<a href="glib-File-Utilities.html#GDir">GDir</a> *dir);
void        <a href="glib-File-Utilities.html#g-dir-rewind">g_dir_rewind</a>                    (<a href="glib-File-Utilities.html#GDir">GDir</a> *dir);
void        <a href="glib-File-Utilities.html#g-dir-close">g_dir_close</a>                     (<a href="glib-File-Utilities.html#GDir">GDir</a> *dir);

</pre></div><div class="refsect1" lang="en"><a name="id3213450"></a><h2>Description</h2><p>

</p></div><div class="refsect1" lang="en"><a name="id3213460"></a><h2>Details</h2><div class="refsect2" lang="en"><a name="id3213466"></a><h3><a name="GFileError"></a>enum GFileError</h3><a class="indexterm" name="id3213477"></a><pre class="programlisting">typedef enum
{
  G_FILE_ERROR_EXIST,
  G_FILE_ERROR_ISDIR,
  G_FILE_ERROR_ACCES,
  G_FILE_ERROR_NAMETOOLONG,
  G_FILE_ERROR_NOENT,
  G_FILE_ERROR_NOTDIR,
  G_FILE_ERROR_NXIO,
  G_FILE_ERROR_NODEV,
  G_FILE_ERROR_ROFS,
  G_FILE_ERROR_TXTBSY,
  G_FILE_ERROR_FAULT,
  G_FILE_ERROR_LOOP,
  G_FILE_ERROR_NOSPC,
  G_FILE_ERROR_NOMEM,
  G_FILE_ERROR_MFILE,
  G_FILE_ERROR_NFILE,
  G_FILE_ERROR_BADF,
  G_FILE_ERROR_INVAL,
  G_FILE_ERROR_PIPE,
  G_FILE_ERROR_AGAIN,
  G_FILE_ERROR_INTR,
  G_FILE_ERROR_IO,
  G_FILE_ERROR_PERM,
  G_FILE_ERROR_FAILED
} GFileError;
</pre><p>
Values corresponding to <tt class="literal">errno</tt> codes returned from file operations
on UNIX. Unlike <tt class="literal">errno</tt> codes, <a href="glib-File-Utilities.html#GFileError"><span class="type">GFileError</span></a> values are available on 
all systems, even Windows. The exact meaning of each code depends on what
sort of file operation you were performing; the UNIX documentation
gives more details. The following error code descriptions come 
from the GNU C Library manual, and are under the copyright
of that manual.
</p><p>
It's not very portable to make detailed assumptions about exactly
which errors will be returned from a given operation. Some errors
don't occur on some systems, etc., sometimes there are subtle
differences in when a system will report a given error, etc.
</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><tt class="literal">G_FILE_ERROR_EXIST</tt></span></td><td>Operation not permitted; only the owner of the
     file (or other resource) or processes with special privileges can
     perform the operation.
</td></tr><tr><td><span class="term"><tt class="literal">G_FILE_ERROR_ISDIR</tt></span></td><td>File is a directory; you cannot open a directory
     for writing, or create or remove hard links to it.
</td></tr><tr><td><span class="term"><tt class="literal">G_FILE_ERROR_ACCES</tt></span></td><td>Permission denied; the file permissions do not
     allow the attempted operation.
</td></tr><tr><td><span class="term"><tt class="literal">G_FILE_ERROR_NAMETOOLONG</tt></span></td><td>Filename too long.
</td></tr><tr><td><span class="term"><tt class="literal">G_FILE_ERROR_NOENT</tt></span></td><td>No such file or directory.  This is a "file
     doesn't exist" error for ordinary files that are referenced in
     contexts where they are expected to already exist.
</td></tr><tr><td><span class="term"><tt class="literal">G_FILE_ERROR_NOTDIR</tt></span></td><td>A file that isn't a directory was specified when
     a directory is required.
</td></tr><tr><td><span class="term"><tt class="literal">G_FILE_ERROR_NXIO</tt></span></td><td>No such device or address.  The system tried to
     use the device represented by a file you specified, and it
     couldn't find the device.  This can mean that the device file was
     installed incorrectly, or that the physical device is missing or
     not correctly attached to the computer.
</td></tr><tr><td><span class="term"><tt class="literal">G_FILE_ERROR_NODEV</tt></span></td><td>This file is of a type that doesn't support
     mapping.
</td></tr><tr><td><span class="term"><tt class="literal">G_FILE_ERROR_ROFS</tt></span></td><td>The directory containing the new link can't be
          modified because it's on a read-only file system.
</td></tr><tr><td><span class="term"><tt class="literal">G_FILE_ERROR_TXTBSY</tt></span></td><td>Text file busy.
</td></tr><tr><td><span class="term"><tt class="literal">G_FILE_ERROR_FAULT</tt></span></td><td>You passed in a pointer to bad memory.
  (GLib won't reliably return this, don't pass in pointers to bad
  memory.)
</td></tr><tr><td><span class="term"><tt class="literal">G_FILE_ERROR_LOOP</tt></span></td><td>Too many levels of symbolic links were encountered
  in looking up a file name.  This often indicates a cycle of symbolic
  links.
</td></tr><tr><td><span class="term"><tt class="literal">G_FILE_ERROR_NOSPC</tt></span></td><td>No space left on device; write operation on a
  file failed because the disk is full.
</td></tr><tr><td><span class="term"><tt class="literal">G_FILE_ERROR_NOMEM</tt></span></td><td>No memory available.  The system cannot allocate
     more virtual memory because its capacity is full.
</td></tr><tr><td><span class="term"><tt class="literal">G_FILE_ERROR_MFILE</tt></span></td><td>The current process has too many files open and
     can't open any more.  Duplicate descriptors do count toward this
     limit.
</td></tr><tr><td><span class="term"><tt class="literal">G_FILE_ERROR_NFILE</tt></span></td><td>There are too many distinct file openings in the
     entire system.
</td></tr><tr><td><span class="term"><tt class="literal">G_FILE_ERROR_BADF</tt></span></td><td>Bad file descriptor; for example, I/O on a
     descriptor that has been closed or reading from a descriptor open
     only for writing (or vice versa).
</td></tr><tr><td><span class="term"><tt class="literal">G_FILE_ERROR_INVAL</tt></span></td><td>Invalid argument.  This is used to indicate
     various kinds of problems with passing the wrong argument to a
     library function.
</td></tr><tr><td><span class="term"><tt class="literal">G_FILE_ERROR_PIPE</tt></span></td><td>Broken pipe; there is no process reading from the
     other end of a pipe.  Every library function that returns this
     error code also generates a `SIGPIPE' signal; this signal
     terminates the program if not handled or blocked.  Thus, your
     program will never actually see this code unless it has handled or
     blocked `SIGPIPE'.
</td></tr><tr><td><span class="term"><tt class="literal">G_FILE_ERROR_AGAIN</tt></span></td><td>Resource temporarily unavailable; the call might
     work if you try again later.
</td></tr><tr><td><span class="term"><tt class="literal">G_FILE_ERROR_INTR</tt></span></td><td>Interrupted function call; an asynchronous signal
     occurred and prevented completion of the call.  When this
     happens, you should try the call again.
</td></tr><tr><td><span class="term"><tt class="literal">G_FILE_ERROR_IO</tt></span></td><td>Input/output error; usually used for physical read
    or write errors. i.e. the disk or other physical device hardware
    is returning errors.
</td></tr><tr><td><span class="term"><tt class="literal">G_FILE_ERROR_PERM</tt></span></td><td>Operation not permitted; only the owner of the
     file (or other resource) or processes with special privileges can
     perform the operation.
</td></tr><tr><td><span class="term"><tt class="literal">G_FILE_ERROR_FAILED</tt></span></td><td>Does not correspond to a UNIX error code; this
  is the standard "failed for unspecified reason" error code present in 
  all <a href="glib-Error-Reporting.html#GError"><span class="type">GError</span></a> error code enumerations. Returned if no specific
  code applies.

</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3213946"></a><h3><a name="G-FILE-ERROR-CAPS"></a>G_FILE_ERROR</h3><a class="indexterm" name="id3213957"></a><pre class="programlisting">#define G_FILE_ERROR g_file_error_quark ()
</pre><p>
Error domain for file operations. Errors in this domain will
be from the <a href="glib-File-Utilities.html#GFileError"><span class="type">GFileError</span></a> enumeration. See <a href="glib-Error-Reporting.html#GError"><span class="type">GError</span></a> for information on 
error domains.
</p></div><hr><div class="refsect2" lang="en"><a name="id3213991"></a><h3><a name="GFileTest"></a>enum GFileTest</h3><a class="indexterm" name="id3214002"></a><pre class="programlisting">typedef enum
{
  G_FILE_TEST_IS_REGULAR    = 1 &lt;&lt; 0,
  G_FILE_TEST_IS_SYMLINK    = 1 &lt;&lt; 1,
  G_FILE_TEST_IS_DIR        = 1 &lt;&lt; 2,
  G_FILE_TEST_IS_EXECUTABLE = 1 &lt;&lt; 3,
  G_FILE_TEST_EXISTS        = 1 &lt;&lt; 4
} GFileTest;
</pre><p>
A test to perform an a file using <a href="glib-File-Utilities.html#g-file-test"><tt class="function">g_file_test()</tt></a>.
</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><tt class="literal">G_FILE_TEST_IS_REGULAR</tt></span></td><td><tt class="literal">TRUE</tt> if the file is a regular file (not a symlink or directory)
</td></tr><tr><td><span class="term"><tt class="literal">G_FILE_TEST_IS_SYMLINK</tt></span></td><td><tt class="literal">TRUE</tt> if the file is a symlink.
</td></tr><tr><td><span class="term"><tt class="literal">G_FILE_TEST_IS_DIR</tt></span></td><td><tt class="literal">TRUE</tt> if the file is a directory.
</td></tr><tr><td><span class="term"><tt class="literal">G_FILE_TEST_IS_EXECUTABLE</tt></span></td><td><tt class="literal">TRUE</tt> if the file is executable.
</td></tr><tr><td><span class="term"><tt class="literal">G_FILE_TEST_EXISTS</tt></span></td><td><tt class="literal">TRUE</tt> if the file exists. It may or may not be a regular file.

</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3214136"></a><h3><a name="g-file-error-from-errno"></a>g_file_error_from_errno ()</h3><a class="indexterm" name="id3214147"></a><pre class="programlisting"><a href="glib-File-Utilities.html#GFileError">GFileError</a>  g_file_error_from_errno         (<a href="glib-Basic-Types.html#gint">gint</a> err_no);</pre><p>
Gets a <a href="glib-File-Utilities.html#GFileError"><span class="type">GFileError</span></a> constant based on the passed-in <i class="parameter"><tt>errno</tt></i>.
For example, if you pass in <tt class="literal">EEXIST</tt> this function returns
<span class="type">G_FILE_ERROR_EXIST</span>. Unlike <i class="parameter"><tt>errno</tt></i> values, you can portably
assume that all <a href="glib-File-Utilities.html#GFileError"><span class="type">GFileError</span></a> values will exist.
</p><p>
Normally a <a href="glib-File-Utilities.html#GFileError"><span class="type">GFileError</span></a> value goes into a <a href="glib-Error-Reporting.html#GError"><span class="type">GError</span></a> returned
from a function that manipulates files. So you would use
<a href="glib-File-Utilities.html#g-file-error-from-errno"><tt class="function">g_file_error_from_errno()</tt></a> when constructing a <a href="glib-Error-Reporting.html#GError"><span class="type">GError</span></a>.</p><p>

</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><i class="parameter"><tt>err_no</tt></i> :</span></td><td> an "errno" value
</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td> <a href="glib-File-Utilities.html#GFileError"><span class="type">GFileError</span></a> corresponding to the given <i class="parameter"><tt>errno</tt></i>
</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3214307"></a><h3><a name="g-file-get-contents"></a>g_file_get_contents ()</h3><a class="indexterm" name="id3214318"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gboolean">gboolean</a>    g_file_get_contents             (const <a href="glib-Basic-Types.html#gchar">gchar</a> *filename,
                                             <a href="glib-Basic-Types.html#gchar">gchar</a> **contents,
                                             <a href="glib-Basic-Types.html#gsize">gsize</a> *length,
                                             <a href="glib-Error-Reporting.html#GError">GError</a> **error);</pre><p>
Reads an entire file into allocated memory, with good error
checking. If <i class="parameter"><tt>error</tt></i> is set, <tt class="literal">FALSE</tt> is returned, and <i class="parameter"><tt>contents</tt></i> is set
to <tt class="literal">NULL</tt>. If <tt class="literal">TRUE</tt> is returned, <i class="parameter"><tt>error</tt></i> will not be set, and <i class="parameter"><tt>contents</tt></i>
will be set to the file contents.  The string stored in <i class="parameter"><tt>contents</tt></i>
will be nul-terminated, so for text files you can pass <tt class="literal">NULL</tt> for the
<i class="parameter"><tt>length</tt></i> argument.  The error domain is <a href="glib-File-Utilities.html#G-FILE-ERROR-CAPS"><span class="type">G_FILE_ERROR</span></a>. Possible
error codes are those in the <a href="glib-File-Utilities.html#GFileError"><span class="type">GFileError</span></a> enumeration.</p><p>

</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><i class="parameter"><tt>filename</tt></i> :</span></td><td> a file to read contents from
</td></tr><tr><td><span class="term"><i class="parameter"><tt>contents</tt></i> :</span></td><td> location to store an allocated string
</td></tr><tr><td><span class="term"><i class="parameter"><tt>length</tt></i> :</span></td><td> location to store length in bytes of the contents
</td></tr><tr><td><span class="term"><i class="parameter"><tt>error</tt></i> :</span></td><td> return location for a <a href="glib-Error-Reporting.html#GError"><span class="type">GError</span></a>
</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td> <tt class="literal">TRUE</tt> on success, <tt class="literal">FALSE</tt> if error is set
</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3214544"></a><h3><a name="g-file-test"></a>g_file_test ()</h3><a class="indexterm" name="id3214555"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gboolean">gboolean</a>    g_file_test                     (const <a href="glib-Basic-Types.html#gchar">gchar</a> *filename,
                                             <a href="glib-File-Utilities.html#GFileTest">GFileTest</a> test);</pre><p>
Returns <tt class="literal">TRUE</tt> if any of the tests in the bitfield <i class="parameter"><tt>test</tt></i> are
<tt class="literal">TRUE</tt>. For example, <tt class="literal">(G_FILE_TEST_EXISTS | 
G_FILE_TEST_IS_DIR)</tt> will return <tt class="literal">TRUE</tt> if the file exists; 
the check whether it's a directory doesn't matter since the existence 
test is <tt class="literal">TRUE</tt>. With the current set of available tests, there's no point
passing in more than one test at a time.
</p><p>
Apart from <tt class="literal">G_FILE_TEST_IS_SYMLINK</tt> all tests follow symbolic links,
so for a symbolic link to a regular file <a href="glib-File-Utilities.html#g-file-test"><tt class="function">g_file_test()</tt></a> will return
<tt class="literal">TRUE</tt> for both <tt class="literal">G_FILE_TEST_IS_SYMLINK</tt> and <tt class="literal">G_FILE_TEST_IS_REGULAR</tt>.
</p><p>
Note, that for a dangling symbolic link <a href="glib-File-Utilities.html#g-file-test"><tt class="function">g_file_test()</tt></a> will return
<tt class="literal">TRUE</tt> for <tt class="literal">G_FILE_TEST_IS_SYMLINK</tt> and <tt class="literal">FALSE</tt> for all other flags.
</p><p>
You should never use <a href="glib-File-Utilities.html#g-file-test"><tt class="function">g_file_test()</tt></a> to test whether it is safe
to perform an operaton, because there is always the possibility
of the condition changing before you actually perform the operation.
For example, you might think you could use <tt class="literal">G_FILE_TEST_IS_SYMLINK</tt>
to know whether it is is safe to write to a file without being
tricked into writing into a different location. It doesn't work!
</p><p>
</p><div class="informalexample"><pre class="programlisting">
/* DON'T DO THIS */
 if (!g_file_test (filename, G_FILE_TEST_IS_SYMLINK)) {
   fd = open (filename, O_WRONLY);
   /* write to fd */
 }
</pre></div><p>
</p><p>
Another thing to note is that <tt class="literal">G_FILE_TEST_EXISTS</tt> and
<tt class="literal">G_FILE_TEST_IS_EXECUTABLE</tt> are implemented using the <tt class="function">access()</tt>
system call. This usually doesn't matter, but if your program
is setuid or setgid it means that these tests will give you
the answer for the real user ID and group ID , rather than the
effective user ID and group ID.</p><p>

</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><i class="parameter"><tt>filename</tt></i> :</span></td><td> a filename to test
</td></tr><tr><td><span class="term"><i class="parameter"><tt>test</tt></i> :</span></td><td> bitfield of <a href="glib-File-Utilities.html#GFileTest"><span class="type">GFileTest</span></a> flags
</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td> whether a test was <tt class="literal">TRUE</tt>
</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3214836"></a><h3><a name="g-mkstemp"></a>g_mkstemp ()</h3><a class="indexterm" name="id3214847"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gint">gint</a>        g_mkstemp                       (<a href="glib-Basic-Types.html#gchar">gchar</a> *tmpl);</pre><p>
Opens a temporary file. See the <tt class="function">mkstemp()</tt> documentation
on most UNIX-like systems. This is a portability wrapper, which simply calls 
<tt class="function">mkstemp()</tt> on systems that have it, and implements 
it in GLib otherwise.
</p><p>
The parameter is a string that should match the rules for
<tt class="function">mkstemp()</tt>, i.e. end in "XXXXXX". The X string will 
be modified to form the name of a file that didn't exist.</p><p>

</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><i class="parameter"><tt>tmpl</tt></i> :</span></td><td> template filename
</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td> A file handle (as from <tt class="function">open()</tt>) to the file
opened for reading and writing. The file is opened in binary mode
on platforms where there is a difference. The file handle should be
closed with <tt class="function">close()</tt>. In case of errors, -1 is returned.
</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3214972"></a><h3><a name="g-file-open-tmp"></a>g_file_open_tmp ()</h3><a class="indexterm" name="id3214983"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gint">gint</a>        g_file_open_tmp                 (const <a href="glib-Basic-Types.html#gchar">gchar</a> *tmpl,
                                             <a href="glib-Basic-Types.html#gchar">gchar</a> **name_used,
                                             <a href="glib-Error-Reporting.html#GError">GError</a> **error);</pre><p>
Opens a file for writing in the preferred directory for temporary
files (as returned by <a href="glib-Miscellaneous-Utility-Functions.html#g-get-tmp-dir"><tt class="function">g_get_tmp_dir()</tt></a>). 
</p><p>
<i class="parameter"><tt>tmpl</tt></i> should be a string ending with six 'X' characters, as the
parameter to <a href="glib-File-Utilities.html#g-mkstemp"><tt class="function">g_mkstemp()</tt></a> (or <tt class="function">mkstemp()</tt>). 
However, unlike these functions, the template should only be a 
basename, no directory components are allowed. If template is <tt class="literal">NULL</tt>, 
a default template is used.
</p><p>
Note that in contrast to <a href="glib-File-Utilities.html#g-mkstemp"><tt class="function">g_mkstemp()</tt></a> (and <tt class="function">mkstemp()</tt>) 
<i class="parameter"><tt>tmpl</tt></i> is not modified, and might thus be a read-only literal string.
</p><p>
The actual name used is returned in <i class="parameter"><tt>name_used</tt></i> if non-<tt class="literal">NULL</tt>. This
string should be freed with <a href="glib-Memory-Allocation.html#g-free"><tt class="function">g_free()</tt></a> when not needed any longer.</p><p>

</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><i class="parameter"><tt>tmpl</tt></i> :</span></td><td> Template for file name, as in <a href="glib-File-Utilities.html#g-mkstemp"><tt class="function">g_mkstemp()</tt></a>, basename only
</td></tr><tr><td><span class="term"><i class="parameter"><tt>name_used</tt></i> :</span></td><td> location to store actual name used
</td></tr><tr><td><span class="term"><i class="parameter"><tt>error</tt></i> :</span></td><td> return location for a <a href="glib-Error-Reporting.html#GError"><span class="type">GError</span></a>
</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td> A file handle (as from <tt class="function">open()</tt>) to 
the file opened for reading and writing. The file is opened in binary 
mode on platforms where there is a difference. The file handle should be
closed with <tt class="function">close()</tt>. In case of errors, -1 is returned 
and <i class="parameter"><tt>error</tt></i> will be set.
</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3215244"></a><h3><a name="g-file-read-link"></a>g_file_read_link ()</h3><a class="indexterm" name="id3215255"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gchar">gchar</a>*      g_file_read_link                (const <a href="glib-Basic-Types.html#gchar">gchar</a> *filename,
                                             <a href="glib-Error-Reporting.html#GError">GError</a> **error);</pre><p>
Reads the contents of the symbolic link <i class="parameter"><tt>filename</tt></i> like the POSIX <tt class="function">readlink()</tt> function.
The returned string is in the encoding used for filenames. Use <a href="glib-Character-Set-Conversion.html#g-filename-to-utf8"><tt class="function">g_filename_to_utf8()</tt></a> to 
convert it to UTF-8.</p><p>

</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><i class="parameter"><tt>filename</tt></i> :</span></td><td> the symbolic link
</td></tr><tr><td><span class="term"><i class="parameter"><tt>error</tt></i> :</span></td><td> return location for a <a href="glib-Error-Reporting.html#GError"><span class="type">GError</span></a>
</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td> A newly allocated string with the contents of the symbolic link, 
         or <tt class="literal">NULL</tt> if an error occurred.

</td></tr></tbody></table></div><p>Since  2.4
</p></div><hr><div class="refsect2" lang="en"><a name="id3215386"></a><h3><a name="GDir"></a>struct GDir</h3><a class="indexterm" name="id3215397"></a><pre class="programlisting">struct GDir;</pre><p>
An opaque structure representing an opened directory.
</p></div><hr><div class="refsect2" lang="en"><a name="id3215413"></a><h3><a name="g-dir-open"></a>g_dir_open ()</h3><a class="indexterm" name="id3215424"></a><pre class="programlisting"><a href="glib-File-Utilities.html#GDir">GDir</a>*       g_dir_open                      (const <a href="glib-Basic-Types.html#gchar">gchar</a> *path,
                                             <a href="glib-Basic-Types.html#guint">guint</a> flags,
                                             <a href="glib-Error-Reporting.html#GError">GError</a> **error);</pre><p>
Opens a directory for reading. The names of the files
in the directory can then be retrieved using
<a href="glib-File-Utilities.html#g-dir-read-name"><tt class="function">g_dir_read_name()</tt></a>.</p><p>

</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><i class="parameter"><tt>path</tt></i> :</span></td><td> the path to the directory you are interested in
</td></tr><tr><td><span class="term"><i class="parameter"><tt>flags</tt></i> :</span></td><td> Currently must be set to 0. Reserved for future use.
</td></tr><tr><td><span class="term"><i class="parameter"><tt>error</tt></i> :</span></td><td> return location for a <a href="glib-Error-Reporting.html#GError"><span class="type">GError</span></a>, or <tt class="literal">NULL</tt>.
        If non-<tt class="literal">NULL</tt>, an error will be set if and only if
        g_dir_open_fails.
</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td> a newly allocated <a href="glib-File-Utilities.html#GDir"><span class="type">GDir</span></a> on success, <tt class="literal">NULL</tt> on failure.
  If non-<tt class="literal">NULL</tt>, you must free the result with <a href="glib-File-Utilities.html#g-dir-close"><tt class="function">g_dir_close()</tt></a>
  when you are finished with it.
</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3215593"></a><h3><a name="g-dir-read-name"></a>g_dir_read_name ()</h3><a class="indexterm" name="id3215604"></a><pre class="programlisting">G_CONST_RETURN <a href="glib-Basic-Types.html#gchar">gchar</a>* g_dir_read_name       (<a href="glib-File-Utilities.html#GDir">GDir</a> *dir);</pre><p>
Retrieves the name of the next entry in the directory.
The '.' and '..' entries are omitted. The returned name is in 
the encoding used for filenames. Use <a href="glib-Character-Set-Conversion.html#g-filename-to-utf8"><tt class="function">g_filename_to_utf8()</tt></a> to 
convert it to UTF-8.</p><p>

</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><i class="parameter"><tt>dir</tt></i> :</span></td><td> a <a href="glib-File-Utilities.html#GDir"><span class="type">GDir</span></a>* created by <a href="glib-File-Utilities.html#g-dir-open"><tt class="function">g_dir_open()</tt></a>
</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td> The entries name or <tt class="literal">NULL</tt> if there are no 
  more entries. The return value is owned by GLib and
  must not be modified or freed.
</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3215704"></a><h3><a name="g-dir-rewind"></a>g_dir_rewind ()</h3><a class="indexterm" name="id3215715"></a><pre class="programlisting">void        g_dir_rewind                    (<a href="glib-File-Utilities.html#GDir">GDir</a> *dir);</pre><p>
Resets the given directory. The next call to <a href="glib-File-Utilities.html#g-dir-read-name"><tt class="function">g_dir_read_name()</tt></a>
will return the first entry again.</p><p>

</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><i class="parameter"><tt>dir</tt></i> :</span></td><td> a <a href="glib-File-Utilities.html#GDir"><span class="type">GDir</span></a>* created by <a href="glib-File-Utilities.html#g-dir-open"><tt class="function">g_dir_open()</tt></a>
</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3215794"></a><h3><a name="g-dir-close"></a>g_dir_close ()</h3><a class="indexterm" name="id3215805"></a><pre class="programlisting">void        g_dir_close                     (<a href="glib-File-Utilities.html#GDir">GDir</a> *dir);</pre><p>
Closes the directory and deallocates all related resources.</p><p>

</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><i class="parameter"><tt>dir</tt></i> :</span></td><td> a <a href="glib-File-Utilities.html#GDir"><span class="type">GDir</span></a>* created by <a href="glib-File-Utilities.html#g-dir-open"><tt class="function">g_dir_open()</tt></a>
</td></tr></tbody></table></div></div></div></div><table class="navigation" width="100%" summary="Navigation footer" cellpadding="2" cellspacing="0"><tr valign="middle"><td align="left"><a accesskey="p" href="glib-Spawning-Processes.html"><b>&lt;&lt; Spawning Processes</b></a></td><td align="right"><a accesskey="n" href="glib-Shell-related-Utilities.html"><b>Shell-related Utilities &gt;&gt;</b></a></td></tr></table></body></html>