toolkit/mozapps/update/common/updatedefines.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/mozapps/update/common/updatedefines.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,148 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +#ifndef UPDATEDEFINES_H
     1.9 +#define UPDATEDEFINES_H
    1.10 +
    1.11 +#include "readstrings.h"
    1.12 +
    1.13 +#ifndef MAXPATHLEN
    1.14 +# ifdef PATH_MAX
    1.15 +#  define MAXPATHLEN PATH_MAX
    1.16 +# elif defined(MAX_PATH)
    1.17 +#  define MAXPATHLEN MAX_PATH
    1.18 +# elif defined(_MAX_PATH)
    1.19 +#  define MAXPATHLEN _MAX_PATH
    1.20 +# elif defined(CCHMAXPATH)
    1.21 +#  define MAXPATHLEN CCHMAXPATH
    1.22 +# else
    1.23 +#  define MAXPATHLEN 1024
    1.24 +# endif
    1.25 +#endif
    1.26 +
    1.27 +#if defined(XP_WIN)
    1.28 +# include <windows.h>
    1.29 +# include <shlwapi.h>
    1.30 +# include <direct.h>
    1.31 +# include <io.h>
    1.32 +# include <stdio.h>
    1.33 +# include <stdarg.h>
    1.34 +
    1.35 +# define F_OK 00
    1.36 +# define W_OK 02
    1.37 +# define R_OK 04
    1.38 +# define S_ISDIR(s) (((s) & _S_IFMT) == _S_IFDIR)
    1.39 +# define S_ISREG(s) (((s) & _S_IFMT) == _S_IFREG)
    1.40 +
    1.41 +# define access _access
    1.42 +
    1.43 +# define putenv _putenv
    1.44 +# define stat _stat
    1.45 +# define DELETE_DIR L"tobedeleted"
    1.46 +# define CALLBACK_BACKUP_EXT L".moz-callback"
    1.47 +
    1.48 +# define LOG_S "%S"
    1.49 +# define NS_T(str) L ## str
    1.50 +# define NS_SLASH NS_T('\\')
    1.51 +// On Windows, _snprintf and _snwprintf don't guarantee null termination. These
    1.52 +// macros always leave room in the buffer for null termination and set the end
    1.53 +// of the buffer to null in case the string is larger than the buffer. Having
    1.54 +// multiple nulls in a string is fine and this approach is simpler (possibly
    1.55 +// faster) than calculating the string length to place the null terminator and
    1.56 +// truncates the string as _snprintf and _snwprintf do on other platforms.
    1.57 +static int mysnprintf(char* dest, size_t count, const char* fmt, ...)
    1.58 +{
    1.59 +  size_t _count = count - 1;
    1.60 +  va_list varargs;
    1.61 +  va_start(varargs, fmt);
    1.62 +  int result = _vsnprintf(dest, count - 1, fmt, varargs);
    1.63 +  va_end(varargs);
    1.64 +  dest[_count] = '\0';
    1.65 +  return result;
    1.66 +}
    1.67 +#define snprintf mysnprintf
    1.68 +static int mywcsprintf(WCHAR* dest, size_t count, const WCHAR* fmt, ...)
    1.69 +{
    1.70 +  size_t _count = count - 1;
    1.71 +  va_list varargs;
    1.72 +  va_start(varargs, fmt);
    1.73 +  int result = _vsnwprintf(dest, count - 1, fmt, varargs);
    1.74 +  va_end(varargs);
    1.75 +  dest[_count] = L'\0';
    1.76 +  return result;
    1.77 +}
    1.78 +#define NS_tsnprintf mywcsprintf
    1.79 +# define NS_taccess _waccess
    1.80 +# define NS_tchdir _wchdir
    1.81 +# define NS_tchmod _wchmod
    1.82 +# define NS_tfopen _wfopen
    1.83 +# define NS_tmkdir(path, perms) _wmkdir(path)
    1.84 +# define NS_tremove _wremove
    1.85 +// _wrename is used to avoid the link tracking service.
    1.86 +# define NS_trename _wrename
    1.87 +# define NS_trmdir _wrmdir
    1.88 +# define NS_tstat _wstat
    1.89 +# define NS_tlstat _wstat // No symlinks on Windows
    1.90 +# define NS_tstrcat wcscat
    1.91 +# define NS_tstrcmp wcscmp
    1.92 +# define NS_tstricmp wcsicmp
    1.93 +# define NS_tstrcpy wcscpy
    1.94 +# define NS_tstrncpy wcsncpy
    1.95 +# define NS_tstrlen wcslen
    1.96 +# define NS_tstrchr wcschr
    1.97 +# define NS_tstrrchr wcsrchr
    1.98 +# define NS_tstrstr wcsstr
    1.99 +# include "win_dirent.h"
   1.100 +# define NS_tDIR DIR
   1.101 +# define NS_tdirent dirent
   1.102 +# define NS_topendir opendir
   1.103 +# define NS_tclosedir closedir
   1.104 +# define NS_treaddir readdir
   1.105 +#else
   1.106 +# include <sys/wait.h>
   1.107 +# include <unistd.h>
   1.108 +
   1.109 +#ifdef SOLARIS
   1.110 +# include <sys/stat.h>
   1.111 +#else
   1.112 +# include <fts.h>
   1.113 +#endif
   1.114 +# include <dirent.h>
   1.115 +
   1.116 +#ifdef XP_MACOSX
   1.117 +# include <sys/time.h>
   1.118 +#endif
   1.119 +
   1.120 +# define LOG_S "%s"
   1.121 +# define NS_T(str) str
   1.122 +# define NS_SLASH NS_T('/')
   1.123 +# define NS_tsnprintf snprintf
   1.124 +# define NS_taccess access
   1.125 +# define NS_tchdir chdir
   1.126 +# define NS_tchmod chmod
   1.127 +# define NS_tfopen fopen
   1.128 +# define NS_tmkdir mkdir
   1.129 +# define NS_tremove remove
   1.130 +# define NS_trename rename
   1.131 +# define NS_trmdir rmdir
   1.132 +# define NS_tstat stat
   1.133 +# define NS_tlstat lstat
   1.134 +# define NS_tstrcat strcat
   1.135 +# define NS_tstrcmp strcmp
   1.136 +# define NS_tstricmp strcasecmp
   1.137 +# define NS_tstrcpy strcpy
   1.138 +# define NS_tstrncpy strncpy
   1.139 +# define NS_tstrlen strlen
   1.140 +# define NS_tstrrchr strrchr
   1.141 +# define NS_tstrstr strstr
   1.142 +# define NS_tDIR DIR
   1.143 +# define NS_tdirent dirent
   1.144 +# define NS_topendir opendir
   1.145 +# define NS_tclosedir closedir
   1.146 +# define NS_treaddir readdir
   1.147 +#endif
   1.148 +
   1.149 +#define BACKUP_EXT NS_T(".moz-backup")
   1.150 +
   1.151 +#endif

mercurial