summaryrefslogtreecommitdiff
path: root/openbsd-compat/posix_win.c
diff options
context:
space:
mode:
authornicoo <nicoo@debian.org>2020-02-12 13:43:18 +0100
committerNicolas Braud-Santoni <nicolas@braud-santoni.eu>2020-02-12 13:43:18 +0100
commit88a8bdd35ca7fb0c1ce70abdd8262d958fedafc1 (patch)
treece42d9d46d371c05eed82d8bb1e8aa7b2522a769 /openbsd-compat/posix_win.c
parent4e06e4554b69e678110563b1cf00a258a202dd7b (diff)
parentc79050aa44b8836d836c5dd22a383a073c28b74b (diff)
Merge upstream release 1.3.0 into debian/sid
Diffstat (limited to 'openbsd-compat/posix_win.c')
-rw-r--r--openbsd-compat/posix_win.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/openbsd-compat/posix_win.c b/openbsd-compat/posix_win.c
new file mode 100644
index 0000000..eac67c2
--- /dev/null
+++ b/openbsd-compat/posix_win.c
@@ -0,0 +1,61 @@
1/*
2 * Public domain
3 *
4 * File IO compatibility shims
5 * Brent Cook <bcook@openbsd.org>
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
17int
18posix_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
35int
36posix_close(int fd)
37{
38 return (close(fd));
39}
40
41ssize_t
42posix_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
52ssize_t
53posix_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}