mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-06 11:00:57 +01:00
simplified wrapper around dirent functions to improve portability of
2001-11-04 Hans Breuer <hans@breuer.org> * glib/gdir.[hc] : (new files) simplified wrapper around dirent functions to improve portability of downstream libs/apps * glib/makefile.msc.in : use them * glib/glib.def : export them * config.h.win32.in : needing HAVE_DIRENT_H defined
This commit is contained in:
parent
49d9628efc
commit
3a86505c77
@ -1,3 +1,11 @@
|
||||
2001-11-04 Hans Breuer <hans@breuer.org>
|
||||
|
||||
* glib/gdir.[hc] : (new files) simplified wrapper around dirent
|
||||
functions to improve portability of downstream libs/apps
|
||||
* glib/makefile.msc.in : use them
|
||||
* glib/glib.def : export them
|
||||
* config.h.win32.in : needing HAVE_DIRENT_H defined
|
||||
|
||||
2001-11-04 Tor Lillqvist <tml@iki.fi>
|
||||
|
||||
* tests/Makefile.am: On Win32, create separate .exp file for
|
||||
|
@ -1,3 +1,11 @@
|
||||
2001-11-04 Hans Breuer <hans@breuer.org>
|
||||
|
||||
* glib/gdir.[hc] : (new files) simplified wrapper around dirent
|
||||
functions to improve portability of downstream libs/apps
|
||||
* glib/makefile.msc.in : use them
|
||||
* glib/glib.def : export them
|
||||
* config.h.win32.in : needing HAVE_DIRENT_H defined
|
||||
|
||||
2001-11-04 Tor Lillqvist <tml@iki.fi>
|
||||
|
||||
* tests/Makefile.am: On Win32, create separate .exp file for
|
||||
|
@ -1,3 +1,11 @@
|
||||
2001-11-04 Hans Breuer <hans@breuer.org>
|
||||
|
||||
* glib/gdir.[hc] : (new files) simplified wrapper around dirent
|
||||
functions to improve portability of downstream libs/apps
|
||||
* glib/makefile.msc.in : use them
|
||||
* glib/glib.def : export them
|
||||
* config.h.win32.in : needing HAVE_DIRENT_H defined
|
||||
|
||||
2001-11-04 Tor Lillqvist <tml@iki.fi>
|
||||
|
||||
* tests/Makefile.am: On Win32, create separate .exp file for
|
||||
|
@ -1,3 +1,11 @@
|
||||
2001-11-04 Hans Breuer <hans@breuer.org>
|
||||
|
||||
* glib/gdir.[hc] : (new files) simplified wrapper around dirent
|
||||
functions to improve portability of downstream libs/apps
|
||||
* glib/makefile.msc.in : use them
|
||||
* glib/glib.def : export them
|
||||
* config.h.win32.in : needing HAVE_DIRENT_H defined
|
||||
|
||||
2001-11-04 Tor Lillqvist <tml@iki.fi>
|
||||
|
||||
* tests/Makefile.am: On Win32, create separate .exp file for
|
||||
|
@ -1,3 +1,11 @@
|
||||
2001-11-04 Hans Breuer <hans@breuer.org>
|
||||
|
||||
* glib/gdir.[hc] : (new files) simplified wrapper around dirent
|
||||
functions to improve portability of downstream libs/apps
|
||||
* glib/makefile.msc.in : use them
|
||||
* glib/glib.def : export them
|
||||
* config.h.win32.in : needing HAVE_DIRENT_H defined
|
||||
|
||||
2001-11-04 Tor Lillqvist <tml@iki.fi>
|
||||
|
||||
* tests/Makefile.am: On Win32, create separate .exp file for
|
||||
|
@ -1,3 +1,11 @@
|
||||
2001-11-04 Hans Breuer <hans@breuer.org>
|
||||
|
||||
* glib/gdir.[hc] : (new files) simplified wrapper around dirent
|
||||
functions to improve portability of downstream libs/apps
|
||||
* glib/makefile.msc.in : use them
|
||||
* glib/glib.def : export them
|
||||
* config.h.win32.in : needing HAVE_DIRENT_H defined
|
||||
|
||||
2001-11-04 Tor Lillqvist <tml@iki.fi>
|
||||
|
||||
* tests/Makefile.am: On Win32, create separate .exp file for
|
||||
|
@ -1,3 +1,11 @@
|
||||
2001-11-04 Hans Breuer <hans@breuer.org>
|
||||
|
||||
* glib/gdir.[hc] : (new files) simplified wrapper around dirent
|
||||
functions to improve portability of downstream libs/apps
|
||||
* glib/makefile.msc.in : use them
|
||||
* glib/glib.def : export them
|
||||
* config.h.win32.in : needing HAVE_DIRENT_H defined
|
||||
|
||||
2001-11-04 Tor Lillqvist <tml@iki.fi>
|
||||
|
||||
* tests/Makefile.am: On Win32, create separate .exp file for
|
||||
|
@ -1,3 +1,11 @@
|
||||
2001-11-04 Hans Breuer <hans@breuer.org>
|
||||
|
||||
* glib/gdir.[hc] : (new files) simplified wrapper around dirent
|
||||
functions to improve portability of downstream libs/apps
|
||||
* glib/makefile.msc.in : use them
|
||||
* glib/glib.def : export them
|
||||
* config.h.win32.in : needing HAVE_DIRENT_H defined
|
||||
|
||||
2001-11-04 Tor Lillqvist <tml@iki.fi>
|
||||
|
||||
* tests/Makefile.am: On Win32, create separate .exp file for
|
||||
|
@ -158,6 +158,9 @@
|
||||
/* Define if you have the `dcgettext' function. */
|
||||
#define HAVE_DCGETTEXT 1
|
||||
|
||||
/* Define if you have the <dirent.h> header file. */
|
||||
#define HAVE_DIRENT_H 1
|
||||
|
||||
/* Define if you have the <dlfcn.h> header file. */
|
||||
/* #undef HAVE_DLFCN_H */
|
||||
|
||||
|
136
glib/gdir.c
Normal file
136
glib/gdir.c
Normal file
@ -0,0 +1,136 @@
|
||||
/* 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 <string.h> /* strerror, strcmp */
|
||||
#ifdef HAVE_DIRENT_H
|
||||
#include <dirent.h>
|
||||
#endif
|
||||
|
||||
#include "glib.h"
|
||||
#include "gdir.h"
|
||||
|
||||
#include "glibintl.h"
|
||||
|
||||
struct _GDir
|
||||
{
|
||||
/*< private >*/
|
||||
DIR *dir;
|
||||
};
|
||||
|
||||
/**
|
||||
* g_dir_open:
|
||||
* @path: the path to the directory you are interested in
|
||||
* @flags: for future binary compatible extensions
|
||||
* @error: return location for a #GError
|
||||
*
|
||||
* Return value: a #GDir* on success, NULL if error is set
|
||||
**/
|
||||
GDir *
|
||||
g_dir_open (const gchar *path,
|
||||
guint flags,
|
||||
GError **error)
|
||||
{
|
||||
GDir *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 dir '%s': %s"),
|
||||
path, strerror (errno));
|
||||
|
||||
g_free (dir);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_dir_read_name:
|
||||
* @dir: a #GDir* created by g_dir_open()
|
||||
*
|
||||
* Iterator which delivers the next directory entries name
|
||||
* with each call. The '.' and '..' entries are omitted.
|
||||
*
|
||||
* BTW: using these functions will simplify porting of
|
||||
* your app, at least to Windows.
|
||||
*
|
||||
* Return value: The entries name or NULL if there are no
|
||||
* more entries. Don't free this value!
|
||||
**/
|
||||
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);
|
||||
|
||||
return entry->d_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* Return value: TRUE on success, FALSE otherwise.
|
||||
**/
|
||||
gboolean
|
||||
g_dir_close (GDir *dir)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
g_return_val_if_fail (dir != NULL, FALSE);
|
||||
|
||||
ret = closedir (dir->dir);
|
||||
g_free (dir);
|
||||
|
||||
return !ret;
|
||||
}
|
18
glib/gdir.h
Normal file
18
glib/gdir.h
Normal file
@ -0,0 +1,18 @@
|
||||
#ifndef __G_DIR_H__
|
||||
#define __G_DIR_H__
|
||||
|
||||
#include <glib/gerror.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _GDir GDir;
|
||||
|
||||
GDir *g_dir_open (const gchar *path, guint flags, GError **error);
|
||||
G_CONST_RETURN
|
||||
gchar *g_dir_read_name (GDir *dir);
|
||||
void g_dir_rewind (GDir *dir);
|
||||
gboolean g_dir_close (GDir *dir);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __G_DIR_H__ */
|
@ -9,7 +9,7 @@ TOP = ..\..
|
||||
|
||||
INCLUDES = -I . -I ..
|
||||
DEFINES = -DHAVE_CONFIG_H -DGLIB_COMPILATION -DG_LOG_DOMAIN=g_log_domain_glib -DG_ENABLE_DEBUG
|
||||
DEPCFLAGS = $(INTL_CFLAGS) $(LIBICONV_CFLAGS)
|
||||
DEPCFLAGS = $(INTL_CFLAGS) $(LIBICONV_CFLAGS) $(DIRENT_CFLAGS)
|
||||
|
||||
all : \
|
||||
..\config.h \
|
||||
@ -28,6 +28,7 @@ glib_OBJECTS = \
|
||||
gconvert.obj \
|
||||
gdataset.obj \
|
||||
gdate.obj \
|
||||
gdir.obj \
|
||||
gerror.obj \
|
||||
gfileutils.obj \
|
||||
ghash.obj \
|
||||
@ -81,7 +82,7 @@ glib-@GLIB_MAJOR_VERSION@.@GLIB_MINOR_VERSION@s.lib : $(glib_OBJECTS)
|
||||
lib /out:glib-@GLIB_MAJOR_VERSION@.@GLIB_MINOR_VERSION@s.lib $(glib_OBJECTS)
|
||||
|
||||
libglib-@GLIB_MAJOR_VERSION@.@GLIB_MINOR_VERSION@-@LT_CURRENT_MINUS_AGE@.dll : $(glib_OBJECTS) glib.def
|
||||
$(CC) $(CFLAGS) -LD -Fe$@ $(glib_OBJECTS) $(LIBICONV_LIBS) $(INTL_LIBS) user32.lib advapi32.lib wsock32.lib $(LDFLAGS) /implib:glib-@GLIB_MAJOR_VERSION@.@GLIB_MINOR_VERSION@.lib /def:glib.def
|
||||
$(CC) $(CFLAGS) -LD -Fe$@ $(glib_OBJECTS) $(LIBICONV_LIBS) $(INTL_LIBS) $(DIRENT_LIBS) user32.lib advapi32.lib wsock32.lib $(LDFLAGS) /implib:glib-@GLIB_MAJOR_VERSION@.@GLIB_MINOR_VERSION@.lib /def:glib.def
|
||||
|
||||
gspawn-win32-helper.exe : gspawn-win32-helper.c libglib-@GLIB_MAJOR_VERSION@.@GLIB_MINOR_VERSION@-@LT_CURRENT_MINUS_AGE@.dll
|
||||
$(CC) $(CFLAGS) -Fe$@ -DG_LOG_DOMAIN=\"gspawn-win32-helper\" gspawn-win32-helper.c glib-@GLIB_MAJOR_VERSION@.@GLIB_MINOR_VERSION@.lib $(LDFLAGS) /subsystem:windows user32.lib
|
||||
|
Loading…
x
Reference in New Issue
Block a user