00001 #ifndef __FILEIO_H
00002 #define __FILEIO_H
00003
00094 #if defined(_WIN32) || defined(UNDER_CE)
00095 # include <windows.h>
00096
00097 # define FILEIO_INVALID INVALID_HANDLE_VALUE
00098
00099 # define FILEIO_SEEKBEG FILE_BEGIN
00100
00101 # define FILEIO_SEEKCUR FILE_CURRENT
00102
00103 # define FILEIO_OPEN(theRes, theHandle, aFileName, aMode) { \
00104 if (aMode == 0) \
00105 theHandle = CreateFile(aFileName, \
00106 GENERIC_READ, \
00107 0, \
00108 NULL, \
00109 OPEN_EXISTING, \
00110 FILE_ATTRIBUTE_NORMAL, \
00111 NULL); \
00112 else \
00113 theHandle = CreateFile(aFileName, \
00114 GENERIC_WRITE, \
00115 FILE_SHARE_READ, \
00116 NULL, \
00117 CREATE_ALWAYS, \
00118 FILE_ATTRIBUTE_NORMAL, \
00119 NULL); \
00120 if (theHandle == FILEIO_INVALID) theRes = 0; else theRes = 1; }
00121
00122 # define FILEIO_RD(theRes, theNum, aBuf, aNum, anFD) { \
00123 DWORD tmpnum; \
00124 theRes = ReadFile(anFD, aBuf, aNum, &tmpnum, NULL); \
00125 theNum = tmpnum; \
00126 }
00127
00128 # define FILEIO_WR(theNum, aBuf, aNum, anFD) { \
00129 DWORD tmpnum; \
00130 WriteFile(anFD, aBuf, aNum, &(tmpnum), NULL); \
00131 theNum = tmpnum; \
00132 }
00133
00134 # define FILEIO_CLOSE(aHandle) CloseHandle(aHandle)
00135
00136 # define FILEIO_SEEK(theRes, anFD, aShift, aPos) { \
00137 if (SetFilePointer(anFD, aShift, NULL, aPos) == 0xFFFFFFFF) theRes = 0; \
00138 else theRes = 1; \
00139 }
00140
00141 # define FILEIO_SIZE(theRes, anFD) {\
00142 theRes = GetFileSize(anFD, NULL); \
00143 if (theRes == INVALID_FILE_SIZE) theRes = 0; \
00144 }
00145
00146 typedef HANDLE t_hfileio;
00147 typedef TCHAR t_filename;
00148
00149 #else
00150 # include <unistd.h>
00151 # include <fcntl.h>
00152 # include <sys/stat.h>
00153
00154 # define FILEIO_INVALID -1
00155
00156 # define FILEIO_SEEKBEG SEEK_SET
00157
00158 # define FILEIO_SEEKCUR SEEK_CUR
00159
00160 # define FILEIO_OPEN(theRes, theHandle, aFileName, aMode) { \
00161 if (aMode == 0) theHandle = open(aFileName, O_RDONLY); \
00162 else theHandle = open (aFileName, O_CREAT | O_WRONLY | S_IREAD, \
00163 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); \
00164 if (theHandle == FILEIO_INVALID) theRes = 0; else theRes = 1; }
00165
00166 # define FILEIO_RD(theRes, theNum, aBuf, aNum, anFD) { \
00167 theNum = read(anFD, aBuf, aNum); \
00168 if (theNum == (size_t) -1) theRes = 0; else theRes = 1; }
00169
00170 # define FILEIO_WR(theNum, aBuf, aNum, anFD) \
00171 theNum = write(anFD, aBuf, aNum)
00172
00173 # define FILEIO_CLOSE(aHandle) close(aHandle)
00174
00175 # define FILEIO_SEEK(theRes, anFD, aShift, aPos) { \
00176 if (lseek(anFD, aShift, aPos) == (size_t) -1) theRes = 0; else theRes = 1; \
00177 }
00178
00179 # define FILEIO_SIZE(theRes, anFD) {\
00180 struct stat st; \
00181 if (fstat(anFD, &st) == 0) theRes = st.st_size; else theRes = 0; \
00182 }
00183
00184 typedef int t_hfileio;
00185 typedef char t_filename;
00186
00187 #endif
00188 #endif