2 * Copyright (c) 2009-2011 Michihiro NAKAJIMA
3 * Copyright (c) 2003-2006 Tim Kientzle
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer
11 * in this position and unchanged.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #ifndef __LIBARCHIVE_BUILD
31 #error This header is only to be used internally to libarchive.
35 * TODO: A lot of stuff in here isn't actually used by libarchive and
36 * can be trimmed out. Note that this file is used by libarchive and
37 * libarchive_test but nowhere else. (But note that it gets compiled
38 * with many different Windows environments, including MinGW, Visual
39 * Studio, and Cygwin. Significant changes should be tested in all three.)
43 * TODO: Don't use off_t in here. Use __int64 instead. Note that
44 * Visual Studio and the Windows SDK define off_t as 32 bits; Win32's
45 * more modern file handling APIs all use __int64 instead of off_t.
48 #ifndef LIBARCHIVE_ARCHIVE_WINDOWS_H_INCLUDED
49 #define LIBARCHIVE_ARCHIVE_WINDOWS_H_INCLUDED
51 /* Start of configuration for native Win32 */
54 #define set_errno(val) ((errno)=val)
56 #include <stdlib.h> //brings in NULL
57 #if defined(HAVE_STDINT_H)
65 #if defined(__MINGW32__) && defined(HAVE_UNISTD_H)
66 /* Prevent build error from a type mismatch of ftruncate().
67 * This unistd.h defines it as ftruncate(int, off_t). */
75 /* TODO: Fix the code, don't suppress the warnings. */
76 #pragma warning(disable:4244) /* 'conversion' conversion from 'type1' to 'type2', possible loss of data */
78 #if defined(__BORLANDC__)
79 #pragma warn -8068 /* Constant out of range in comparison. */
80 #pragma warn -8072 /* Suspicious pointer arithmetic. */
87 #define NULL ((void *)0)
91 /* Alias the Windows _function to the POSIX equivalent. */
93 #define fcntl(fd, cmd, flg) /* No operation. */
95 #define fileno _fileno
97 #define fstat __la_fstat
98 #define lseek _lseeki64
99 #define lstat __la_stat
100 #define open __la_open
101 #define read __la_read
102 #if !defined(__BORLANDC__)
103 #define setmode _setmode
105 #define stat(path,stref) __la_stat(path,stref)
106 #if !defined(__BORLANDC__)
107 #define strdup _strdup
110 #if !defined(__BORLANDC__)
113 #define waitpid __la_waitpid
114 #define write __la_write
117 #define O_RDONLY _O_RDONLY
118 #define O_WRONLY _O_WRONLY
119 #define O_TRUNC _O_TRUNC
120 #define O_CREAT _O_CREAT
121 #define O_EXCL _O_EXCL
122 #define O_BINARY _O_BINARY
126 #define _S_IFIFO 0010000 /* pipe */
129 #define _S_IFCHR 0020000 /* character special */
132 #define _S_IFDIR 0040000 /* directory */
135 #define _S_IFBLK 0060000 /* block special */
138 #define _S_IFLNK 0120000 /* symbolic link */
141 #define _S_IFSOCK 0140000 /* socket */
144 #define _S_IFREG 0100000 /* regular */
147 #define _S_IFMT 0170000 /* file type mask */
151 #define S_IFIFO _S_IFIFO
153 //#define S_IFCHR _S_IFCHR
154 //#define S_IFDIR _S_IFDIR
156 #define S_IFBLK _S_IFBLK
159 #define S_IFLNK _S_IFLNK
162 #define S_IFSOCK _S_IFSOCK
164 //#define S_IFREG _S_IFREG
165 //#define S_IFMT _S_IFMT
168 #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) /* block special */
169 #define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) /* fifo or socket */
170 #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) /* char special */
171 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) /* directory */
172 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) /* regular file */
174 #define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) /* Symbolic link */
175 #define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK) /* Socket */
177 #define _S_ISUID 0004000 /* set user id on execution */
178 #define _S_ISGID 0002000 /* set group id on execution */
179 #define _S_ISVTX 0001000 /* save swapped text even after use */
181 #define S_ISUID _S_ISUID
182 #define S_ISGID _S_ISGID
183 #define S_ISVTX _S_ISVTX
185 #define _S_IRWXU (_S_IREAD | _S_IWRITE | _S_IEXEC)
186 #define _S_IXUSR _S_IEXEC /* read permission, user */
187 #define _S_IWUSR _S_IWRITE /* write permission, user */
188 #define _S_IRUSR _S_IREAD /* execute/search permission, user */
189 #define _S_IRWXG (_S_IRWXU >> 3)
190 #define _S_IXGRP (_S_IXUSR >> 3) /* read permission, group */
191 #define _S_IWGRP (_S_IWUSR >> 3) /* write permission, group */
192 #define _S_IRGRP (_S_IRUSR >> 3) /* execute/search permission, group */
193 #define _S_IRWXO (_S_IRWXG >> 3)
194 #define _S_IXOTH (_S_IXGRP >> 3) /* read permission, other */
195 #define _S_IWOTH (_S_IWGRP >> 3) /* write permission, other */
196 #define _S_IROTH (_S_IRGRP >> 3) /* execute/search permission, other */
199 #define S_IRWXU _S_IRWXU
200 #define S_IXUSR _S_IXUSR
201 #define S_IWUSR _S_IWUSR
202 #define S_IRUSR _S_IRUSR
204 #define S_IRWXG _S_IRWXG
205 #define S_IXGRP _S_IXGRP
206 #define S_IWGRP _S_IWGRP
207 #define S_IRGRP _S_IRGRP
208 #define S_IRWXO _S_IRWXO
209 #define S_IXOTH _S_IXOTH
210 #define S_IWOTH _S_IWOTH
211 #define S_IROTH _S_IROTH
213 #define F_DUPFD 0 /* Duplicate file descriptor. */
214 #define F_GETFD 1 /* Get file descriptor flags. */
215 #define F_SETFD 2 /* Set file descriptor flags. */
216 #define F_GETFL 3 /* Get file status flags. */
217 #define F_SETFL 4 /* Set file status flags. */
218 #define F_GETOWN 5 /* Get owner (receiver of SIGIO). */
219 #define F_SETOWN 6 /* Set owner (receiver of SIGIO). */
220 #define F_GETLK 7 /* Get record locking info. */
221 #define F_SETLK 8 /* Set record locking info (non-blocking). */
222 #define F_SETLKW 9 /* Set record locking info (blocking). */
225 #define F_GETLK64 7 /* Get record locking info. */
226 #define F_SETLK64 8 /* Set record locking info (non-blocking). */
227 #define F_SETLKW64 9 /* Set record locking info (blocking). */
229 /* File descriptor flags used with F_GETFD and F_SETFD. */
230 #define FD_CLOEXEC 1 /* Close on exec. */
232 //NOT SURE IF O_NONBLOCK is OK here but at least the 0x0004 flag is not used by anything else...
233 #define O_NONBLOCK 0x0004 /* Non-blocking I/O. */
234 //#define O_NDELAY O_NONBLOCK
236 /* Symbolic constants for the access() function */
238 #define R_OK 4 /* Test for read permission */
239 #define W_OK 2 /* Test for write permission */
240 #define X_OK 1 /* Test for execute permission */
241 #define F_OK 0 /* Test for existence of file */
245 /* Replacement POSIX function */
246 extern int __la_fstat(int fd, struct stat *st);
247 extern int __la_lstat(const char *path, struct stat *st);
248 extern int __la_open(const char *path, int flags, ...);
249 extern ssize_t __la_read(int fd, void *buf, size_t nbytes);
250 extern int __la_stat(const char *path, struct stat *st);
251 extern pid_t __la_waitpid(pid_t wpid, int *status, int option);
252 extern ssize_t __la_write(int fd, const void *buf, size_t nbytes);
254 #define _stat64i32(path, st) __la_stat(path, st)
255 #define _stat64(path, st) __la_stat(path, st)
256 /* for status returned by la_waitpid */
257 #define WIFEXITED(sts) ((sts & 0x100) == 0)
258 #define WEXITSTATUS(sts) (sts & 0x0FF)
260 extern wchar_t *__la_win_permissive_name(const char *name);
261 extern wchar_t *__la_win_permissive_name_w(const wchar_t *wname);
262 extern void __la_dosmaperr(unsigned long e);
263 #define la_dosmaperr(e) __la_dosmaperr(e)
266 #endif /* LIBARCHIVE_ARCHIVE_WINDOWS_H_INCLUDED */