Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / onlineupdate / source / update / common / updatedefines.h
blob52a8b8437cc2420f8680daf62a0799aaeb76defa
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"
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
24 #if defined(_WIN32)
25 # include <windows.h>
26 # include <shlwapi.h>
27 # include <direct.h>
28 # include <io.h>
29 # include <stdio.h>
30 # include <stdarg.h>
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)
38 # define access _access
40 # define putenv _putenv
41 # if _MSC_VER < 1900
42 # define stat _stat
43 # endif
44 # define DELETE_DIR L"tobedeleted"
45 # define CALLBACK_BACKUP_EXT L".moz-callback"
47 # define LOG_S "%S"
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;
61 va_list varargs;
62 va_start(varargs, fmt);
63 int result = _vsnprintf(dest, count - 1, fmt, varargs);
64 va_end(varargs);
65 dest[_count] = '\0';
66 return result;
68 #define snprintf mysnprintf
69 #endif
70 static inline int mywcsprintf(WCHAR* dest, size_t count, const WCHAR* fmt, ...)
72 size_t _count = count - 1;
73 va_list varargs;
74 va_start(varargs, fmt);
75 int result = _vsnwprintf(dest, count - 1, fmt, varargs);
76 va_end(varargs);
77 dest[_count] = L'\0';
78 return result;
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"
103 # define NS_tDIR DIR
104 # define NS_tdirent dirent
105 # define NS_topendir opendir
106 # define NS_tclosedir closedir
107 # define NS_treaddir readdir
108 #else
109 # include <sys/wait.h>
110 # include <unistd.h>
112 #ifdef SOLARIS
113 # include <sys/stat.h>
114 #else
115 # include <fts.h>
116 #endif
117 # include <dirent.h>
119 #ifdef MACOSX
120 # include <sys/time.h>
121 #endif
123 # define LOG_S "%s"
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
146 # define NS_tDIR DIR
147 # define NS_tdirent dirent
148 # define NS_topendir opendir
149 # define NS_tclosedir closedir
150 # define NS_treaddir readdir
151 #endif
153 #define BACKUP_EXT NS_T(".moz-backup")
155 #endif