|
| 1 | +#ifndef XPLDIR_H |
| 2 | +#define XPLDIR_H |
| 3 | + |
| 4 | +#cmakedefine HAVE_VALGRIND_H 1 |
| 5 | +#cmakedefine HAVE_MMAN_H 1 |
| 6 | + |
| 7 | +/* |
| 8 | + Platform defines |
| 9 | +
|
| 10 | + The use of these should be limited as much as possible. Specific tests for |
| 11 | + features of the platform are prefered. |
| 12 | +*/ |
| 13 | +#ifndef LINUX |
| 14 | +#cmakedefine LINUX 1 |
| 15 | +#endif |
| 16 | + |
| 17 | +#ifndef WIN32 |
| 18 | +#cmakedefine WIN32 1 |
| 19 | +#endif |
| 20 | +#ifndef WINDOWS |
| 21 | +#cmakedefine WINDOWS 1 |
| 22 | + |
| 23 | +#endif |
| 24 | + |
| 25 | + |
| 26 | +#ifndef MACOSX |
| 27 | +#cmakedefine MACOSX 1 |
| 28 | +#endif |
| 29 | +#ifndef DARWIN |
| 30 | +#cmakedefine DARWIN 1 |
| 31 | +#endif |
| 32 | +#ifndef APPLE |
| 33 | +#cmakedefine APPLE 1 |
| 34 | +#endif |
| 35 | + |
| 36 | +#cmakedefine DEBUG 1 |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | +/* File and Directory Functions */ |
| 41 | + |
| 42 | +#if defined(LINUX) || defined(MACOSX) |
| 43 | + |
| 44 | +#include <sys/stat.h> |
| 45 | +#include <sys/types.h> |
| 46 | +#include <dirent.h> |
| 47 | + |
| 48 | +/* Limits */ |
| 49 | +#if defined (PATH_MAX) |
| 50 | +# define XPL_MAX_PATH PATH_MAX |
| 51 | +#elif defined (MAX_PATH) |
| 52 | +# define XPL_MAX_PATH MAX_PATH |
| 53 | +#elif defined (_PC_PATH_MAX) |
| 54 | +# define XPL_MAX_PATH sysconf(_PC_PATH_MAX) |
| 55 | +#elif defined (_MAX_PATH) |
| 56 | +# define XPL_MAX_PATH _MAX_PATH |
| 57 | +#else |
| 58 | +# error "XPL_MAX_PATH is not implemented on this platform" |
| 59 | +#endif |
| 60 | + |
| 61 | + |
| 62 | +typedef struct _XplDir { |
| 63 | + unsigned long d_attr; |
| 64 | + unsigned long d_size; |
| 65 | + unsigned char *d_name; |
| 66 | + unsigned long d_cdatetime; |
| 67 | + DIR *dirp; |
| 68 | + struct dirent *direntp; |
| 69 | + unsigned char Path[XPL_MAX_PATH]; |
| 70 | +} XplDir; |
| 71 | + |
| 72 | +#ifdef __cplusplus |
| 73 | +extern "C"{ |
| 74 | +#endif |
| 75 | + |
| 76 | +int XplMakeDir(const char *path); |
| 77 | + |
| 78 | +#ifdef __cplusplus |
| 79 | +} |
| 80 | +#endif |
| 81 | + |
| 82 | +#elif defined(WIN32) |
| 83 | + |
| 84 | +#include <direct.h> |
| 85 | +#include <io.h> |
| 86 | + |
| 87 | +typedef struct _XplDir { |
| 88 | + unsigned long d_attr; |
| 89 | + unsigned long d_size; |
| 90 | + unsigned char *d_name; |
| 91 | + unsigned long d_cdatetime; |
| 92 | + long dirp; |
| 93 | + struct _finddata_t FindData; |
| 94 | + unsigned char Path[_MAX_PATH+1]; |
| 95 | +} XplDir; |
| 96 | + |
| 97 | +#define XplMakeDir(path) mkdir(path) |
| 98 | + |
| 99 | +#endif |
| 100 | + |
| 101 | +typedef struct _XplDirMatch { |
| 102 | + struct _XplDirMatch *next; |
| 103 | + struct _XplDirMatch *base; |
| 104 | + |
| 105 | + unsigned long d_attr; |
| 106 | + unsigned long d_size; |
| 107 | + unsigned long d_cdatetime; |
| 108 | + |
| 109 | + unsigned char *d_name; |
| 110 | + |
| 111 | + struct { |
| 112 | + void *data; |
| 113 | + void *lock; |
| 114 | + } client; |
| 115 | +} XplDirMatch; |
| 116 | + |
| 117 | +#ifdef __cplusplus |
| 118 | +extern "C" { |
| 119 | +#endif |
| 120 | + |
| 121 | +EXPORT XplDir *XplOpenDir(const char *dirname); |
| 122 | +EXPORT XplDir *XplReadDir(XplDir *dirp); |
| 123 | +EXPORT int XplCloseDir(XplDir *dirp); |
| 124 | +EXPORT int XplIsSubDir(XplDir *dirp); |
| 125 | + |
| 126 | +EXPORT XplDirMatch *XplOpenDirMatch(const char *pattern); |
| 127 | +EXPORT XplDirMatch *XplReadDirMatch(XplDirMatch *dirp); |
| 128 | +EXPORT XplDirMatch *XplResetDirMatch(XplDirMatch *dirp); |
| 129 | +EXPORT int XplCloseDirMatch(XplDirMatch *dirp); |
| 130 | +EXPORT void XplMakePath(const char *path); |
| 131 | +EXPORT int XplStat( const char *path, struct stat *st ); |
| 132 | + |
| 133 | + |
| 134 | +#if defined(WIN32) |
| 135 | + #define XplGetCurrentDir _getcwd |
| 136 | +#else |
| 137 | + #define XplGetCurrentDir getcwd |
| 138 | +#endif |
| 139 | + |
| 140 | +typedef struct |
| 141 | +{ |
| 142 | + struct stat st; |
| 143 | + char d_name[256]; |
| 144 | +}XDirEnt; |
| 145 | + |
| 146 | +typedef struct |
| 147 | +{ |
| 148 | + void *dirp; |
| 149 | + void (*XFree)(void *); |
| 150 | + XDirEnt entry; |
| 151 | + char *pattern; |
| 152 | + char name[]; |
| 153 | +}XDir; |
| 154 | + |
| 155 | +EXPORT XDir *XOpenDir( const char *path, void *(*XAlloc)(size_t), void (*XFree)(void *) ); |
| 156 | +EXPORT XDirEnt *XReadDir( XDir *dir ); |
| 157 | +EXPORT int XCloseDir( XDir *dir ); |
| 158 | + |
| 159 | +#endif // XPLDIR_H |
0 commit comments