#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
Go to the source code of this file.
Defines | |
#define | FILEIO_INVALID -1 |
Invalid file handle. | |
#define | FILEIO_SEEKBEG SEEK_SET |
Start moving pointer from the begin of the file. | |
#define | FILEIO_SEEKCUR SEEK_CUR |
Start moving pointer from the current position. | |
#define | FILEIO_OPEN(theRes, theHandle, aFileName, aMode) |
Opens a file. | |
#define | FILEIO_RD(theRes, theNum, aBuf, aNum, anFD) |
Reads from a file. | |
#define | FILEIO_WR(theNum, aBuf, aNum, anFD) theNum = write(anFD, aBuf, aNum) |
Writes to a file. | |
#define | FILEIO_CLOSE(aHandle) close(aHandle) |
Closes a file. | |
#define | FILEIO_SEEK(theRes, anFD, aShift, aPos) |
Moves pointer within the file. | |
#define | FILEIO_SIZE(theRes, anFD) |
Returns size of the file denoted by the given handlr. | |
Typedefs | |
typedef int | t_hfileio |
File handle. | |
typedef char | t_filename |
Type for the file name. |
#define FILEIO_CLOSE | ( | aHandle | ) | close(aHandle) |
Closes a file.
aHandle | handle of the file to close. |
#define FILEIO_INVALID -1 |
Invalid file handle.
#define FILEIO_OPEN | ( | theRes, | |||
theHandle, | |||||
aFileName, | |||||
aMode | ) |
Value:
{ \ if (aMode == 0) theHandle = open(aFileName, O_RDONLY); \ else theHandle = open (aFileName, O_CREAT | O_WRONLY | S_IREAD, \ S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); \ if (theHandle == FILEIO_INVALID) theRes = 0; else theRes = 1; }
theRes | out, != 0 for success, 0 for error. | |
theHandle | in, the resulting file handle. | |
aFileName | in, name of the file to open. | |
aMode | in, != 0 for write, 0 for read. |
#define FILEIO_RD | ( | theRes, | |||
theNum, | |||||
aBuf, | |||||
aNum, | |||||
anFD | ) |
Value:
{ \ theNum = read(anFD, aBuf, aNum); \ if (theNum == (size_t) -1) theRes = 0; else theRes = 1; }
theRes | out, 0 on error, != 0 on success. | |
theNum | out, number of bytes successfully read from the file. | |
aBuf | in, pointer to the buffer where to read the data. | |
aNum | in, number of bytes to read. | |
anFD | in, descriptor of the file, from which to read. |
#define FILEIO_SEEK | ( | theRes, | |||
anFD, | |||||
aShift, | |||||
aPos | ) |
Value:
{ \ if (lseek(anFD, aShift, aPos) == (size_t) -1) theRes = 0; else theRes = 1; \ }
theRes | out, 0 on error, != 0 on success. | |
anFD | in, file descriptor. | |
aShift | in, number of bytes by which to move the pointer. | |
aPos | in, position from which to move the pointer, it may be either FILEIO_SEEKBEG or FILEIO_SEEKCUR. |
#define FILEIO_SEEKBEG SEEK_SET |
#define FILEIO_SEEKCUR SEEK_CUR |
#define FILEIO_SIZE | ( | theRes, | |||
anFD | ) |
Value:
{\ struct stat st; \ if (fstat(anFD, &st) == 0) theRes = st.st_size; else theRes = 0; \ }
theRes | out, the resulting size of the file, 0 for empty files or errors. | |
anFD | in, file descriptor. |
#define FILEIO_WR | ( | theNum, | |||
aBuf, | |||||
aNum, | |||||
anFD | ) | theNum = write(anFD, aBuf, aNum) |
Writes to a file.
theNum | out, number of bytes written. | |
aBuf | in, pointer to the buffer from which to write the data. | |
aNum | in, number of bytes to write. | |
anFD | in, descriptor of the file into which to wrie the data. |
Type for the file name.
TCHAR for windows, const char * for the rest of the world.
File handle.
HANDLE for Windows, int for the remaining part of the world.