mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-27 04:32:15 +01:00
* glib/gmain.c: Remove references to nonexisting functions g_source_set_callback_closure(), g_source_poll(), g_source_add() from docs. * glib/gdir.c (g_dir_open): Typo fix in docs. * glib/gasyncqueue.c (g_async_queue_lock): (g_async_queue_unref_and_unlock): Fix markup to avoid erroneous <link>s in docs. * glib/gwin32.c: Escape #'s leading to erroneous <link>s in docs. * glib/gtree.c: Replace some occurances of Gtree by GTree in docs. * glib/gstring.c (g_string_insert_unichar): Typo fix in docs. * glib/tmpl/conversions.sgml: Add GIConv. * glib/tmpl/main.sgml: Fix references to nonexisting functions g_main_loop_destroy(), g_source_add(), g_source_connect(). * glib/glib-sections.txt: Add GIConv, g_str_has_prefix, g_str_has_suffix. * glib/tmpl/linked_lists_single.sgml: * glib/tmpl/linked_lists_double.sgml: GListAllocator doesn't exist. * glib/glib-docs.sgml: Declare hash entity. * glib/tmpl/macros.sgml: Escape # in #ifdef to suppress erroneous links. * gobject/Makefile.am, gobject/gobject-docs.sgml, gobject/tmpl/*: * glib/Makefile.am, glib/glib-docs.sgml, glib/tmpl/*: Produce XML, not SGML.
146 lines
3.4 KiB
C
146 lines
3.4 KiB
C
/* GLIB - Library of useful routines for C programming
|
|
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
|
*
|
|
* gdir.c: Simplified wrapper around the DIRENT functions.
|
|
*
|
|
* Copyright 2001 Hans Breuer
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
* License as published by the Free Software Foundation; either
|
|
* version 2 of the License, or (at your option) any later version.
|
|
*
|
|
* This library is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
* License along with this library; if not, write to the
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
* Boston, MA 02111-1307, USA.
|
|
*/
|
|
|
|
#include "config.h"
|
|
|
|
#include <errno.h>
|
|
#include <string.h> /* strcmp */
|
|
|
|
#ifdef HAVE_DIRENT_H
|
|
#include <sys/types.h>
|
|
#include <dirent.h>
|
|
#endif
|
|
|
|
#include "glib.h"
|
|
#include "gdir.h"
|
|
|
|
#include "glibintl.h"
|
|
|
|
struct _GDir
|
|
{
|
|
DIR *dir;
|
|
};
|
|
|
|
/**
|
|
* g_dir_open:
|
|
* @path: the path to the directory you are interested in
|
|
* @flags: Currently must be set to 0. Reserved for future use.
|
|
* @error: return location for a #GError, or %NULL.
|
|
* If non-%NULL, an error will be set if and only if
|
|
* g_dir_open_fails.
|
|
*
|
|
* Opens a directory for reading. The names of the files
|
|
* in the directory can then be retrieved using
|
|
* g_dir_read_name().
|
|
*
|
|
* Return value: a newly allocated #GDir on success, %NULL on failure.
|
|
* If non-%NULL, you must free the result with g_dir_close()
|
|
* when you are finished with it.
|
|
**/
|
|
GDir *
|
|
g_dir_open (const gchar *path,
|
|
guint flags,
|
|
GError **error)
|
|
{
|
|
GDir *dir;
|
|
|
|
g_return_val_if_fail (path != NULL, NULL);
|
|
|
|
dir = g_new (GDir, 1);
|
|
|
|
dir->dir = opendir (path);
|
|
|
|
if (dir->dir)
|
|
return dir;
|
|
|
|
/* error case */
|
|
g_set_error (error,
|
|
G_FILE_ERROR,
|
|
g_file_error_from_errno (errno),
|
|
_("Error opening directory '%s': %s"),
|
|
path, g_strerror (errno));
|
|
|
|
g_free (dir);
|
|
return NULL;
|
|
}
|
|
|
|
/**
|
|
* g_dir_read_name:
|
|
* @dir: a #GDir* created by g_dir_open()
|
|
*
|
|
* Retrieves the name of the next entry in the directory.
|
|
* The '.' and '..' entries are omitted.
|
|
*
|
|
* Return value: The entries name or %NULL if there are no
|
|
* more entries. The return value is owned by GLib and
|
|
* must not be modified or freed.
|
|
**/
|
|
G_CONST_RETURN gchar*
|
|
g_dir_read_name (GDir *dir)
|
|
{
|
|
struct dirent *entry;
|
|
|
|
g_return_val_if_fail (dir != NULL, NULL);
|
|
|
|
entry = readdir (dir->dir);
|
|
while (entry
|
|
&& (0 == strcmp (entry->d_name, ".") ||
|
|
0 == strcmp (entry->d_name, "..")))
|
|
entry = readdir (dir->dir);
|
|
|
|
if (entry)
|
|
return entry->d_name;
|
|
else
|
|
return NULL;
|
|
}
|
|
|
|
/**
|
|
* g_dir_rewind:
|
|
* @dir: a #GDir* created by g_dir_open()
|
|
*
|
|
* Resets the given directory. The next call to g_dir_read_name()
|
|
* will return the first entry again.
|
|
**/
|
|
void
|
|
g_dir_rewind (GDir *dir)
|
|
{
|
|
g_return_if_fail (dir != NULL);
|
|
|
|
rewinddir (dir->dir);
|
|
}
|
|
|
|
/**
|
|
* g_dir_close:
|
|
* @dir: a #GDir* created by g_dir_open()
|
|
*
|
|
* Closes the directory and deallocates all related resources.
|
|
**/
|
|
void
|
|
g_dir_close (GDir *dir)
|
|
{
|
|
g_return_if_fail (dir != NULL);
|
|
|
|
closedir (dir->dir);
|
|
g_free (dir);
|
|
}
|