mariadb/bdb/os_win32/os_dir.c

87 lines
1.7 KiB
C
Raw Normal View History

2001-03-05 01:42:05 +01:00
/*-
* See the file LICENSE for redistribution information.
*
2002-10-30 12:57:05 +01:00
* Copyright (c) 1997-2002
2001-03-05 01:42:05 +01:00
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
2002-10-30 12:57:05 +01:00
static const char revid[] = "$Id: os_dir.c,v 11.12 2002/07/12 18:56:54 bostic Exp $";
2001-03-05 01:42:05 +01:00
#endif /* not lint */
#include "db_int.h"
/*
* __os_dirlist --
* Return a list of the files in a directory.
*/
int
__os_dirlist(dbenv, dir, namesp, cntp)
DB_ENV *dbenv;
const char *dir;
char ***namesp;
int *cntp;
{
struct _finddata_t fdata;
2002-10-30 12:57:05 +01:00
#ifdef _WIN64
intptr_t dirhandle;
#else
2001-03-05 01:42:05 +01:00
long dirhandle;
2002-10-30 12:57:05 +01:00
#endif
2001-03-05 01:42:05 +01:00
int arraysz, cnt, finished, ret;
char **names, filespec[MAXPATHLEN];
2002-10-30 12:57:05 +01:00
if (DB_GLOBAL(j_dirlist) != NULL)
return (DB_GLOBAL(j_dirlist)(dir, namesp, cntp));
2001-03-05 01:42:05 +01:00
(void)snprintf(filespec, sizeof(filespec), "%s/*", dir);
if ((dirhandle = _findfirst(filespec, &fdata)) == -1)
return (__os_get_errno());
names = NULL;
finished = 0;
for (arraysz = cnt = 0; finished != 1; ++cnt) {
if (cnt >= arraysz) {
arraysz += 100;
if ((ret = __os_realloc(dbenv,
2002-10-30 12:57:05 +01:00
arraysz * sizeof(names[0]), &names)) != 0)
2001-03-05 01:42:05 +01:00
goto nomem;
}
if ((ret = __os_strdup(dbenv, fdata.name, &names[cnt])) != 0)
goto nomem;
2002-10-30 12:57:05 +01:00
if (_findnext(dirhandle, &fdata) != 0)
2001-03-05 01:42:05 +01:00
finished = 1;
}
_findclose(dirhandle);
*namesp = names;
*cntp = cnt;
return (0);
nomem: if (names != NULL)
2002-10-30 12:57:05 +01:00
__os_dirfree(dbenv, names, cnt);
2001-03-05 01:42:05 +01:00
return (ret);
}
/*
* __os_dirfree --
* Free the list of files.
*/
void
2002-10-30 12:57:05 +01:00
__os_dirfree(dbenv, names, cnt)
DB_ENV *dbenv;
2001-03-05 01:42:05 +01:00
char **names;
int cnt;
{
2002-10-30 12:57:05 +01:00
if (DB_GLOBAL(j_dirfree) != NULL) {
DB_GLOBAL(j_dirfree)(names, cnt);
2001-03-05 01:42:05 +01:00
return;
}
while (cnt > 0)
2002-10-30 12:57:05 +01:00
__os_free(dbenv, names[--cnt]);
__os_free(dbenv, names);
2001-03-05 01:42:05 +01:00
}