fileutils.xml   [plain text]


<refentry id="glib-File-Utilities">
<refmeta>
<refentrytitle>File Utilities</refentrytitle>
<manvolnum>3</manvolnum>
<refmiscinfo>GLIB Library</refmiscinfo>
</refmeta>

<refnamediv>
<refname>File Utilities</refname><refpurpose>various file-related functions.</refpurpose>
</refnamediv>

<refsynopsisdiv><title>Synopsis</title>

<synopsis>

#include &lt;glib.h&gt;


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

struct      <link linkend="GDir">GDir</link>;
<link linkend="GDir">GDir</link>*       <link linkend="g-dir-open">g_dir_open</link>                      (const <link linkend="gchar">gchar</link> *path,
                                             <link linkend="guint">guint</link> flags,
                                             <link linkend="GError">GError</link> **error);
G_CONST_RETURN <link linkend="gchar">gchar</link>* <link linkend="g-dir-read-name">g_dir_read_name</link>       (<link linkend="GDir">GDir</link> *dir);
<link linkend="void">void</link>        <link linkend="g-dir-rewind">g_dir_rewind</link>                    (<link linkend="GDir">GDir</link> *dir);
<link linkend="void">void</link>        <link linkend="g-dir-close">g_dir_close</link>                     (<link linkend="GDir">GDir</link> *dir);

</synopsis>
</refsynopsisdiv>









<refsect1>
<title>Description</title>
<para>

</para>
</refsect1>

<refsect1>
<title>Details</title>
<refsect2>
<title><anchor id="GFileError"/>enum GFileError</title>
<indexterm><primary>GFileError</primary></indexterm><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;
</programlisting>
<para>
Values corresponding to <literal>errno</literal> codes returned from file operations
on UNIX. Unlike <literal>errno</literal> codes, <link linkend="GFileError"><type>GFileError</type></link> 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.
</para>

<para>
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.
</para><variablelist role="enum">
<varlistentry>
<term><literal>G_FILE_ERROR_EXIST</literal></term>
<listitem><simpara>Operation not permitted; only the owner of the
     file (or other resource) or processes with special privileges can
     perform the operation.
</simpara></listitem>
</varlistentry>
<varlistentry>
<term><literal>G_FILE_ERROR_ISDIR</literal></term>
<listitem><simpara>File is a directory; you cannot open a directory
     for writing, or create or remove hard links to it.
</simpara></listitem>
</varlistentry>
<varlistentry>
<term><literal>G_FILE_ERROR_ACCES</literal></term>
<listitem><simpara>Permission denied; the file permissions do not
     allow the attempted operation.
</simpara></listitem>
</varlistentry>
<varlistentry>
<term><literal>G_FILE_ERROR_NAMETOOLONG</literal></term>
<listitem><simpara>Filename too long.
</simpara></listitem>
</varlistentry>
<varlistentry>
<term><literal>G_FILE_ERROR_NOENT</literal></term>
<listitem><simpara>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.
</simpara></listitem>
</varlistentry>
<varlistentry>
<term><literal>G_FILE_ERROR_NOTDIR</literal></term>
<listitem><simpara>A file that isn't a directory was specified when
     a directory is required.
</simpara></listitem>
</varlistentry>
<varlistentry>
<term><literal>G_FILE_ERROR_NXIO</literal></term>
<listitem><simpara>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.
</simpara></listitem>
</varlistentry>
<varlistentry>
<term><literal>G_FILE_ERROR_NODEV</literal></term>
<listitem><simpara>This file is of a type that doesn't support
     mapping.
</simpara></listitem>
</varlistentry>
<varlistentry>
<term><literal>G_FILE_ERROR_ROFS</literal></term>
<listitem><simpara>The directory containing the new link can't be
          modified because it's on a read-only file system.
</simpara></listitem>
</varlistentry>
<varlistentry>
<term><literal>G_FILE_ERROR_TXTBSY</literal></term>
<listitem><simpara>Text file busy.
</simpara></listitem>
</varlistentry>
<varlistentry>
<term><literal>G_FILE_ERROR_FAULT</literal></term>
<listitem><simpara>You passed in a pointer to bad memory.
  (GLib won't reliably return this, don't pass in pointers to bad
  memory.)
</simpara></listitem>
</varlistentry>
<varlistentry>
<term><literal>G_FILE_ERROR_LOOP</literal></term>
<listitem><simpara>Too many levels of symbolic links were encountered
  in looking up a file name.  This often indicates a cycle of symbolic
  links.
</simpara></listitem>
</varlistentry>
<varlistentry>
<term><literal>G_FILE_ERROR_NOSPC</literal></term>
<listitem><simpara>No space left on device; write operation on a
  file failed because the disk is full.
</simpara></listitem>
</varlistentry>
<varlistentry>
<term><literal>G_FILE_ERROR_NOMEM</literal></term>
<listitem><simpara>No memory available.  The system cannot allocate
     more virtual memory because its capacity is full.
</simpara></listitem>
</varlistentry>
<varlistentry>
<term><literal>G_FILE_ERROR_MFILE</literal></term>
<listitem><simpara>The current process has too many files open and
     can't open any more.  Duplicate descriptors do count toward this
     limit.
</simpara></listitem>
</varlistentry>
<varlistentry>
<term><literal>G_FILE_ERROR_NFILE</literal></term>
<listitem><simpara>There are too many distinct file openings in the
     entire system.
</simpara></listitem>
</varlistentry>
<varlistentry>
<term><literal>G_FILE_ERROR_BADF</literal></term>
<listitem><simpara>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).
</simpara></listitem>
</varlistentry>
<varlistentry>
<term><literal>G_FILE_ERROR_INVAL</literal></term>
<listitem><simpara>Invalid argument.  This is used to indicate
     various kinds of problems with passing the wrong argument to a
     library function.
</simpara></listitem>
</varlistentry>
<varlistentry>
<term><literal>G_FILE_ERROR_PIPE</literal></term>
<listitem><simpara>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'.
</simpara></listitem>
</varlistentry>
<varlistentry>
<term><literal>G_FILE_ERROR_AGAIN</literal></term>
<listitem><simpara>Resource temporarily unavailable; the call might
     work if you try again later.
</simpara></listitem>
</varlistentry>
<varlistentry>
<term><literal>G_FILE_ERROR_INTR</literal></term>
<listitem><simpara>Interrupted function call; an asynchronous signal
     occurred and prevented completion of the call.  When this
     happens, you should try the call again.
</simpara></listitem>
</varlistentry>
<varlistentry>
<term><literal>G_FILE_ERROR_IO</literal></term>
<listitem><simpara>Input/output error; usually used for physical read
    or write errors. i.e. the disk or other physical device hardware
    is returning errors.
</simpara></listitem>
</varlistentry>
<varlistentry>
<term><literal>G_FILE_ERROR_PERM</literal></term>
<listitem><simpara>Operation not permitted; only the owner of the
     file (or other resource) or processes with special privileges can
     perform the operation.
</simpara></listitem>
</varlistentry>
<varlistentry>
<term><literal>G_FILE_ERROR_FAILED</literal></term>
<listitem><simpara>Does not correspond to a UNIX error code; this
  is the standard "failed for unspecified reason" error code present in 
  all <link linkend="GError"><type>GError</type></link> error code enumerations. Returned if no specific
  code applies.

</simpara></listitem>
</varlistentry>
</variablelist></refsect2>
<refsect2>
<title><anchor id="G-FILE-ERROR-CAPS"/>G_FILE_ERROR</title>
<indexterm><primary>G_FILE_ERROR</primary></indexterm><programlisting>#define G_FILE_ERROR g_file_error_quark ()
</programlisting>
<para>
Error domain for file operations. Errors in this domain will
be from the <link linkend="GFileError"><type>GFileError</type></link> enumeration. See <link linkend="GError"><type>GError</type></link> for information on 
error domains.
</para></refsect2>
<refsect2>
<title><anchor id="GFileTest"/>enum GFileTest</title>
<indexterm><primary>GFileTest</primary></indexterm><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;
</programlisting>
<para>
A test to perform an a file using <link linkend="g-file-test"><function>g_file_test()</function></link>.
</para><variablelist role="enum">
<varlistentry>
<term><literal>G_FILE_TEST_IS_REGULAR</literal></term>
<listitem><simpara><literal>TRUE</literal> if the file is a regular file (not a symlink or directory)
</simpara></listitem>
</varlistentry>
<varlistentry>
<term><literal>G_FILE_TEST_IS_SYMLINK</literal></term>
<listitem><simpara><literal>TRUE</literal> if the file is a symlink.
</simpara></listitem>
</varlistentry>
<varlistentry>
<term><literal>G_FILE_TEST_IS_DIR</literal></term>
<listitem><simpara><literal>TRUE</literal> if the file is a directory.
</simpara></listitem>
</varlistentry>
<varlistentry>
<term><literal>G_FILE_TEST_IS_EXECUTABLE</literal></term>
<listitem><simpara><literal>TRUE</literal> if the file is executable.
</simpara></listitem>
</varlistentry>
<varlistentry>
<term><literal>G_FILE_TEST_EXISTS</literal></term>
<listitem><simpara><literal>TRUE</literal> if the file exists. It may or may not be a regular file.

</simpara></listitem>
</varlistentry>
</variablelist></refsect2>
<refsect2>
<title><anchor id="g-file-error-from-errno"/>g_file_error_from_errno ()</title>
<indexterm><primary>g_file_error_from_errno</primary></indexterm><programlisting><link linkend="GFileError">GFileError</link>  g_file_error_from_errno         (<link linkend="gint">gint</link> err_no);</programlisting>
<para>
Gets a <link linkend="GFileError"><type>GFileError</type></link> constant based on the passed-in <parameter>errno</parameter>.
For example, if you pass in <literal>EEXIST</literal> this function returns
<link linkend="G-FILE-ERROR-EXIST-CAPS"><type>G_FILE_ERROR_EXIST</type></link>. Unlike <parameter>errno</parameter> values, you can portably
assume that all <link linkend="GFileError"><type>GFileError</type></link> values will exist.
</para>
<para>
Normally a <link linkend="GFileError"><type>GFileError</type></link> value goes into a <link linkend="GError"><type>GError</type></link> returned
from a function that manipulates files. So you would use
<link linkend="g-file-error-from-errno"><function>g_file_error_from_errno()</function></link> when constructing a <link linkend="GError"><type>GError</type></link>.</para>
<para>

</para><variablelist role="params">
<varlistentry><term><parameter>err_no</parameter>&nbsp;:</term>
<listitem><simpara> an "errno" value
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> <link linkend="GFileError"><type>GFileError</type></link> corresponding to the given <parameter>errno</parameter>
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2>
<title><anchor id="g-file-get-contents"/>g_file_get_contents ()</title>
<indexterm><primary>g_file_get_contents</primary></indexterm><programlisting><link linkend="gboolean">gboolean</link>    g_file_get_contents             (const <link linkend="gchar">gchar</link> *filename,
                                             <link linkend="gchar">gchar</link> **contents,
                                             <link linkend="gsize">gsize</link> *length,
                                             <link linkend="GError">GError</link> **error);</programlisting>
<para>
Reads an entire file into allocated memory, with good error
checking. If <parameter>error</parameter> is set, <literal>FALSE</literal> is returned, and <parameter>contents</parameter> is set
to <literal>NULL</literal>. If <literal>TRUE</literal> is returned, <parameter>error</parameter> will not be set, and <parameter>contents</parameter>
will be set to the file contents.  The string stored in <parameter>contents</parameter>
will be nul-terminated, so for text files you can pass <literal>NULL</literal> for the
<parameter>length</parameter> argument.  The error domain is <link linkend="G-FILE-ERROR-CAPS"><type>G_FILE_ERROR</type></link>. Possible
error codes are those in the <link linkend="GFileError"><type>GFileError</type></link> enumeration.</para>
<para>

</para><variablelist role="params">
<varlistentry><term><parameter>filename</parameter>&nbsp;:</term>
<listitem><simpara> a file to read contents from
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>contents</parameter>&nbsp;:</term>
<listitem><simpara> location to store an allocated string
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>length</parameter>&nbsp;:</term>
<listitem><simpara> location to store length in bytes of the contents
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>error</parameter>&nbsp;:</term>
<listitem><simpara> return location for a <link linkend="GError"><type>GError</type></link>
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> <literal>TRUE</literal> on success, <literal>FALSE</literal> if error is set
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2>
<title><anchor id="g-file-test"/>g_file_test ()</title>
<indexterm><primary>g_file_test</primary></indexterm><programlisting><link linkend="gboolean">gboolean</link>    g_file_test                     (const <link linkend="gchar">gchar</link> *filename,
                                             <link linkend="GFileTest">GFileTest</link> test);</programlisting>
<para>
Returns <literal>TRUE</literal> if any of the tests in the bitfield <parameter>test</parameter> are
<literal>TRUE</literal>. For example, <literal>(G_FILE_TEST_EXISTS | 
G_FILE_TEST_IS_DIR)</literal> will return <literal>TRUE</literal> if the file exists; 
the check whether it's a directory doesn't matter since the existence 
test is <literal>TRUE</literal>. With the current set of available tests, there's no point
passing in more than one test at a time.
</para>
<para>
Apart from <literal>G_FILE_TEST_IS_SYMLINK</literal> all tests follow symbolic links,
so for a symbolic link to a regular file <link linkend="g-file-test"><function>g_file_test()</function></link> will return
<literal>TRUE</literal> for both <literal>G_FILE_TEST_IS_SYMLINK</literal> and <literal>G_FILE_TEST_IS_REGULAR</literal>.
</para>
<para>
Note, that for a dangling symbolic link <link linkend="g-file-test"><function>g_file_test()</function></link> will return
<literal>TRUE</literal> for <literal>G_FILE_TEST_IS_SYMLINK</literal> and <literal>FALSE</literal> for all other flags.
</para>
<para>
You should never use <link linkend="g-file-test"><function>g_file_test()</function></link> 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 <literal>G_FILE_TEST_IS_SYMLINK</literal>
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!
</para>
<para>
<informalexample><programlisting>
/&ast; DON'T DO THIS &ast;/
 if (!g_file_test (filename, G_FILE_TEST_IS_SYMLINK)) {
   fd = open (filename, O_WRONLY);
   /&ast; write to fd &ast;/
 }
</programlisting></informalexample>
</para>
<para>
Another thing to note is that <literal>G_FILE_TEST_EXISTS</literal> and
<literal>G_FILE_TEST_IS_EXECUTABLE</literal> are implemented using the <link linkend="access"><function>access()</function></link>
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.</para>
<para>

</para><variablelist role="params">
<varlistentry><term><parameter>filename</parameter>&nbsp;:</term>
<listitem><simpara> a filename to test
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>test</parameter>&nbsp;:</term>
<listitem><simpara> bitfield of <link linkend="GFileTest"><type>GFileTest</type></link> flags
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> whether a test was <literal>TRUE</literal>
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2>
<title><anchor id="g-mkstemp"/>g_mkstemp ()</title>
<indexterm><primary>g_mkstemp</primary></indexterm><programlisting><link linkend="gint">gint</link>        g_mkstemp                       (<link linkend="gchar">gchar</link> *tmpl);</programlisting>
<para>
Opens a temporary file. See the <link linkend="mkstemp"><function>mkstemp()</function></link> documentation
on most UNIX-like systems. This is a portability wrapper, which simply calls 
<link linkend="mkstemp"><function>mkstemp()</function></link> on systems that have it, and implements 
it in GLib otherwise.
</para>
<para>
The parameter is a string that should match the rules for
<link linkend="mkstemp"><function>mkstemp()</function></link>, i.e. end in "XXXXXX". The X string will 
be modified to form the name of a file that didn't exist.</para>
<para>

</para><variablelist role="params">
<varlistentry><term><parameter>tmpl</parameter>&nbsp;:</term>
<listitem><simpara> template filename
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> A file handle (as from <link linkend="open"><function>open()</function></link>) 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 <link linkend="close"><function>close()</function></link>. In case of errors, -1 is returned.
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2>
<title><anchor id="g-file-open-tmp"/>g_file_open_tmp ()</title>
<indexterm><primary>g_file_open_tmp</primary></indexterm><programlisting><link linkend="gint">gint</link>        g_file_open_tmp                 (const <link linkend="gchar">gchar</link> *tmpl,
                                             <link linkend="gchar">gchar</link> **name_used,
                                             <link linkend="GError">GError</link> **error);</programlisting>
<para>
Opens a file for writing in the preferred directory for temporary
files (as returned by <link linkend="g-get-tmp-dir"><function>g_get_tmp_dir()</function></link>). 
</para>
<para>
<parameter>tmpl</parameter> should be a string ending with six 'X' characters, as the
parameter to <link linkend="g-mkstemp"><function>g_mkstemp()</function></link> (or <link linkend="mkstemp"><function>mkstemp()</function></link>). 
However, unlike these functions, the template should only be a 
basename, no directory components are allowed. If template is <literal>NULL</literal>, 
a default template is used.
</para>
<para>
Note that in contrast to <link linkend="g-mkstemp"><function>g_mkstemp()</function></link> (and <link linkend="mkstemp"><function>mkstemp()</function></link>) 
<parameter>tmpl</parameter> is not modified, and might thus be a read-only literal string.
</para>
<para>
The actual name used is returned in <parameter>name_used</parameter> if non-<literal>NULL</literal>. This
string should be freed with <link linkend="g-free"><function>g_free()</function></link> when not needed any longer.</para>
<para>

</para><variablelist role="params">
<varlistentry><term><parameter>tmpl</parameter>&nbsp;:</term>
<listitem><simpara> Template for file name, as in <link linkend="g-mkstemp"><function>g_mkstemp()</function></link>, basename only
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>name_used</parameter>&nbsp;:</term>
<listitem><simpara> location to store actual name used
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>error</parameter>&nbsp;:</term>
<listitem><simpara> return location for a <link linkend="GError"><type>GError</type></link>
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> A file handle (as from <link linkend="open"><function>open()</function></link>) 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 <link linkend="close"><function>close()</function></link>. In case of errors, -1 is returned 
and <parameter>error</parameter> will be set.
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2>
<title><anchor id="g-file-read-link"/>g_file_read_link ()</title>
<indexterm role="2.4"><primary>g_file_read_link</primary></indexterm><programlisting><link linkend="gchar">gchar</link>*      g_file_read_link                (const <link linkend="gchar">gchar</link> *filename,
                                             <link linkend="GError">GError</link> **error);</programlisting>
<para>
Reads the contents of the symbolic link <parameter>filename</parameter> like the POSIX <link linkend="readlink"><function>readlink()</function></link> function.
The returned string is in the encoding used for filenames. Use <link linkend="g-filename-to-utf8"><function>g_filename_to_utf8()</function></link> to 
convert it to UTF-8.</para>
<para>

</para><variablelist role="params">
<varlistentry><term><parameter>filename</parameter>&nbsp;:</term>
<listitem><simpara> the symbolic link
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>error</parameter>&nbsp;:</term>
<listitem><simpara> return location for a <link linkend="GError"><type>GError</type></link>
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> A newly allocated string with the contents of the symbolic link, 
         or <literal>NULL</literal> if an error occurred.

</simpara></listitem></varlistentry>
</variablelist><para>Since  2.4
</para></refsect2>
<refsect2>
<title><anchor id="GDir"/>struct GDir</title>
<indexterm><primary>GDir</primary></indexterm><programlisting>struct GDir;</programlisting>
<para>
An opaque structure representing an opened directory.
</para></refsect2>
<refsect2>
<title><anchor id="g-dir-open"/>g_dir_open ()</title>
<indexterm><primary>g_dir_open</primary></indexterm><programlisting><link linkend="GDir">GDir</link>*       g_dir_open                      (const <link linkend="gchar">gchar</link> *path,
                                             <link linkend="guint">guint</link> flags,
                                             <link linkend="GError">GError</link> **error);</programlisting>
<para>
Opens a directory for reading. The names of the files
in the directory can then be retrieved using
<link linkend="g-dir-read-name"><function>g_dir_read_name()</function></link>.</para>
<para>

</para><variablelist role="params">
<varlistentry><term><parameter>path</parameter>&nbsp;:</term>
<listitem><simpara> the path to the directory you are interested in
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>flags</parameter>&nbsp;:</term>
<listitem><simpara> Currently must be set to 0. Reserved for future use.
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>error</parameter>&nbsp;:</term>
<listitem><simpara> return location for a <link linkend="GError"><type>GError</type></link>, or <literal>NULL</literal>.
        If non-<literal>NULL</literal>, an error will be set if and only if
        g_dir_open_fails.
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> a newly allocated <link linkend="GDir"><type>GDir</type></link> on success, <literal>NULL</literal> on failure.
  If non-<literal>NULL</literal>, you must free the result with <link linkend="g-dir-close"><function>g_dir_close()</function></link>
  when you are finished with it.
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2>
<title><anchor id="g-dir-read-name"/>g_dir_read_name ()</title>
<indexterm><primary>g_dir_read_name</primary></indexterm><programlisting>G_CONST_RETURN <link linkend="gchar">gchar</link>* g_dir_read_name       (<link linkend="GDir">GDir</link> *dir);</programlisting>
<para>
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 <link linkend="g-filename-to-utf8"><function>g_filename_to_utf8()</function></link> to 
convert it to UTF-8.</para>
<para>

</para><variablelist role="params">
<varlistentry><term><parameter>dir</parameter>&nbsp;:</term>
<listitem><simpara> a <link linkend="GDir"><type>GDir</type></link>* created by <link linkend="g-dir-open"><function>g_dir_open()</function></link>
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> The entries name or <literal>NULL</literal> if there are no 
  more entries. The return value is owned by GLib and
  must not be modified or freed.
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2>
<title><anchor id="g-dir-rewind"/>g_dir_rewind ()</title>
<indexterm><primary>g_dir_rewind</primary></indexterm><programlisting><link linkend="void">void</link>        g_dir_rewind                    (<link linkend="GDir">GDir</link> *dir);</programlisting>
<para>
Resets the given directory. The next call to <link linkend="g-dir-read-name"><function>g_dir_read_name()</function></link>
will return the first entry again.</para>
<para>

</para><variablelist role="params">
<varlistentry><term><parameter>dir</parameter>&nbsp;:</term>
<listitem><simpara> a <link linkend="GDir"><type>GDir</type></link>* created by <link linkend="g-dir-open"><function>g_dir_open()</function></link>
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2>
<title><anchor id="g-dir-close"/>g_dir_close ()</title>
<indexterm><primary>g_dir_close</primary></indexterm><programlisting><link linkend="void">void</link>        g_dir_close                     (<link linkend="GDir">GDir</link> *dir);</programlisting>
<para>
Closes the directory and deallocates all related resources.</para>
<para>

</para><variablelist role="params">
<varlistentry><term><parameter>dir</parameter>&nbsp;:</term>
<listitem><simpara> a <link linkend="GDir"><type>GDir</type></link>* created by <link linkend="g-dir-open"><function>g_dir_open()</function></link>
</simpara></listitem></varlistentry>
</variablelist></refsect2>

</refsect1>




</refentry>