Bug 1531160 - Add the original NS_tsnprintf and use a new name for the new function. r=mhowell
authorRobert Strong <robert.bugzilla@gmail.com>
Thu, 28 Feb 2019 00:33:12 +0000
changeset 519451 2624b1bdee9b2bab41ca9a8c784cf0a7f14c2b7e
parent 519450 67213a91036c5830a6f830bc48ccb55c424d34ca
child 519452 6f00a2d89b5fa9785dac8ea8d4f47dfe17827702
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmhowell
bugs1531160
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1531160 - Add the original NS_tsnprintf and use a new name for the new function. r=mhowell Differential Revision: https://phabricator.services.mozilla.com/D21468
toolkit/mozapps/update/common/updatedefines.h
toolkit/mozapps/update/tests/TestAUSHelper.cpp
--- a/toolkit/mozapps/update/common/updatedefines.h
+++ b/toolkit/mozapps/update/common/updatedefines.h
@@ -36,17 +36,27 @@
 #  define DELETE_DIR L"tobedeleted"
 #  define CALLBACK_BACKUP_EXT L".moz-callback"
 
 #  define LOG_S "%S"
 #  define NS_CONCAT(x, y) x##y
 // The extra layer of indirection here allows this macro to be passed macros
 #  define NS_T(str) NS_CONCAT(L, str)
 #  define NS_SLASH NS_T('\\')
-#  define NS_tvsnprintf _vsnwprintf
+static inline int mywcsprintf(WCHAR* dest, size_t count, const WCHAR* fmt,
+                              ...) {
+  size_t _count = count - 1;
+  va_list varargs;
+  va_start(varargs, fmt);
+  int result = _vsnwprintf(dest, count - 1, fmt, varargs);
+  va_end(varargs);
+  dest[_count] = L'\0';
+  return result;
+}
+#  define NS_tsnprintf mywcsprintf
 #  define NS_taccess _waccess
 #  define NS_tatoi _wtoi64
 #  define NS_tchdir _wchdir
 #  define NS_tchmod _wchmod
 #  define NS_tfopen _wfopen
 #  define NS_tmkdir(path, perms) _wmkdir(path)
 #  define NS_tpid __int64
 #  define NS_tremove _wremove
@@ -84,17 +94,17 @@
 
 #  ifdef XP_MACOSX
 #    include <sys/time.h>
 #  endif
 
 #  define LOG_S "%s"
 #  define NS_T(str) str
 #  define NS_SLASH NS_T('/')
-#  define NS_tvsnprintf vsnprintf
+#  define NS_tsnprintf snprintf
 #  define NS_taccess access
 #  define NS_tatoi atoi
 #  define NS_tchdir chdir
 #  define NS_tchmod chmod
 #  define NS_tfopen fopen
 #  define NS_tmkdir mkdir
 #  define NS_tpid int
 #  define NS_tremove remove
@@ -129,21 +139,24 @@
 #    define MAXPATHLEN _MAX_PATH
 #  elif defined(CCHMAXPATH)
 #    define MAXPATHLEN CCHMAXPATH
 #  else
 #    define MAXPATHLEN 1024
 #  endif
 #endif
 
-static inline bool NS_tsnprintf(NS_tchar* dest, size_t count,
-                                const NS_tchar* fmt, ...) {
+static inline bool NS_tvsnprintf(NS_tchar* dest, size_t count,
+                                 const NS_tchar* fmt, ...) {
   va_list varargs;
   va_start(varargs, fmt);
-  int result = NS_tvsnprintf(dest, count - 1, fmt, varargs);
+#if defined(XP_WIN)
+  int result = _vsnwprintf(dest, count, fmt, varargs);
+#else
+  int result = vsnprintf(dest, count, fmt, varargs);
+#endif
   va_end(varargs);
-  dest[count - 1] = NS_T('\0');
   // The size_t cast of result is safe because result can only be positive after
   // the first check.
   return result >= 0 && (size_t)result < count;
 }
 
 #endif
--- a/toolkit/mozapps/update/tests/TestAUSHelper.cpp
+++ b/toolkit/mozapps/update/tests/TestAUSHelper.cpp
@@ -80,54 +80,54 @@ int NS_main(int argc, NS_tchar **argv) {
     if (!NS_tstrcmp(argv[1], NS_T("post-update-async")) ||
         !NS_tstrcmp(argv[1], NS_T("post-update-sync"))) {
       NS_tchar exePath[MAXPATHLEN];
 #ifdef XP_WIN
       if (!::GetModuleFileNameW(0, exePath, MAXPATHLEN)) {
         return 1;
       }
 #else
-      if (!NS_tsnprintf(exePath, sizeof(exePath) / sizeof(exePath[0]),
-                        NS_T("%s"), argv[0])) {
+      if (!NS_tvsnprintf(exePath, sizeof(exePath) / sizeof(exePath[0]),
+                         NS_T("%s"), argv[0])) {
         return 1;
       }
 #endif
       NS_tchar runFilePath[MAXPATHLEN];
-      if (!NS_tsnprintf(runFilePath,
-                        sizeof(runFilePath) / sizeof(runFilePath[0]),
-                        NS_T("%s.running"), exePath)) {
+      if (!NS_tvsnprintf(runFilePath,
+                         sizeof(runFilePath) / sizeof(runFilePath[0]),
+                         NS_T("%s.running"), exePath)) {
         return 1;
       }
 #ifdef XP_WIN
       if (!NS_taccess(runFilePath, F_OK)) {
         // This makes it possible to check if the post update process was
         // launched twice which happens when the service performs an update.
         NS_tchar runFilePathBak[MAXPATHLEN];
-        if (!NS_tsnprintf(runFilePathBak,
-                          sizeof(runFilePathBak) / sizeof(runFilePathBak[0]),
-                          NS_T("%s.bak"), runFilePath)) {
+        if (!NS_tvsnprintf(runFilePathBak,
+                           sizeof(runFilePathBak) / sizeof(runFilePathBak[0]),
+                           NS_T("%s.bak"), runFilePath)) {
           return 1;
         }
         MoveFileExW(runFilePath, runFilePathBak, MOVEFILE_REPLACE_EXISTING);
       }
 #endif
       WriteMsg(runFilePath, "running");
 
       if (!NS_tstrcmp(argv[1], NS_T("post-update-sync"))) {
 #ifdef XP_WIN
         Sleep(2000);
 #else
         sleep(2);
 #endif
       }
 
       NS_tchar logFilePath[MAXPATHLEN];
-      if (!NS_tsnprintf(logFilePath,
-                        sizeof(logFilePath) / sizeof(logFilePath[0]),
-                        NS_T("%s.log"), exePath)) {
+      if (!NS_tvsnprintf(logFilePath,
+                         sizeof(logFilePath) / sizeof(logFilePath[0]),
+                         NS_T("%s.log"), exePath)) {
         return 1;
       }
       WriteMsg(logFilePath, "post-update");
       return 0;
     }
   }
 
   if (argc < 3) {
@@ -182,44 +182,45 @@ int NS_main(int argc, NS_tchar **argv) {
     // Not implemented on non-Windows platforms
     return 1;
 #endif
   }
 
   if (!NS_tstrcmp(argv[1], NS_T("setup-symlink"))) {
 #ifdef XP_UNIX
     NS_tchar path[MAXPATHLEN];
-    if (!NS_tsnprintf(path, sizeof(path) / sizeof(path[0]), NS_T("%s/%s"),
-                      NS_T("/tmp"), argv[2])) {
+    if (!NS_tvsnprintf(path, sizeof(path) / sizeof(path[0]), NS_T("%s/%s"),
+                       NS_T("/tmp"), argv[2])) {
       return 1;
     }
     if (mkdir(path, 0755)) {
       return 1;
     }
-    if (!NS_tsnprintf(path, sizeof(path) / sizeof(path[0]), NS_T("%s/%s/%s"),
-                      NS_T("/tmp"), argv[2], argv[3])) {
+    if (!NS_tvsnprintf(path, sizeof(path) / sizeof(path[0]), NS_T("%s/%s/%s"),
+                       NS_T("/tmp"), argv[2], argv[3])) {
       return 1;
     }
     if (mkdir(path, 0755)) {
       return 1;
     }
-    if (!NS_tsnprintf(path, sizeof(path) / sizeof(path[0]), NS_T("%s/%s/%s/%s"),
-                      NS_T("/tmp"), argv[2], argv[3], argv[4])) {
+    if (!NS_tvsnprintf(path, sizeof(path) / sizeof(path[0]),
+                       NS_T("%s/%s/%s/%s"), NS_T("/tmp"), argv[2], argv[3],
+                       argv[4])) {
       return 1;
     }
     FILE *file = NS_tfopen(path, NS_T("w"));
     if (file) {
       fputs(NS_T("test"), file);
       fclose(file);
     }
     if (symlink(path, argv[5]) != 0) {
       return 1;
     }
-    if (!NS_tsnprintf(path, sizeof(path) / sizeof(path[0]), NS_T("%s/%s"),
-                      NS_T("/tmp"), argv[2])) {
+    if (!NS_tvsnprintf(path, sizeof(path) / sizeof(path[0]), NS_T("%s/%s"),
+                       NS_T("/tmp"), argv[2])) {
       return 1;
     }
     if (argc > 6 && !NS_tstrcmp(argv[6], NS_T("change-perm"))) {
       if (chmod(path, 0644)) {
         return 1;
       }
     }
     return 0;
@@ -231,39 +232,40 @@ int NS_main(int argc, NS_tchar **argv) {
 
   if (!NS_tstrcmp(argv[1], NS_T("remove-symlink"))) {
 #ifdef XP_UNIX
     // The following can be called at the start of a test in case these symlinks
     // need to be removed if they already exist and at the end of a test to
     // remove the symlinks created by the test so ignore file doesn't exist
     // errors.
     NS_tchar path[MAXPATHLEN];
-    if (!NS_tsnprintf(path, sizeof(path) / sizeof(path[0]), NS_T("%s/%s"),
-                      NS_T("/tmp"), argv[2])) {
+    if (!NS_tvsnprintf(path, sizeof(path) / sizeof(path[0]), NS_T("%s/%s"),
+                       NS_T("/tmp"), argv[2])) {
       return 1;
     }
     if (chmod(path, 0755) && errno != ENOENT) {
       return 1;
     }
-    if (!NS_tsnprintf(path, sizeof(path) / sizeof(path[0]), NS_T("%s/%s/%s/%s"),
-                      NS_T("/tmp"), argv[2], argv[3], argv[4])) {
+    if (!NS_tvsnprintf(path, sizeof(path) / sizeof(path[0]),
+                       NS_T("%s/%s/%s/%s"), NS_T("/tmp"), argv[2], argv[3],
+                       argv[4])) {
       return 1;
     }
     if (unlink(path) && errno != ENOENT) {
       return 1;
     }
-    if (!NS_tsnprintf(path, sizeof(path) / sizeof(path[0]), NS_T("%s/%s/%s"),
-                      NS_T("/tmp"), argv[2], argv[3])) {
+    if (!NS_tvsnprintf(path, sizeof(path) / sizeof(path[0]), NS_T("%s/%s/%s"),
+                       NS_T("/tmp"), argv[2], argv[3])) {
       return 1;
     }
     if (rmdir(path) && errno != ENOENT) {
       return 1;
     }
-    if (!NS_tsnprintf(path, sizeof(path) / sizeof(path[0]), NS_T("%s/%s"),
-                      NS_T("/tmp"), argv[2])) {
+    if (!NS_tvsnprintf(path, sizeof(path) / sizeof(path[0]), NS_T("%s/%s"),
+                       NS_T("/tmp"), argv[2])) {
       return 1;
     }
     if (rmdir(path) && errno != ENOENT) {
       return 1;
     }
     return 0;
 #else
     // Not implemented on non-Unix platforms
@@ -366,23 +368,24 @@ int NS_main(int argc, NS_tchar **argv) {
   }
 
   // File in use test helper section
   if (!NS_tstrcmp(argv[4], NS_T("-s"))) {
     // Note: glibc's getcwd() allocates the buffer dynamically using malloc(3)
     // if buf (the 1st param) is NULL so free cwd when it is no longer needed.
     NS_tchar *cwd = NS_tgetcwd(nullptr, 0);
     NS_tchar inFilePath[MAXPATHLEN];
-    if (!NS_tsnprintf(inFilePath, sizeof(inFilePath) / sizeof(inFilePath[0]),
-                      NS_T("%s/%s"), cwd, argv[2])) {
+    if (!NS_tvsnprintf(inFilePath, sizeof(inFilePath) / sizeof(inFilePath[0]),
+                       NS_T("%s/%s"), cwd, argv[2])) {
       return 1;
     }
     NS_tchar outFilePath[MAXPATHLEN];
-    if (!NS_tsnprintf(outFilePath, sizeof(outFilePath) / sizeof(outFilePath[0]),
-                      NS_T("%s/%s"), cwd, argv[3])) {
+    if (!NS_tvsnprintf(outFilePath,
+                       sizeof(outFilePath) / sizeof(outFilePath[0]),
+                       NS_T("%s/%s"), cwd, argv[3])) {
       return 1;
     }
     free(cwd);
 
     int seconds = NS_ttoi(argv[5]);
 #ifdef XP_WIN
     HANDLE hFile = INVALID_HANDLE_VALUE;
     if (argc == 7) {
@@ -412,18 +415,19 @@ int NS_main(int argc, NS_tchar **argv) {
 #endif
     WriteMsg(outFilePath, "finished");
     return 0;
   }
 
   {
     // Command line argument test helper section
     NS_tchar logFilePath[MAXPATHLEN];
-    if (!NS_tsnprintf(logFilePath, sizeof(logFilePath) / sizeof(logFilePath[0]),
-                      NS_T("%s"), argv[2])) {
+    if (!NS_tvsnprintf(logFilePath,
+                       sizeof(logFilePath) / sizeof(logFilePath[0]), NS_T("%s"),
+                       argv[2])) {
       return 1;
     }
 
     FILE *logFP = NS_tfopen(logFilePath, NS_T("wb"));
     if (!logFP) {
       return 1;
     }
     for (int i = 1; i < argc; ++i) {