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/. */
5 #ifndef UPDATEDEFINES_H
6 #define UPDATEDEFINES_H
8 #include "readstrings.h"
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
20 # define MAXPATHLEN 1024
35 # define S_ISDIR(s) (((s) & _S_IFMT) == _S_IFDIR)
36 # define S_ISREG(s) (((s) & _S_IFMT) == _S_IFREG)
38 # define access _access
40 # define putenv _putenv
44 # define DELETE_DIR L"tobedeleted"
45 # define CALLBACK_BACKUP_EXT L".moz-callback"
48 # define NS_T(str) L ## str
49 # define NS_SLASH NS_T('\\')
51 #if defined(_MSC_VER) && _MSC_VER < 1900
52 // On Windows, _snprintf and _snwprintf don't guarantee null termination. These
53 // macros always leave room in the buffer for null termination and set the end
54 // of the buffer to null in case the string is larger than the buffer. Having
55 // multiple nulls in a string is fine and this approach is simpler (possibly
56 // faster) than calculating the string length to place the null terminator and
57 // truncates the string as _snprintf and _snwprintf do on other platforms.
58 static inline int mysnprintf(char* dest
, size_t count
, const char* fmt
, ...)
60 size_t _count
= count
- 1;
62 va_start(varargs
, fmt
);
63 int result
= _vsnprintf(dest
, count
- 1, fmt
, varargs
);
68 #define snprintf mysnprintf
70 static inline int mywcsprintf(WCHAR
* dest
, size_t count
, const WCHAR
* fmt
, ...)
72 size_t _count
= count
- 1;
74 va_start(varargs
, fmt
);
75 int result
= _vsnwprintf(dest
, count
- 1, fmt
, varargs
);
80 #define NS_tsnprintf mywcsprintf
81 # define NS_taccess _waccess
82 # define NS_tchdir _wchdir
83 # define NS_tchmod _wchmod
84 # define NS_tfopen _wfopen
85 # define NS_tmkdir(path, perms) _wmkdir(path)
86 # define NS_tremove _wremove
87 // _wrename is used to avoid the link tracking service.
88 # define NS_trename _wrename
89 # define NS_trmdir _wrmdir
90 # define NS_tstat _wstat
91 # define NS_tlstat _wstat // No symlinks on Windows
92 # define NS_tstat_t _stat
93 # define NS_tstrcat wcscat
94 # define NS_tstrcmp wcscmp
95 # define NS_tstricmp wcsicmp
96 # define NS_tstrcpy wcscpy
97 # define NS_tstrncpy wcsncpy
98 # define NS_tstrlen wcslen
99 # define NS_tstrchr wcschr
100 # define NS_tstrrchr wcsrchr
101 # define NS_tstrstr wcsstr
102 # include "win_dirent.h"
104 # define NS_tdirent dirent
105 # define NS_topendir opendir
106 # define NS_tclosedir closedir
107 # define NS_treaddir readdir
109 # include <sys/wait.h>
113 # include <sys/stat.h>
120 # include <sys/time.h>
124 # define NS_T(str) str
125 # define NS_SLASH NS_T('/')
126 # define NS_tsnprintf snprintf
127 # define NS_taccess access
128 # define NS_tchdir chdir
129 # define NS_tchmod chmod
130 # define NS_tfopen fopen
131 # define NS_tmkdir mkdir
132 # define NS_tremove remove
133 # define NS_trename rename
134 # define NS_trmdir rmdir
135 # define NS_tstat stat
136 # define NS_tstat_t stat
137 # define NS_tlstat lstat
138 # define NS_tstrcat strcat
139 # define NS_tstrcmp strcmp
140 # define NS_tstricmp strcasecmp
141 # define NS_tstrcpy strcpy
142 # define NS_tstrncpy strncpy
143 # define NS_tstrlen strlen
144 # define NS_tstrrchr strrchr
145 # define NS_tstrstr strstr
147 # define NS_tdirent dirent
148 # define NS_topendir opendir
149 # define NS_tclosedir closedir
150 # define NS_treaddir readdir
153 #define BACKUP_EXT NS_T(".moz-backup")