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:
Bill Kendrick 2017-10-15 11:09:17 -07:00
parent 4aabc2da43
commit f8c4dc626c
2 changed files with 192 additions and 192 deletions

View file

@ -38,6 +38,7 @@
DIR * opendir(const char *pSpec) DIR * opendir(const char *pSpec)
{ {
char pathname[MAX_PATH + 2]; char pathname[MAX_PATH + 2];
DIR * pDir = calloc(1, sizeof(DIR)); DIR * pDir = calloc(1, sizeof(DIR));
if (!pDir) if (!pDir)
return NULL; return NULL;
@ -52,6 +53,7 @@
} }
return pDir; return pDir;
} }
void closedir(DIR * pDir) void closedir(DIR * pDir)
{ {
assert(pDir != NULL); assert(pDir != NULL);
@ -73,24 +75,19 @@
} }
return NULL; return NULL;
} }
int alphasort(const void *a, const void *b) int alphasort(const void *a, const void *b)
{ {
return (strcmp return (strcmp((*(const struct dirent **)a)->d_name, (*(const struct dirent **)b)->d_name));
((*(const struct dirent **) a)->d_name, } static int addToList(int i, struct dirent ***namelist, struct dirent *entry)
(*(const struct dirent **) b)->d_name));
} static int addToList(int i, struct dirent ***namelist,
struct dirent *entry)
{ {
int size; int size;
struct dirent *block; struct dirent *block;
*namelist =
(struct dirent **) realloc((void *) (*namelist), *namelist = (struct dirent **)realloc((void *)(*namelist), (size_t) ((i + 1) * sizeof(struct dirent *)));
(size_t) ((i + 1) * sizeof(struct dirent *)));
if (*namelist == NULL) if (*namelist == NULL)
return -1; return -1;
size = size = (((char *)&entry->d_name) - ((char *)entry)) + strlen(entry->d_name) + 1;
(((char *) &entry->d_name) - ((char *) entry)) + strlen(entry->d_name) +
1;
block = (struct dirent *)malloc(size); block = (struct dirent *)malloc(size);
if (block == NULL) if (block == NULL)
return -1; return -1;
@ -98,12 +95,13 @@
memcpy(block, entry, size); memcpy(block, entry, size);
return ++i; 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; DIR * pDir;
int count; int count;
struct dirent *entry; struct dirent *entry;
assert((dir != NULL) && (namelist != NULL)); assert((dir != NULL) && (namelist != NULL));
pDir = opendir(dir); pDir = opendir(dir);
if (!pDir) if (!pDir)
@ -120,8 +118,7 @@
if (count <= 0) if (count <= 0)
return -1; return -1;
if (compar != NULL) if (compar != NULL)
qsort((void *) (*namelist), (size_t) count, sizeof(struct dirent *), qsort((void *)(*namelist), (size_t) count, sizeof(struct dirent *), compar);
compar);
return count; return count;
} }

View file

@ -13,6 +13,7 @@
typedef wchar_t TCHAR; typedef wchar_t TCHAR;
typedef void *HANDLE; typedef void *HANDLE;
#define MAX_PATH 256 #define MAX_PATH 256
#define INVALID_HANDLE_VALUE ((HANDLE)(-1)) #define INVALID_HANDLE_VALUE ((HANDLE)(-1))
#define WINAPI __stdcall #define WINAPI __stdcall
@ -35,6 +36,7 @@
TCHAR cAlternateFileName[14]; TCHAR cAlternateFileName[14];
} WIN32_FIND_DATA; } WIN32_FIND_DATA;
#define FindFirstFile FindFirstFileA #define FindFirstFile FindFirstFileA
#define FindNextFile FindNextFileA #define FindNextFile FindNextFileA
#define FindClose FindClose #define FindClose FindClose
@ -51,6 +53,7 @@ extern "C"
#ifdef __cplusplus #ifdef __cplusplus
}; };
#endif /* */ #endif /* */
struct dirent struct dirent
{ {
@ -68,6 +71,6 @@ extern "C"
typedef int (*selectCB) (const struct dirent *); typedef int (*selectCB) (const struct dirent *);
typedef int (*comparCB) (const void *, const void *); typedef int (*comparCB) (const void *, const void *);
extern int alphasort(const void *a, const void *b); extern int alphasort(const void *a, const void *b);
extern int scandir(const char *dir, struct dirent ***namelist, extern int scandir(const char *dir, struct dirent ***namelist, selectCB select, comparCB compar);
selectCB select, comparCB compar);