indent, and tr -d "\r", win32_dirent.c & .h
Ran indent on win32_dirent.* and also removed MSDOS CR ("^M" aka "\r")
This commit is contained in:
parent
4aabc2da43
commit
f8c4dc626c
2 changed files with 192 additions and 192 deletions
|
|
@ -38,6 +38,7 @@
|
|||
DIR * opendir(const char *pSpec)
|
||||
{
|
||||
char pathname[MAX_PATH + 2];
|
||||
|
||||
DIR * pDir = calloc(1, sizeof(DIR));
|
||||
if (!pDir)
|
||||
return NULL;
|
||||
|
|
@ -51,18 +52,19 @@
|
|||
pDir = NULL;
|
||||
}
|
||||
return pDir;
|
||||
}
|
||||
void closedir(DIR * pDir)
|
||||
}
|
||||
|
||||
void closedir(DIR * pDir)
|
||||
{
|
||||
assert(pDir != NULL);
|
||||
free(pDir);
|
||||
}
struct dirent *readdir(struct DIR *pDir)
|
||||
} struct dirent *readdir(struct DIR *pDir)
|
||||
{
|
||||
assert(pDir != NULL);
|
||||
if (pDir->hFind)
|
||||
|
||||
{
|
||||
strcpy(pDir->de.d_name, (const char *) pDir->wfd.cFileName);
|
||||
strcpy(pDir->de.d_name, (const char *)pDir->wfd.cFileName);
|
||||
if (!FindNextFile(pDir->hFind, &pDir->wfd))
|
||||
|
||||
{
|
||||
|
|
@ -72,38 +74,34 @@
|
|||
return &pDir->de;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
int alphasort(const void *a, const void *b)
|
||||
}
|
||||
|
||||
int alphasort(const void *a, const void *b)
|
||||
{
|
||||
return (strcmp
|
||||
((*(const struct dirent **) a)->d_name,
|
||||
(*(const struct dirent **) b)->d_name));
|
||||
}
static int addToList(int i, struct dirent ***namelist,
|
||||
struct dirent *entry)
|
||||
return (strcmp((*(const struct dirent **)a)->d_name, (*(const struct dirent **)b)->d_name));
|
||||
} static int addToList(int i, struct dirent ***namelist, struct dirent *entry)
|
||||
{
|
||||
int size;
|
||||
struct dirent *block;
|
||||
*namelist =
|
||||
(struct dirent **) realloc((void *) (*namelist),
|
||||
(size_t) ((i + 1) * sizeof(struct dirent *)));
|
||||
|
||||
*namelist = (struct dirent **)realloc((void *)(*namelist), (size_t) ((i + 1) * sizeof(struct dirent *)));
|
||||
if (*namelist == NULL)
|
||||
return -1;
|
||||
size =
|
||||
(((char *) &entry->d_name) - ((char *) entry)) + strlen(entry->d_name) +
|
||||
1;
|
||||
block = (struct dirent *) malloc(size);
|
||||
size = (((char *)&entry->d_name) - ((char *)entry)) + strlen(entry->d_name) + 1;
|
||||
block = (struct dirent *)malloc(size);
|
||||
if (block == NULL)
|
||||
return -1;
|
||||
(*namelist)[i] = block;
|
||||
memcpy(block, entry, size);
|
||||
return ++i;
|
||||
}
|
||||
int scandir(const char *dir, struct dirent ***namelist, selectCB select,
|
||||
comparCB compar)
|
||||
}
|
||||
|
||||
int scandir(const char *dir, struct dirent ***namelist, selectCB select, comparCB compar)
|
||||
{
|
||||
DIR * pDir;
|
||||
int count;
|
||||
struct dirent *entry;
|
||||
|
||||
assert((dir != NULL) && (namelist != NULL));
|
||||
pDir = opendir(dir);
|
||||
if (!pDir)
|
||||
|
|
@ -120,9 +118,8 @@
|
|||
if (count <= 0)
|
||||
return -1;
|
||||
if (compar != NULL)
|
||||
qsort((void *) (*namelist), (size_t) count, sizeof(struct dirent *),
|
||||
compar);
|
||||
qsort((void *)(*namelist), (size_t) count, sizeof(struct dirent *), compar);
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -8,20 +8,21 @@
|
|||
/* */
|
||||
/****************************************************/
|
||||
/* $Id$ */
|
||||
typedef long BOOL;
|
||||
typedef unsigned int DWORD;
|
||||
typedef wchar_t TCHAR;
|
||||
typedef void *HANDLE;
|
||||
typedef long BOOL;
|
||||
typedef unsigned int DWORD;
|
||||
typedef wchar_t TCHAR;
|
||||
typedef void *HANDLE;
|
||||
|
||||
|
||||
#define MAX_PATH 256
|
||||
#define INVALID_HANDLE_VALUE ((HANDLE)(-1))
|
||||
#define WINAPI __stdcall
|
||||
typedef struct
|
||||
typedef struct
|
||||
{
|
||||
DWORD dwLowDateTime;
|
||||
DWORD dwHighDateTime;
|
||||
} FILETIME;
|
||||
typedef struct
|
||||
} FILETIME;
|
||||
typedef struct
|
||||
{
|
||||
DWORD dwFileAttributes;
|
||||
FILETIME ftCreationTime;
|
||||
|
|
@ -33,7 +34,8 @@
|
|||
DWORD dwReserved1;
|
||||
TCHAR cFileName[MAX_PATH];
|
||||
TCHAR cAlternateFileName[14];
|
||||
} WIN32_FIND_DATA;
|
||||
} WIN32_FIND_DATA;
|
||||
|
||||
|
||||
#define FindFirstFile FindFirstFileA
|
||||
#define FindNextFile FindNextFileA
|
||||
|
|
@ -51,23 +53,24 @@ extern "C"
|
|||
#ifdef __cplusplus
|
||||
};
|
||||
|
||||
|
||||
#endif /* */
|
||||
struct dirent
|
||||
struct dirent
|
||||
{
|
||||
char d_name[MAX_PATH];
|
||||
};
|
||||
typedef struct
|
||||
};
|
||||
typedef struct
|
||||
{
|
||||
WIN32_FIND_DATA wfd;
|
||||
HANDLE hFind;
|
||||
struct dirent de;
|
||||
} DIR;
|
||||
extern DIR *opendir(const char *pSpec);
|
||||
extern void closedir(DIR * pDir);
|
||||
extern struct dirent *readdir(struct DIR *pDir);
|
||||
typedef int (*selectCB) (const struct dirent *);
|
||||
typedef int (*comparCB) (const void *, const void *);
|
||||
extern int alphasort(const void *a, const void *b);
|
||||
extern int scandir(const char *dir, struct dirent ***namelist,
|
||||
selectCB select, comparCB compar);
|
||||
} DIR;
|
||||
extern DIR *opendir(const char *pSpec);
|
||||
extern void closedir(DIR * pDir);
|
||||
extern struct dirent *readdir(struct DIR *pDir);
|
||||
typedef int (*selectCB) (const struct dirent *);
|
||||
typedef int (*comparCB) (const void *, const void *);
|
||||
extern int alphasort(const void *a, const void *b);
|
||||
extern int scandir(const char *dir, struct dirent ***namelist, selectCB select, comparCB compar);
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue