diff options
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2010-04-14 06:51:11 +0200 |
---|---|---|
committer | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2010-09-10 19:28:25 +1000 |
commit | 3d88e4b6c9d3bb7b5eb75575049ed6d06f47bcd9 (patch) | |
tree | ee2ddec9412c8a61a6f660b7b3ebfe3b08837a31 | |
parent | 7a7312a3a10b3f580d7e149d814609660703d53b (diff) | |
download | busybox-w32-3d88e4b6c9d3bb7b5eb75575049ed6d06f47bcd9.tar.gz busybox-w32-3d88e4b6c9d3bb7b5eb75575049ed6d06f47bcd9.tar.bz2 busybox-w32-3d88e4b6c9d3bb7b5eb75575049ed6d06f47bcd9.zip |
win32: Replace open/fopen to support /dev/null
-rw-r--r-- | include/mingw.h | 4 | ||||
-rw-r--r-- | win32/mingw.c | 34 |
2 files changed, 38 insertions, 0 deletions
diff --git a/include/mingw.h b/include/mingw.h index 57fa6177d..ba73c362e 100644 --- a/include/mingw.h +++ b/include/mingw.h | |||
@@ -120,6 +120,8 @@ NOIMPL(sigfillset,int *mask UNUSED_PARAM); | |||
120 | #define fseeko(f,o,w) fseek(f,o,w) | 120 | #define fseeko(f,o,w) fseek(f,o,w) |
121 | 121 | ||
122 | int fdprintf(int fd, const char *format, ...); | 122 | int fdprintf(int fd, const char *format, ...); |
123 | FILE* mingw_fopen(const char *filename, const char *mode); | ||
124 | #define fopen mingw_fopen | ||
123 | 125 | ||
124 | /* | 126 | /* |
125 | * ANSI emulation wrappers | 127 | * ANSI emulation wrappers |
@@ -269,6 +271,7 @@ IMPL(fsync,int,0,int fd UNUSED_PARAM); | |||
269 | NOIMPL(kill,pid_t pid UNUSED_PARAM, int sig UNUSED_PARAM); | 271 | NOIMPL(kill,pid_t pid UNUSED_PARAM, int sig UNUSED_PARAM); |
270 | int link(const char *oldpath, const char *newpath); | 272 | int link(const char *oldpath, const char *newpath); |
271 | NOIMPL(mknod,const char *name UNUSED_PARAM, mode_t mode UNUSED_PARAM, dev_t device UNUSED_PARAM); | 273 | NOIMPL(mknod,const char *name UNUSED_PARAM, mode_t mode UNUSED_PARAM, dev_t device UNUSED_PARAM); |
274 | int mingw_open (const char *filename, int oflags, ...); | ||
272 | int pipe(int filedes[2]); | 275 | int pipe(int filedes[2]); |
273 | NOIMPL(readlink,const char *path UNUSED_PARAM, char *buf UNUSED_PARAM, size_t bufsiz UNUSED_PARAM); | 276 | NOIMPL(readlink,const char *path UNUSED_PARAM, char *buf UNUSED_PARAM, size_t bufsiz UNUSED_PARAM); |
274 | NOIMPL(setgid,gid_t gid UNUSED_PARAM); | 277 | NOIMPL(setgid,gid_t gid UNUSED_PARAM); |
@@ -282,6 +285,7 @@ NOIMPL(vfork,void); | |||
282 | 285 | ||
283 | #define getcwd mingw_getcwd | 286 | #define getcwd mingw_getcwd |
284 | #define lchown(a,b,c) chown(a,b,c) | 287 | #define lchown(a,b,c) chown(a,b,c) |
288 | #define open mingw_open | ||
285 | #define unlink mingw_unlink | 289 | #define unlink mingw_unlink |
286 | 290 | ||
287 | /* | 291 | /* |
diff --git a/win32/mingw.c b/win32/mingw.c index 5604fdda5..cc266462f 100644 --- a/win32/mingw.c +++ b/win32/mingw.c | |||
@@ -115,6 +115,40 @@ static int err_win_to_posix(DWORD winerr) | |||
115 | return error; | 115 | return error; |
116 | } | 116 | } |
117 | 117 | ||
118 | #undef open | ||
119 | int mingw_open (const char *filename, int oflags, ...) | ||
120 | { | ||
121 | va_list args; | ||
122 | unsigned mode; | ||
123 | int fd; | ||
124 | |||
125 | va_start(args, oflags); | ||
126 | mode = va_arg(args, int); | ||
127 | va_end(args); | ||
128 | |||
129 | if (oflags & O_NONBLOCK) { | ||
130 | errno = ENOSYS; | ||
131 | return -1; | ||
132 | } | ||
133 | if (!strcmp(filename, "/dev/null")) | ||
134 | filename = "nul"; | ||
135 | fd = open(filename, oflags, mode); | ||
136 | if (fd < 0 && (oflags & O_CREAT) && errno == EACCES) { | ||
137 | DWORD attrs = GetFileAttributes(filename); | ||
138 | if (attrs != INVALID_FILE_ATTRIBUTES && (attrs & FILE_ATTRIBUTE_DIRECTORY)) | ||
139 | errno = EISDIR; | ||
140 | } | ||
141 | return fd; | ||
142 | } | ||
143 | |||
144 | #undef fopen | ||
145 | FILE *mingw_fopen (const char *filename, const char *mode) | ||
146 | { | ||
147 | if (!strcmp(filename, "/dev/null")) | ||
148 | filename = "nul"; | ||
149 | return fopen(filename, mode); | ||
150 | } | ||
151 | |||
118 | unsigned int sleep (unsigned int seconds) | 152 | unsigned int sleep (unsigned int seconds) |
119 | { | 153 | { |
120 | Sleep(seconds*1000); | 154 | Sleep(seconds*1000); |