|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 #ifndef UPDATEDEFINES_H |
|
6 #define UPDATEDEFINES_H |
|
7 |
|
8 #include "readstrings.h" |
|
9 |
|
10 #ifndef MAXPATHLEN |
|
11 # ifdef PATH_MAX |
|
12 # define MAXPATHLEN PATH_MAX |
|
13 # elif defined(MAX_PATH) |
|
14 # define MAXPATHLEN MAX_PATH |
|
15 # elif defined(_MAX_PATH) |
|
16 # define MAXPATHLEN _MAX_PATH |
|
17 # elif defined(CCHMAXPATH) |
|
18 # define MAXPATHLEN CCHMAXPATH |
|
19 # else |
|
20 # define MAXPATHLEN 1024 |
|
21 # endif |
|
22 #endif |
|
23 |
|
24 #if defined(XP_WIN) |
|
25 # include <windows.h> |
|
26 # include <shlwapi.h> |
|
27 # include <direct.h> |
|
28 # include <io.h> |
|
29 # include <stdio.h> |
|
30 # include <stdarg.h> |
|
31 |
|
32 # define F_OK 00 |
|
33 # define W_OK 02 |
|
34 # define R_OK 04 |
|
35 # define S_ISDIR(s) (((s) & _S_IFMT) == _S_IFDIR) |
|
36 # define S_ISREG(s) (((s) & _S_IFMT) == _S_IFREG) |
|
37 |
|
38 # define access _access |
|
39 |
|
40 # define putenv _putenv |
|
41 # define stat _stat |
|
42 # define DELETE_DIR L"tobedeleted" |
|
43 # define CALLBACK_BACKUP_EXT L".moz-callback" |
|
44 |
|
45 # define LOG_S "%S" |
|
46 # define NS_T(str) L ## str |
|
47 # define NS_SLASH NS_T('\\') |
|
48 // On Windows, _snprintf and _snwprintf don't guarantee null termination. These |
|
49 // macros always leave room in the buffer for null termination and set the end |
|
50 // of the buffer to null in case the string is larger than the buffer. Having |
|
51 // multiple nulls in a string is fine and this approach is simpler (possibly |
|
52 // faster) than calculating the string length to place the null terminator and |
|
53 // truncates the string as _snprintf and _snwprintf do on other platforms. |
|
54 static int mysnprintf(char* dest, size_t count, const char* fmt, ...) |
|
55 { |
|
56 size_t _count = count - 1; |
|
57 va_list varargs; |
|
58 va_start(varargs, fmt); |
|
59 int result = _vsnprintf(dest, count - 1, fmt, varargs); |
|
60 va_end(varargs); |
|
61 dest[_count] = '\0'; |
|
62 return result; |
|
63 } |
|
64 #define snprintf mysnprintf |
|
65 static int mywcsprintf(WCHAR* dest, size_t count, const WCHAR* fmt, ...) |
|
66 { |
|
67 size_t _count = count - 1; |
|
68 va_list varargs; |
|
69 va_start(varargs, fmt); |
|
70 int result = _vsnwprintf(dest, count - 1, fmt, varargs); |
|
71 va_end(varargs); |
|
72 dest[_count] = L'\0'; |
|
73 return result; |
|
74 } |
|
75 #define NS_tsnprintf mywcsprintf |
|
76 # define NS_taccess _waccess |
|
77 # define NS_tchdir _wchdir |
|
78 # define NS_tchmod _wchmod |
|
79 # define NS_tfopen _wfopen |
|
80 # define NS_tmkdir(path, perms) _wmkdir(path) |
|
81 # define NS_tremove _wremove |
|
82 // _wrename is used to avoid the link tracking service. |
|
83 # define NS_trename _wrename |
|
84 # define NS_trmdir _wrmdir |
|
85 # define NS_tstat _wstat |
|
86 # define NS_tlstat _wstat // No symlinks on Windows |
|
87 # define NS_tstrcat wcscat |
|
88 # define NS_tstrcmp wcscmp |
|
89 # define NS_tstricmp wcsicmp |
|
90 # define NS_tstrcpy wcscpy |
|
91 # define NS_tstrncpy wcsncpy |
|
92 # define NS_tstrlen wcslen |
|
93 # define NS_tstrchr wcschr |
|
94 # define NS_tstrrchr wcsrchr |
|
95 # define NS_tstrstr wcsstr |
|
96 # include "win_dirent.h" |
|
97 # define NS_tDIR DIR |
|
98 # define NS_tdirent dirent |
|
99 # define NS_topendir opendir |
|
100 # define NS_tclosedir closedir |
|
101 # define NS_treaddir readdir |
|
102 #else |
|
103 # include <sys/wait.h> |
|
104 # include <unistd.h> |
|
105 |
|
106 #ifdef SOLARIS |
|
107 # include <sys/stat.h> |
|
108 #else |
|
109 # include <fts.h> |
|
110 #endif |
|
111 # include <dirent.h> |
|
112 |
|
113 #ifdef XP_MACOSX |
|
114 # include <sys/time.h> |
|
115 #endif |
|
116 |
|
117 # define LOG_S "%s" |
|
118 # define NS_T(str) str |
|
119 # define NS_SLASH NS_T('/') |
|
120 # define NS_tsnprintf snprintf |
|
121 # define NS_taccess access |
|
122 # define NS_tchdir chdir |
|
123 # define NS_tchmod chmod |
|
124 # define NS_tfopen fopen |
|
125 # define NS_tmkdir mkdir |
|
126 # define NS_tremove remove |
|
127 # define NS_trename rename |
|
128 # define NS_trmdir rmdir |
|
129 # define NS_tstat stat |
|
130 # define NS_tlstat lstat |
|
131 # define NS_tstrcat strcat |
|
132 # define NS_tstrcmp strcmp |
|
133 # define NS_tstricmp strcasecmp |
|
134 # define NS_tstrcpy strcpy |
|
135 # define NS_tstrncpy strncpy |
|
136 # define NS_tstrlen strlen |
|
137 # define NS_tstrrchr strrchr |
|
138 # define NS_tstrstr strstr |
|
139 # define NS_tDIR DIR |
|
140 # define NS_tdirent dirent |
|
141 # define NS_topendir opendir |
|
142 # define NS_tclosedir closedir |
|
143 # define NS_treaddir readdir |
|
144 #endif |
|
145 |
|
146 #define BACKUP_EXT NS_T(".moz-backup") |
|
147 |
|
148 #endif |