michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef UPDATEDEFINES_H michael@0: #define UPDATEDEFINES_H michael@0: michael@0: #include "readstrings.h" michael@0: michael@0: #ifndef MAXPATHLEN michael@0: # ifdef PATH_MAX michael@0: # define MAXPATHLEN PATH_MAX michael@0: # elif defined(MAX_PATH) michael@0: # define MAXPATHLEN MAX_PATH michael@0: # elif defined(_MAX_PATH) michael@0: # define MAXPATHLEN _MAX_PATH michael@0: # elif defined(CCHMAXPATH) michael@0: # define MAXPATHLEN CCHMAXPATH michael@0: # else michael@0: # define MAXPATHLEN 1024 michael@0: # endif michael@0: #endif michael@0: michael@0: #if defined(XP_WIN) michael@0: # include michael@0: # include michael@0: # include michael@0: # include michael@0: # include michael@0: # include michael@0: michael@0: # define F_OK 00 michael@0: # define W_OK 02 michael@0: # define R_OK 04 michael@0: # define S_ISDIR(s) (((s) & _S_IFMT) == _S_IFDIR) michael@0: # define S_ISREG(s) (((s) & _S_IFMT) == _S_IFREG) michael@0: michael@0: # define access _access michael@0: michael@0: # define putenv _putenv michael@0: # define stat _stat michael@0: # define DELETE_DIR L"tobedeleted" michael@0: # define CALLBACK_BACKUP_EXT L".moz-callback" michael@0: michael@0: # define LOG_S "%S" michael@0: # define NS_T(str) L ## str michael@0: # define NS_SLASH NS_T('\\') michael@0: // On Windows, _snprintf and _snwprintf don't guarantee null termination. These michael@0: // macros always leave room in the buffer for null termination and set the end michael@0: // of the buffer to null in case the string is larger than the buffer. Having michael@0: // multiple nulls in a string is fine and this approach is simpler (possibly michael@0: // faster) than calculating the string length to place the null terminator and michael@0: // truncates the string as _snprintf and _snwprintf do on other platforms. michael@0: static int mysnprintf(char* dest, size_t count, const char* fmt, ...) michael@0: { michael@0: size_t _count = count - 1; michael@0: va_list varargs; michael@0: va_start(varargs, fmt); michael@0: int result = _vsnprintf(dest, count - 1, fmt, varargs); michael@0: va_end(varargs); michael@0: dest[_count] = '\0'; michael@0: return result; michael@0: } michael@0: #define snprintf mysnprintf michael@0: static int mywcsprintf(WCHAR* dest, size_t count, const WCHAR* fmt, ...) michael@0: { michael@0: size_t _count = count - 1; michael@0: va_list varargs; michael@0: va_start(varargs, fmt); michael@0: int result = _vsnwprintf(dest, count - 1, fmt, varargs); michael@0: va_end(varargs); michael@0: dest[_count] = L'\0'; michael@0: return result; michael@0: } michael@0: #define NS_tsnprintf mywcsprintf michael@0: # define NS_taccess _waccess michael@0: # define NS_tchdir _wchdir michael@0: # define NS_tchmod _wchmod michael@0: # define NS_tfopen _wfopen michael@0: # define NS_tmkdir(path, perms) _wmkdir(path) michael@0: # define NS_tremove _wremove michael@0: // _wrename is used to avoid the link tracking service. michael@0: # define NS_trename _wrename michael@0: # define NS_trmdir _wrmdir michael@0: # define NS_tstat _wstat michael@0: # define NS_tlstat _wstat // No symlinks on Windows michael@0: # define NS_tstrcat wcscat michael@0: # define NS_tstrcmp wcscmp michael@0: # define NS_tstricmp wcsicmp michael@0: # define NS_tstrcpy wcscpy michael@0: # define NS_tstrncpy wcsncpy michael@0: # define NS_tstrlen wcslen michael@0: # define NS_tstrchr wcschr michael@0: # define NS_tstrrchr wcsrchr michael@0: # define NS_tstrstr wcsstr michael@0: # include "win_dirent.h" michael@0: # define NS_tDIR DIR michael@0: # define NS_tdirent dirent michael@0: # define NS_topendir opendir michael@0: # define NS_tclosedir closedir michael@0: # define NS_treaddir readdir michael@0: #else michael@0: # include michael@0: # include michael@0: michael@0: #ifdef SOLARIS michael@0: # include michael@0: #else michael@0: # include michael@0: #endif michael@0: # include michael@0: michael@0: #ifdef XP_MACOSX michael@0: # include michael@0: #endif michael@0: michael@0: # define LOG_S "%s" michael@0: # define NS_T(str) str michael@0: # define NS_SLASH NS_T('/') michael@0: # define NS_tsnprintf snprintf michael@0: # define NS_taccess access michael@0: # define NS_tchdir chdir michael@0: # define NS_tchmod chmod michael@0: # define NS_tfopen fopen michael@0: # define NS_tmkdir mkdir michael@0: # define NS_tremove remove michael@0: # define NS_trename rename michael@0: # define NS_trmdir rmdir michael@0: # define NS_tstat stat michael@0: # define NS_tlstat lstat michael@0: # define NS_tstrcat strcat michael@0: # define NS_tstrcmp strcmp michael@0: # define NS_tstricmp strcasecmp michael@0: # define NS_tstrcpy strcpy michael@0: # define NS_tstrncpy strncpy michael@0: # define NS_tstrlen strlen michael@0: # define NS_tstrrchr strrchr michael@0: # define NS_tstrstr strstr michael@0: # define NS_tDIR DIR michael@0: # define NS_tdirent dirent michael@0: # define NS_topendir opendir michael@0: # define NS_tclosedir closedir michael@0: # define NS_treaddir readdir michael@0: #endif michael@0: michael@0: #define BACKUP_EXT NS_T(".moz-backup") michael@0: michael@0: #endif