2 * See the file LICENSE for redistribution information.
4 * Copyright (c) 1997, 1998
5 * Sleepycat Software. All rights reserved.
11 static const char sccsid
[] = "@(#)os_dir.c 10.15 (Sleepycat) 4/26/98";
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 * Return a list of the files in a directory.
43 * PUBLIC: int __os_dirlist __P((const char *, char ***, int *));
46 __os_dirlist(dir
, namesp
, cntp
)
56 if ((dirp
= opendir(dir
)) == NULL
)
59 for (arraysz
= cnt
= 0; (dp
= readdir(dirp
)) != NULL
; ++cnt
) {
62 names
= (char **)(names
== NULL
?
63 __db_malloc(arraysz
* sizeof(names
[0])) :
64 __db_realloc(names
, arraysz
* sizeof(names
[0])));
68 if ((names
[cnt
] = (char *)__db_strdup(dp
->d_name
)) == NULL
)
77 nomem
: if (names
!= NULL
)
78 __os_dirfree(names
, cnt
);
84 * Free the list of files.
86 * PUBLIC: void __os_dirfree __P((char **, int));
89 __os_dirfree(names
, cnt
)
94 __db_free(names
[--cnt
]);