| 1 |
/* |
| 2 |
* Public domain |
| 3 |
* |
| 4 |
* File IO compatibility shims |
| 5 |
* Brent Cook <[email protected]> |
| 6 |
*/ |
| 7 |
|
| 8 |
#define NO_REDEF_POSIX_FUNCTIONS |
| 9 |
|
| 10 |
#include <windows.h> |
| 11 |
|
| 12 |
#include <errno.h> |
| 13 |
#include <io.h> |
| 14 |
|
| 15 |
#include "posix_win.h" |
| 16 |
|
| 17 |
int |
| 18 |
posix_open(const char *path, ...) |
| 19 |
{ |
| 20 |
va_list ap; |
| 21 |
int mode = 0; |
| 22 |
int flags; |
| 23 |
|
| 24 |
va_start(ap, path); |
| 25 |
flags = va_arg(ap, int); |
| 26 |
if (flags & O_CREAT) |
| 27 |
mode = va_arg(ap, int); |
| 28 |
va_end(ap); |
| 29 |
|
| 30 |
flags |= O_BINARY | O_NOINHERIT; |
| 31 |
|
| 32 |
return (open(path, flags, mode)); |
| 33 |
} |
| 34 |
|
| 35 |
int |
| 36 |
posix_close(int fd) |
| 37 |
{ |
| 38 |
return (close(fd)); |
| 39 |
} |
| 40 |
|
| 41 |
ssize_t |
| 42 |
posix_read(int fd, void *buf, size_t count) |
| 43 |
{ |
| 44 |
if (count > INT_MAX) { |
| 45 |
errno = EINVAL; |
| 46 |
return (-1); |
| 47 |
} |
| 48 |
|
| 49 |
return (read(fd, buf, (unsigned int)count)); |
| 50 |
} |
| 51 |
|
| 52 |
ssize_t |
| 53 |
posix_write(int fd, const void *buf, size_t count) |
| 54 |
{ |
| 55 |
if (count > INT_MAX) { |
| 56 |
errno = EINVAL; |
| 57 |
return (-1); |
| 58 |
} |
| 59 |
|
| 60 |
return (write(fd, buf, (unsigned int)count)); |
| 61 |
} |