]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - libarchive/archive_windows.h
Update vendor/libarchive/dist to git d6d3799d6b309593f271c4c319dfba92efc95772
[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 #ifndef MINGW_HAS_SECURE_API
53 #define MINGW_HAS_SECURE_API 1
54 #endif
55
56 #include <errno.h>
57 #define set_errno(val)  ((errno)=val)
58 #include <io.h>
59 #include <stdlib.h>   //brings in NULL
60 #if defined(HAVE_STDINT_H)
61 #include <stdint.h>
62 #endif
63 #include <stdio.h>
64 #include <fcntl.h>
65 #include <sys/stat.h>
66 #include <process.h>
67 #include <direct.h>
68 #if defined(__MINGW32__) && defined(HAVE_UNISTD_H)
69 /* Prevent build error from a type mismatch of ftruncate().
70  * This unistd.h defines it as ftruncate(int, off_t). */
71 #include <unistd.h>
72 #endif
73 #define NOCRYPT
74 #include <windows.h>
75 //#define       EFTYPE 7
76
77 #if defined(__BORLANDC__)
78 #pragma warn -8068      /* Constant out of range in comparison. */
79 #pragma warn -8072      /* Suspicious pointer arithmetic. */
80 #endif
81
82 #ifndef NULL
83 #ifdef  __cplusplus
84 #define NULL    0
85 #else
86 #define NULL    ((void *)0)
87 #endif
88 #endif
89
90 /* Alias the Windows _function to the POSIX equivalent. */
91 #define close           _close
92 #define fcntl(fd, cmd, flg)     /* No operation. */
93 #ifndef fileno
94 #define fileno          _fileno
95 #endif
96 #ifdef fstat
97 #undef fstat
98 #endif
99 #define fstat           __la_fstat
100 #if !defined(__BORLANDC__)
101 #ifdef lseek
102 #undef lseek
103 #endif
104 #define lseek           _lseeki64
105 #else
106 #define lseek           __la_lseek
107 #define __LA_LSEEK_NEEDED
108 #endif
109 #define lstat           __la_stat
110 #define open            __la_open
111 #define read            __la_read
112 #if !defined(__BORLANDC__) && !defined(__WATCOMC__)
113 #define setmode         _setmode
114 #endif
115 #define la_stat(path,stref)             __la_stat(path,stref)
116 #if !defined(__WATCOMC__)
117 #if !defined(__BORLANDC__)
118 #define strdup          _strdup
119 #endif
120 #define tzset           _tzset
121 #if !defined(__BORLANDC__)
122 #define umask           _umask
123 #endif
124 #endif
125 #define waitpid         __la_waitpid
126 #define write           __la_write
127
128 #if !defined(__WATCOMC__)
129
130 #ifndef O_RDONLY
131 #define O_RDONLY        _O_RDONLY
132 #define O_WRONLY        _O_WRONLY
133 #define O_TRUNC         _O_TRUNC
134 #define O_CREAT         _O_CREAT
135 #define O_EXCL          _O_EXCL
136 #define O_BINARY        _O_BINARY
137 #endif
138
139 #ifndef _S_IFIFO
140   #define       _S_IFIFO        0010000   /* pipe */
141 #endif
142 #ifndef _S_IFCHR
143   #define       _S_IFCHR        0020000   /* character special */
144 #endif
145 #ifndef _S_IFDIR
146   #define       _S_IFDIR        0040000   /* directory */
147 #endif
148 #ifndef _S_IFBLK
149   #define       _S_IFBLK        0060000   /* block special */
150 #endif
151 #ifndef _S_IFLNK
152   #define       _S_IFLNK        0120000   /* symbolic link */
153 #endif
154 #ifndef _S_IFSOCK
155   #define       _S_IFSOCK       0140000   /* socket */
156 #endif
157 #ifndef _S_IFREG
158   #define       _S_IFREG        0100000   /* regular */
159 #endif
160 #ifndef _S_IFMT
161   #define       _S_IFMT         0170000   /* file type mask */
162 #endif
163
164 #ifndef S_IFIFO
165 #define S_IFIFO     _S_IFIFO
166 #endif
167 //#define       S_IFCHR  _S_IFCHR
168 //#define       S_IFDIR  _S_IFDIR
169 #ifndef S_IFBLK
170 #define S_IFBLK     _S_IFBLK
171 #endif
172 #ifndef S_IFLNK
173 #define S_IFLNK     _S_IFLNK
174 #endif
175 #ifndef S_IFSOCK
176 #define S_IFSOCK    _S_IFSOCK
177 #endif
178 //#define       S_IFREG  _S_IFREG
179 //#define       S_IFMT   _S_IFMT
180
181 #ifndef S_ISBLK
182 #define S_ISBLK(m)      (((m) & S_IFMT) == S_IFBLK)     /* block special */
183 #define S_ISFIFO(m)     (((m) & S_IFMT) == S_IFIFO)     /* fifo or socket */
184 #define S_ISCHR(m)      (((m) & S_IFMT) == S_IFCHR)     /* char special */
185 #define S_ISDIR(m)      (((m) & S_IFMT) == S_IFDIR)     /* directory */
186 #define S_ISREG(m)      (((m) & S_IFMT) == S_IFREG)     /* regular file */
187 #endif
188 #define S_ISLNK(m)  (((m) & S_IFMT) == S_IFLNK) /* Symbolic link */
189 #define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK) /* Socket */
190
191 #define _S_ISUID        0004000   /* set user id on execution */
192 #define _S_ISGID        0002000   /* set group id on execution */
193 #define _S_ISVTX        0001000   /* save swapped text even after use */
194
195 #define S_ISUID        _S_ISUID
196 #define S_ISGID        _S_ISGID
197 #define S_ISVTX        _S_ISVTX
198
199 #define _S_IRWXU             (_S_IREAD | _S_IWRITE | _S_IEXEC)
200 #define _S_IXUSR             _S_IEXEC  /* read permission, user */
201 #define _S_IWUSR             _S_IWRITE /* write permission, user */
202 #define _S_IRUSR             _S_IREAD  /* execute/search permission, user */
203 #define _S_IRWXG        (_S_IRWXU >> 3)
204 #define _S_IXGRP        (_S_IXUSR >> 3) /* read permission, group */
205 #define _S_IWGRP        (_S_IWUSR >> 3) /* write permission, group */
206 #define _S_IRGRP        (_S_IRUSR >> 3) /* execute/search permission, group */
207 #define _S_IRWXO        (_S_IRWXG >> 3)
208 #define _S_IXOTH        (_S_IXGRP >> 3) /* read permission, other */
209 #define _S_IWOTH        (_S_IWGRP >> 3) /* write permission, other */
210 #define _S_IROTH        (_S_IRGRP  >> 3) /* execute/search permission, other */
211
212 #ifndef S_IRWXU
213 #define S_IRWXU      _S_IRWXU
214 #define S_IXUSR      _S_IXUSR
215 #define S_IWUSR      _S_IWUSR
216 #define S_IRUSR      _S_IRUSR
217 #endif
218 #ifndef S_IRWXG
219 #define S_IRWXG        _S_IRWXG
220 #define S_IXGRP        _S_IXGRP
221 #define S_IWGRP        _S_IWGRP
222 #endif
223 #ifndef S_IRGRP
224 #define S_IRGRP        _S_IRGRP
225 #endif
226 #ifndef S_IRWXO
227 #define S_IRWXO        _S_IRWXO
228 #define S_IXOTH        _S_IXOTH
229 #define S_IWOTH        _S_IWOTH
230 #define S_IROTH        _S_IROTH
231 #endif
232
233 #endif
234
235 #define F_DUPFD         0       /* Duplicate file descriptor.  */
236 #define F_GETFD         1       /* Get file descriptor flags.  */
237 #define F_SETFD         2       /* Set file descriptor flags.  */
238 #define F_GETFL         3       /* Get file status flags.  */
239 #define F_SETFL         4       /* Set file status flags.  */
240 #define F_GETOWN                5       /* Get owner (receiver of SIGIO).  */
241 #define F_SETOWN                6       /* Set owner (receiver of SIGIO).  */
242 #define F_GETLK         7       /* Get record locking info.  */
243 #define F_SETLK         8       /* Set record locking info (non-blocking).  */
244 #define F_SETLKW                9       /* Set record locking info (blocking).  */
245
246 /* XXX missing */
247 #define F_GETLK64       7       /* Get record locking info.  */
248 #define F_SETLK64       8       /* Set record locking info (non-blocking).  */
249 #define F_SETLKW64      9       /* Set record locking info (blocking).  */
250
251 /* File descriptor flags used with F_GETFD and F_SETFD.  */
252 #define FD_CLOEXEC      1       /* Close on exec.  */
253
254 //NOT SURE IF O_NONBLOCK is OK here but at least the 0x0004 flag is not used by anything else...
255 #define O_NONBLOCK 0x0004 /* Non-blocking I/O.  */
256 //#define       O_NDELAY   O_NONBLOCK
257
258 /* Symbolic constants for the access() function */
259 #if !defined(F_OK)
260     #define     R_OK    4       /*  Test for read permission    */
261     #define     W_OK    2       /*  Test for write permission   */
262     #define     X_OK    1       /*  Test for execute permission */
263     #define     F_OK    0       /*  Test for existence of file  */
264 #endif
265
266
267 /* Replacement POSIX function */
268 extern int       __la_fstat(int fd, struct stat *st);
269 extern int       __la_lstat(const char *path, struct stat *st);
270 #if defined(__LA_LSEEK_NEEDED)
271 extern __int64   __la_lseek(int fd, __int64 offset, int whence);
272 #endif
273 extern int       __la_open(const char *path, int flags, ...);
274 extern ssize_t   __la_read(int fd, void *buf, size_t nbytes);
275 extern int       __la_stat(const char *path, struct stat *st);
276 extern pid_t     __la_waitpid(HANDLE child, int *status, int option);
277 extern ssize_t   __la_write(int fd, const void *buf, size_t nbytes);
278
279 #define _stat64i32(path, st)    __la_stat(path, st)
280 #define _stat64(path, st)       __la_stat(path, st)
281 /* for status returned by la_waitpid */
282 #define WIFEXITED(sts)          ((sts & 0x100) == 0)
283 #define WEXITSTATUS(sts)        (sts & 0x0FF)
284
285 extern wchar_t *__la_win_permissive_name(const char *name);
286 extern wchar_t *__la_win_permissive_name_w(const wchar_t *wname);
287 extern void __la_dosmaperr(unsigned long e);
288 #define la_dosmaperr(e) __la_dosmaperr(e)
289 extern struct archive_entry *__la_win_entry_in_posix_pathseparator(
290     struct archive_entry *);
291
292 #if defined(HAVE_WCRTOMB) && defined(__BORLANDC__)
293 typedef int mbstate_t;
294 size_t wcrtomb(char *, wchar_t, mbstate_t *);
295 #endif
296
297 #if defined(_MSC_VER) && _MSC_VER < 1300
298 WINBASEAPI BOOL WINAPI GetVolumePathNameW(
299        LPCWSTR lpszFileName,
300        LPWSTR lpszVolumePathName,
301        DWORD cchBufferLength
302        );
303 # if _WIN32_WINNT < 0x0500 /* windows.h not providing 0x500 API */
304 typedef struct _FILE_ALLOCATED_RANGE_BUFFER {
305        LARGE_INTEGER FileOffset;
306        LARGE_INTEGER Length;
307 } FILE_ALLOCATED_RANGE_BUFFER, *PFILE_ALLOCATED_RANGE_BUFFER;
308 #  define FSCTL_SET_SPARSE \
309      CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 49, METHOD_BUFFERED, FILE_WRITE_DATA)
310 #  define FSCTL_QUERY_ALLOCATED_RANGES \
311      CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 51,  METHOD_NEITHER, FILE_READ_DATA)
312 # endif
313 #endif
314
315 #endif /* LIBARCHIVE_ARCHIVE_WINDOWS_H_INCLUDED */