… | |
… | |
54 | #include <stdlib.h> |
54 | #include <stdlib.h> |
55 | #include <string.h> |
55 | #include <string.h> |
56 | #include <errno.h> |
56 | #include <errno.h> |
57 | #include <sys/types.h> |
57 | #include <sys/types.h> |
58 | #include <sys/stat.h> |
58 | #include <sys/stat.h> |
59 | #include <sys/statvfs.h> |
|
|
60 | #include <limits.h> |
59 | #include <limits.h> |
61 | #include <fcntl.h> |
60 | #include <fcntl.h> |
62 | #include <assert.h> |
61 | #include <assert.h> |
63 | |
62 | |
|
|
63 | #include <sys/statvfs.h> |
64 | /* intptr_t comes from unistd.h, says POSIX/UNIX/tradition */ |
64 | /* intptr_t comes from unistd.h, says POSIX/UNIX/tradition */ |
65 | /* intptr_t only comes from stdint.h, says idiot openbsd coder */ |
65 | /* intptr_t only comes from stdint.h, says idiot openbsd coder */ |
66 | #if HAVE_STDINT_H |
66 | #if HAVE_STDINT_H |
67 | # include <stdint.h> |
67 | # include <stdint.h> |
68 | #endif |
68 | #endif |
… | |
… | |
83 | |
83 | |
84 | #ifndef EIO_FEED |
84 | #ifndef EIO_FEED |
85 | # define EIO_FEED(req) do { if ((req)->feed ) (req)->feed (req); } while (0) |
85 | # define EIO_FEED(req) do { if ((req)->feed ) (req)->feed (req); } while (0) |
86 | #endif |
86 | #endif |
87 | |
87 | |
|
|
88 | #ifndef EIO_FD_TO_WIN32_HANDLE |
|
|
89 | # define EIO_FD_TO_WIN32_HANDLE(fd) _get_osfhandle (fd) |
|
|
90 | #endif |
|
|
91 | #ifndef EIO_WIN32_HANDLE_TO_FD |
|
|
92 | # define EIO_WIN32_HANDLE_TO_FD(handle) _open_osfhandle (handle, 0) |
|
|
93 | #endif |
|
|
94 | |
|
|
95 | #define EIO_ERRNO(errval,retval) ((errno = errval), retval) |
|
|
96 | |
|
|
97 | #define EIO_ENOSYS() EIO_ERRNO (ENOSYS, -1) |
|
|
98 | |
88 | #ifdef _WIN32 |
99 | #ifdef _WIN32 |
89 | |
100 | |
90 | /*doh*/ |
101 | #define PAGESIZE 4096 /* GetSystemInfo? */ |
|
|
102 | |
|
|
103 | #define stat(path,buf) _stati64 (path,buf) |
|
|
104 | #define lstat(path,buf) stat (path,buf) |
|
|
105 | #define fstat(fd,buf) _fstati64 (path,buf) |
|
|
106 | #define fsync(fd) (FlushFileBuffers (EIO_FD_TO_WIN32_HANDLE (fd)) ? 0 : EIO_ERRNO (EBADF, -1)) |
|
|
107 | #define mkdir(path,mode) _mkdir (path) |
|
|
108 | #define link(old,neu) (CreateHardLink (neu, old, 0) ? 0 : EIO_ERRNO (ENOENT, -1)) |
|
|
109 | |
|
|
110 | #define chown(path,uid,gid) EIO_ENOSYS () |
|
|
111 | #define fchown(fd,uid,gid) EIO_ENOSYS () |
|
|
112 | #define truncate(path,offs) EIO_ENOSYS () /* far-miss: SetEndOfFile */ |
|
|
113 | #define ftruncate(fd,offs) EIO_ENOSYS () /* near-miss: SetEndOfFile */ |
|
|
114 | #define mknod(path,mode,dev) EIO_ENOSYS () |
|
|
115 | #define sync() EIO_ENOSYS () |
|
|
116 | |
|
|
117 | /* we could even stat and see if it exists */ |
|
|
118 | static int |
|
|
119 | symlink (const char *old, const char *neu) |
|
|
120 | { |
|
|
121 | if (CreateSymbolicLink (neu, old, 1)) |
|
|
122 | return 0; |
|
|
123 | |
|
|
124 | if (CreateSymbolicLink (neu, old, 0)) |
|
|
125 | return 0; |
|
|
126 | |
|
|
127 | return EIO_ERRNO (ENOENT, -1); |
|
|
128 | } |
|
|
129 | |
91 | #else |
130 | #else |
92 | |
131 | |
93 | # include <sys/time.h> |
132 | #include <sys/time.h> |
94 | # include <sys/select.h> |
133 | #include <sys/select.h> |
|
|
134 | #include <sys/statvfs.h> |
95 | # include <unistd.h> |
135 | #include <unistd.h> |
96 | # include <utime.h> |
136 | #include <utime.h> |
97 | # include <signal.h> |
137 | #include <signal.h> |
98 | # include <dirent.h> |
138 | #include <dirent.h> |
99 | |
139 | |
100 | #if _POSIX_MEMLOCK || _POSIX_MEMLOCK_RANGE || _POSIX_MAPPED_FILES |
140 | #if _POSIX_MEMLOCK || _POSIX_MEMLOCK_RANGE || _POSIX_MAPPED_FILES |
101 | # include <sys/mman.h> |
141 | #include <sys/mman.h> |
102 | #endif |
142 | #endif |
103 | |
143 | |
104 | /* POSIX_SOURCE is useless on bsd's, and XOPEN_SOURCE is unreliable there, too */ |
144 | /* POSIX_SOURCE is useless on bsd's, and XOPEN_SOURCE is unreliable there, too */ |
105 | # if __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ |
145 | #if __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ |
106 | # define _DIRENT_HAVE_D_TYPE /* sigh */ |
146 | #define _DIRENT_HAVE_D_TYPE /* sigh */ |
107 | # define D_INO(de) (de)->d_fileno |
147 | #define D_INO(de) (de)->d_fileno |
108 | # define D_NAMLEN(de) (de)->d_namlen |
148 | #define D_NAMLEN(de) (de)->d_namlen |
109 | # elif __linux || defined d_ino || _XOPEN_SOURCE >= 600 |
149 | #elif __linux || defined d_ino || _XOPEN_SOURCE >= 600 |
110 | # define D_INO(de) (de)->d_ino |
150 | #define D_INO(de) (de)->d_ino |
111 | # endif |
151 | #endif |
112 | |
152 | |
113 | #ifdef _D_EXACT_NAMLEN |
153 | #ifdef _D_EXACT_NAMLEN |
114 | # undef D_NAMLEN |
154 | #undef D_NAMLEN |
115 | # define D_NAMLEN(de) _D_EXACT_NAMLEN (de) |
155 | #define D_NAMLEN(de) _D_EXACT_NAMLEN (de) |
116 | #endif |
156 | #endif |
117 | |
157 | |
118 | # ifdef _DIRENT_HAVE_D_TYPE |
158 | #ifdef _DIRENT_HAVE_D_TYPE |
119 | # define D_TYPE(de) (de)->d_type |
159 | #define D_TYPE(de) (de)->d_type |
120 | # endif |
160 | #endif |
121 | |
161 | |
122 | # ifndef EIO_STRUCT_DIRENT |
162 | #ifndef EIO_STRUCT_DIRENT |
123 | # define EIO_STRUCT_DIRENT struct dirent |
163 | #define EIO_STRUCT_DIRENT struct dirent |
124 | # endif |
164 | #endif |
125 | |
165 | |
126 | #endif |
166 | #endif |
127 | |
167 | |
128 | #if HAVE_SENDFILE |
168 | #if HAVE_SENDFILE |
129 | # if __linux |
169 | # if __linux |
… | |
… | |
1042 | if (res < 0 && sbytes) |
1082 | if (res < 0 && sbytes) |
1043 | res = sbytes; |
1083 | res = sbytes; |
1044 | |
1084 | |
1045 | # endif |
1085 | # endif |
1046 | |
1086 | |
1047 | #elif defined (_WIN32) |
1087 | #elif defined (_WIN32) && 0 |
1048 | /* does not work, just for documentation of what would need to be done */ |
1088 | /* does not work, just for documentation of what would need to be done */ |
1049 | /* actually, cannot be done like this, as TransmitFile changes the file offset, */ |
1089 | /* actually, cannot be done like this, as TransmitFile changes the file offset, */ |
1050 | /* libeio guarantees that the file offset does not change, and windows */ |
1090 | /* libeio guarantees that the file offset does not change, and windows */ |
1051 | /* has no way to get an independent handle to the same file description */ |
1091 | /* has no way to get an independent handle to the same file description */ |
1052 | HANDLE h = TO_SOCKET (ifd); |
1092 | HANDLE h = TO_SOCKET (ifd); |
… | |
… | |
1157 | /* round up length */ |
1197 | /* round up length */ |
1158 | *length = (*length + mask) & ~mask; |
1198 | *length = (*length + mask) & ~mask; |
1159 | } |
1199 | } |
1160 | |
1200 | |
1161 | #if !_POSIX_MEMLOCK |
1201 | #if !_POSIX_MEMLOCK |
1162 | # define eio__mlockall(a) ((errno = ENOSYS), -1) |
1202 | # define eio__mlockall(a) eio_nosyscall() |
1163 | #else |
1203 | #else |
1164 | |
1204 | |
1165 | static int |
1205 | static int |
1166 | eio__mlockall (int flags) |
1206 | eio__mlockall (int flags) |
1167 | { |
1207 | { |
… | |
… | |
1181 | return mlockall (flags); |
1221 | return mlockall (flags); |
1182 | } |
1222 | } |
1183 | #endif |
1223 | #endif |
1184 | |
1224 | |
1185 | #if !_POSIX_MEMLOCK_RANGE |
1225 | #if !_POSIX_MEMLOCK_RANGE |
1186 | # define eio__mlock(a,b) ((errno = ENOSYS), -1) |
1226 | # define eio__mlock(a,b) EIO_ENOSYS () |
1187 | #else |
1227 | #else |
1188 | |
1228 | |
1189 | static int |
1229 | static int |
1190 | eio__mlock (void *addr, size_t length) |
1230 | eio__mlock (void *addr, size_t length) |
1191 | { |
1231 | { |
… | |
… | |
1195 | } |
1235 | } |
1196 | |
1236 | |
1197 | #endif |
1237 | #endif |
1198 | |
1238 | |
1199 | #if !(_POSIX_MAPPED_FILES && _POSIX_SYNCHRONIZED_IO) |
1239 | #if !(_POSIX_MAPPED_FILES && _POSIX_SYNCHRONIZED_IO) |
1200 | # define eio__msync(a,b,c) ((errno = ENOSYS), -1) |
1240 | # define eio__msync(a,b,c) EIO_ENOSYS () |
1201 | #else |
1241 | #else |
1202 | |
1242 | |
1203 | static int |
1243 | static int |
1204 | eio__msync (void *mem, size_t len, int flags) |
1244 | eio__msync (void *mem, size_t len, int flags) |
1205 | { |
1245 | { |