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 #if MSVCRT
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  /* MSVCRT */
39 
40 #if MSVCRT
41 typedef struct _stati64 TFileStat;
42 typedef struct _finddatai64_t TFileInfo;
43 #else /* MSVCRT */
44 
45 #include <unistd.h>
46 #include <dirent.h>
47 
48 typedef struct stat TFileStat;
49 
50 typedef struct finddata_t {
51     char name[NAME_MAX+1];
52     int attrib;
53     uint64_t size;
54     time_t time_write;
55 } TFileInfo;
56 
57 #endif  /* MSVCRT */
58 
59 typedef struct TFileFind TFileFind;
60 
61 typedef struct TFile {
62     int fd;
63 } TFile;
64 
65 bool
66 FileOpen(TFile **     const filePP,
67          const char * const name,
68          uint32_t     const attrib);
69 
70 bool
71 FileOpenCreate(TFile **     const filePP,
72                const char * const name,
73                uint32_t     const attrib);
74 
75 bool
76 FileClose(TFile * const fileP);
77 
78 bool
79 FileWrite(const TFile * const fileP,
80           const void *  const buffer,
81           uint32_t      const len);
82 
83 int32_t
84 FileRead(const TFile * const fileP,
85          void *        const buffer,
86          uint32_t      const len);
87 
88 bool
89 FileSeek(const TFile * const fileP,
90          uint64_t      const pos,
91          uint32_t      const attrib);
92 
93 uint64_t
94 FileSize(const TFile * const fileP);
95 
96 bool
97 FileStat(const char * const filename,
98          TFileStat *  const filestat);
99 
100 bool
101 FileFindFirst(TFileFind ** const filefind,
102               const char * const path,
103               TFileInfo *  const fileinfo);
104 
105 bool
106 FileFindNext(TFileFind * const filefind,
107              TFileInfo * const fileinfo);
108 
109 void
110 FileFindClose(TFileFind * const filefind);
111 
112 #endif
113