]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - libarchive/archive_windows.h
Update vendor libarchive dist to new "release" branch (post 3.0.3)
[FreeBSD/FreeBSD.git] / libarchive / archive_windows.h
1 /*-
2  * Copyright (c) 2009-2011 Michihiro NAKAJIMA
3  * Copyright (c) 2003-2006 Tim Kientzle
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
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.
15  *
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.
26  *
27  * $FreeBSD$
28  */
29
30 #ifndef __LIBARCHIVE_BUILD
31 #error This header is only to be used internally to libarchive.
32 #endif
33
34 /*
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.)
40  */
41
42 /*
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.
46  */
47
48 #ifndef LIBARCHIVE_ARCHIVE_WINDOWS_H_INCLUDED
49 #define LIBARCHIVE_ARCHIVE_WINDOWS_H_INCLUDED
50
51 /* Start of configuration for native Win32  */
52
53 #include <errno.h>
54 #define set_errno(val)  ((errno)=val)
55 #include <io.h>
56 #include <stdlib.h>   //brings in NULL
57 #if defined(HAVE_STDINT_H)
58 #include <stdint.h>
59 #endif
60 #include <stdio.h>
61 #include <fcntl.h>
62 #include <sys/stat.h>
63 #include <process.h>
64 #include <direct.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). */
68 #include <unistd.h>
69 #endif
70 #define NOCRYPT
71 #include <windows.h>
72 //#define       EFTYPE 7
73
74 #if defined(_MSC_VER)
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 */
77 #endif
78 #if defined(__BORLANDC__)
79 #pragma warn -8068      /* Constant out of range in comparison. */
80 #pragma warn -8072      /* Suspicious pointer arithmetic. */
81 #endif
82
83 #ifndef NULL
84 #ifdef  __cplusplus
85 #define NULL    0
86 #else
87 #define NULL    ((void *)0)
88 #endif
89 #endif
90
91 /* Alias the Windows _function to the POSIX equivalent. */
92 #define close           _close
93 #define fcntl(fd, cmd, flg)     /* No operation. */             
94 #ifndef fileno
95 #define fileno          _fileno
96 #endif
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
104 #endif
105 #define stat(path,stref)                __la_stat(path,stref)
106 #if !defined(__BORLANDC__)
107 #define strdup          _strdup
108 #endif
109 #define tzset           _tzset
110 #if !defined(__BORLANDC__)
111 #define umask           _umask
112 #endif
113 #define waitpid         __la_waitpid
114 #define write           __la_write
115
116 #ifndef O_RDONLY
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
123 #endif
124
125 #ifndef _S_IFIFO
126   #define       _S_IFIFO        0010000   /* pipe */
127 #endif
128 #ifndef _S_IFCHR
129   #define       _S_IFCHR        0020000   /* character special */
130 #endif
131 #ifndef _S_IFDIR
132   #define       _S_IFDIR        0040000   /* directory */
133 #endif
134 #ifndef _S_IFBLK
135   #define       _S_IFBLK        0060000   /* block special */
136 #endif
137 #ifndef _S_IFLNK
138   #define       _S_IFLNK        0120000   /* symbolic link */
139 #endif
140 #ifndef _S_IFSOCK
141   #define       _S_IFSOCK       0140000   /* socket */
142 #endif
143 #ifndef _S_IFREG
144   #define       _S_IFREG        0100000   /* regular */
145 #endif
146 #ifndef _S_IFMT
147   #define       _S_IFMT         0170000   /* file type mask */
148 #endif
149
150 #ifndef S_IFIFO
151 #define S_IFIFO     _S_IFIFO
152 #endif
153 //#define       S_IFCHR  _S_IFCHR
154 //#define       S_IFDIR  _S_IFDIR
155 #ifndef S_IFBLK
156 #define S_IFBLK     _S_IFBLK
157 #endif
158 #ifndef S_IFLNK
159 #define S_IFLNK     _S_IFLNK
160 #endif
161 #ifndef S_IFSOCK
162 #define S_IFSOCK    _S_IFSOCK
163 #endif
164 //#define       S_IFREG  _S_IFREG
165 //#define       S_IFMT   _S_IFMT
166
167 #ifndef S_ISBLK
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 */
173 #endif
174 #define S_ISLNK(m)  (((m) & S_IFMT) == S_IFLNK) /* Symbolic link */
175 #define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK) /* Socket */
176
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 */
180
181 #define S_ISUID        _S_ISUID
182 #define S_ISGID        _S_ISGID
183 #define S_ISVTX        _S_ISVTX
184
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 */
197
198 #ifndef S_IRWXU
199 #define S_IRWXU      _S_IRWXU
200 #define S_IXUSR      _S_IXUSR
201 #define S_IWUSR      _S_IWUSR
202 #define S_IRUSR      _S_IRUSR
203 #endif
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
212
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).  */
223
224 /* XXX missing */
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).  */
228
229 /* File descriptor flags used with F_GETFD and F_SETFD.  */
230 #define FD_CLOEXEC      1       /* Close on exec.  */
231
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
235
236 /* Symbolic constants for the access() function */
237 #if !defined(F_OK)
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  */
242 #endif
243
244
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);
253
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)
259
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)
264
265
266 #endif /* LIBARCHIVE_ARCHIVE_WINDOWS_H_INCLUDED */