]>
sourceware.org Git - glibc.git/blob - db2/os/db_os_dir.c
2 * See the file LICENSE for redistribution information.
5 * Sleepycat Software. All rights reserved.
11 static const char sccsid
[] = "@(#)db_os_dir.c 10.7 (Sleepycat) 8/23/97";
14 #ifndef NO_SYSTEM_INCLUDES
15 #include <sys/types.h>
19 # define NAMLEN(dirent) strlen((dirent)->d_name)
21 # define dirent direct
22 # define NAMLEN(dirent) (dirent)->d_namlen
24 # include <sys/ndir.h>
42 #include "common_ext.h"
46 * Return a list of the files in a directory.
48 * PUBLIC: int __db_dir __P((DB_ENV *, char *, char ***, int *));
51 __db_dir(dbenv
, dir
, namesp
, cntp
)
60 struct _finddata_t fdata
;
64 if ((dirhandle
= _findfirst(dir
,&fdata
)) == -1) {
65 __db_err(dbenv
, "%s: %s", dir
, strerror(errno
));
71 for (arraysz
= cnt
= 0; finished
!= 1; ++cnt
) {
74 names
= (char **)(names
== NULL
?
75 malloc(arraysz
* sizeof(names
[0])) :
76 realloc(names
, arraysz
* sizeof(names
[0])));
80 if ((names
[cnt
] = (char *)strdup(fdata
.name
)) == NULL
)
82 if (_findnext(dirhandle
,&fdata
) != 0)
85 _findclose(dirhandle
);
90 if ((dirp
= opendir(dir
)) == NULL
) {
91 __db_err(dbenv
, "%s: %s", dir
, strerror(errno
));
95 for (arraysz
= cnt
= 0; (dp
= readdir(dirp
)) != NULL
; ++cnt
) {
98 names
= (char **)(names
== NULL
?
99 malloc(arraysz
* sizeof(names
[0])) :
100 realloc(names
, arraysz
* sizeof(names
[0])));
104 if ((names
[cnt
] = (char *)strdup(dp
->d_name
)) == NULL
)
107 (void)closedir(dirp
);
114 nomem
: if (names
!= NULL
)
115 __db_dirf(dbenv
, names
, cnt
);
116 __db_err(dbenv
, "%s", strerror(ENOMEM
));
122 * Free the list of files.
124 * PUBLIC: void __db_dirf __P((DB_ENV *, char **, int));
127 __db_dirf(dbenv
, names
, cnt
)
132 dbenv
= dbenv
; /* XXX: Shut the compiler up. */
This page took 0.038446 seconds and 5 git commands to generate.