1 #ifndef FILE_H_INCLUDED
2 #define FILE_H_INCLUDED
3 
4 #include <fcntl.h>
5 #include <sys/types.h>
6 #include <sys/stat.h>
7 #include <limits.h>
8 
9 #include "bool.h"
10 #include "int.h"
11 #include "xmlrpc-c/abyss.h"
12 
13 #ifndef NAME_MAX
14 #define NAME_MAX    1024
15 #endif
16 
17 #ifdef WIN32
18 #ifndef __BORLANDC__
19 #define O_APPEND    _O_APPEND
20 #define O_CREAT     _O_CREAT
21 #define O_EXCL      _O_EXCL
22 #define O_RDONLY    _O_RDONLY
23 #define O_RDWR      _O_RDWR
24 #define O_TRUNC _O_TRUNC
25 #define O_WRONLY    _O_WRONLY
26 #define O_TEXT      _O_TEXT
27 #define O_BINARY    _O_BINARY
28 #endif
29 
30 #define A_HIDDEN    _A_HIDDEN
31 #define A_NORMAL    _A_NORMAL
32 #define A_RDONLY    _A_RDONLY
33 #define A_SUBDIR    _A_SUBDIR
34 #else
35 #define A_SUBDIR    1
36 #define O_BINARY    0
37 #define O_TEXT      0
38 #endif  /* WIN32 */
39 
40 #ifdef WIN32
41 
42 #if MSVCRT
43 typedef struct _stati64 TFileStat;
44 typedef struct _finddatai64_t TFileInfo;
45 
46 #else  /* MSVCRT */
47 
48 typedef struct stat TFileStat;
49 typedef struct finddata_t {
50     char name[NAME_MAX+1];
51     int attrib;
52     uint64_t size;
53     time_t time_write;
54     WIN32_FIND_DATA data;
55 } TFileInfo;
56 
57 #endif /* MSVCRT */
58 
59 #else /* WIN32 */
60 
61 #include <unistd.h>
62 #include <dirent.h>
63 
64 typedef struct stat TFileStat;
65 
66 typedef struct finddata_t {
67     char name[NAME_MAX+1];
68     int attrib;
69     uint64_t size;
70     time_t time_write;
71 } TFileInfo;
72 
73 #endif
74 
75 typedef struct TFileFind TFileFind;
76 
77 typedef struct TFile {
78     int fd;
79 } TFile;
80 
81 bool
82 FileOpen(TFile **     const filePP,
83          const char * const name,
84          uint32_t     const attrib);
85 
86 bool
87 FileOpenCreate(TFile **     const filePP,
88                const char * const name,
89                uint32_t     const attrib);
90 
91 bool
92 FileClose(TFile * const fileP);
93 
94 bool
95 FileWrite(const TFile * const fileP,
96           const void *  const buffer,
97           uint32_t      const len);
98 
99 int32_t
100 FileRead(const TFile * const fileP,
101          void *        const buffer,
102          uint32_t      const len);
103 
104 bool
105 FileSeek(const TFile * const fileP,
106          uint64_t      const pos,
107          uint32_t      const attrib);
108 
109 uint64_t
110 FileSize(const TFile * const fileP);
111 
112 bool
113 FileStat(const char * const filename,
114          TFileStat *  const filestat);
115 
116 bool
117 FileFindFirst(TFileFind ** const filefind,
118               const char * const path,
119               TFileInfo *  const fileinfo);
120 
121 bool
122 FileFindNext(TFileFind * const filefind,
123              TFileInfo * const fileinfo);
124 
125 void
126 FileFindClose(TFileFind * const filefind);
127 
128 #endif
129