2 * See the file LICENSE for redistribution information.
5 * Sleepycat Software. All rights reserved.
11 static const char sccsid[] = "@(#)os_dir.c 10.13 (Sleepycat) 10/28/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>
41 #include "common_ext.h"
45 * Return a list of the files in a directory.
47 * PUBLIC: int __os_dirlist __P((const char *, char ***, int *));
50 __os_dirlist(dir, namesp, cntp)
60 if ((dirp = opendir(dir)) == NULL)
63 for (arraysz = cnt = 0; (dp = readdir(dirp)) != NULL; ++cnt) {
66 names = (char **)(names == NULL ?
67 __db_malloc(arraysz * sizeof(names[0])) :
68 __db_realloc(names, arraysz * sizeof(names[0])));
72 if ((names[cnt] = (char *)__db_strdup(dp->d_name)) == NULL)
81 nomem: if (names != NULL)
82 __os_dirfree(names, cnt);
88 * Free the list of files.
90 * PUBLIC: void __os_dirfree __P((char **, int));
93 __os_dirfree(names, cnt)
98 __db_free(names[--cnt]);