Bug 860827 - Move TEMP_FAILURE_RETRY to FileUtils.h and rename it. r=tbsaunde
authorVasil Dimov <vd@FreeBSD.org>
Thu, 09 May 2013 13:42:12 -0400
changeset 142361 fb3cb79e27d9ed538b1ee53218f4f836de30645a
parent 142360 b4c12bd0ca4e3e61eebef3aeb49ee01b311fefd6
child 142362 831491563b7d6bdec06d02bd4c2ed0858a46fcc8
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstbsaunde
bugs860827
milestone23.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 860827 - Move TEMP_FAILURE_RETRY to FileUtils.h and rename it. r=tbsaunde
xpcom/glue/FileUtils.cpp
xpcom/glue/FileUtils.h
xpcom/glue/tests/gtest/TestFileUtils.cpp
--- a/xpcom/glue/FileUtils.cpp
+++ b/xpcom/glue/FileUtils.cpp
@@ -114,43 +114,35 @@ mozilla::fallocate(PRFileDesc *aFD, int6
   PR_Seek64(aFD, oldpos, PR_SEEK_SET);
   return nWrite == 1;
 #endif
   return false;
 }
 
 #ifdef ReadSysFile_PRESENT
 
-#undef TEMP_FAILURE_RETRY
-#define TEMP_FAILURE_RETRY(exp) (__extension__({ \
-  typeof (exp) _rc; \
-  do { \
-    _rc = (exp); \
-  } while (_rc == -1 && errno == EINTR); \
-  _rc; \
-}))
-
 bool
 mozilla::ReadSysFile(
   const char* aFilename,
   char* aBuf,
   size_t aBufSize)
 {
-  int fd = TEMP_FAILURE_RETRY(open(aFilename, O_RDONLY));
+  int fd = MOZ_TEMP_FAILURE_RETRY(open(aFilename, O_RDONLY));
   if (fd < 0) {
     return false;
   }
   ScopedClose autoClose(fd);
   if (aBufSize == 0) {
     return true;
   }
   ssize_t bytesRead;
   size_t offset = 0;
   do {
-    bytesRead = TEMP_FAILURE_RETRY(read(fd, aBuf + offset, aBufSize - offset));
+    bytesRead = MOZ_TEMP_FAILURE_RETRY(
+      read(fd, aBuf + offset, aBufSize - offset));
     if (bytesRead == -1) {
       return false;
     }
     offset += bytesRead;
   } while (bytesRead > 0 && offset < aBufSize);
   MOZ_ASSERT(offset <= aBufSize);
   if (offset > 0 && aBuf[offset - 1] == '\n') {
     offset--;
--- a/xpcom/glue/FileUtils.h
+++ b/xpcom/glue/FileUtils.h
@@ -149,16 +149,24 @@ NS_COM_GLUE void ReadAhead(filedesc_t aF
 Also define it in debug builds, so that unit tests for it can be written
 and run in non-GONK builds. */
 #if (defined(MOZ_WIDGET_GONK) || defined(DEBUG)) && defined(XP_UNIX)
 
 #ifndef ReadSysFile_PRESENT
 #define ReadSysFile_PRESENT
 #endif /* ReadSysFile_PRESENT */
 
+#define MOZ_TEMP_FAILURE_RETRY(exp) (__extension__({ \
+  typeof (exp) _rc; \
+  do { \
+    _rc = (exp); \
+  } while (_rc == -1 && errno == EINTR); \
+  _rc; \
+}))
+
 /**
  * Read the contents of a file.
  * This function is intended for reading a single-lined text files from
  * /sys/. If the file ends with a newline ('\n') then it will be discarded.
  * The output buffer will always be '\0'-terminated on successful completion.
  * If aBufSize == 0, then this function will return true if the file exists
  * and is readable (it will not attempt to read anything from it).
  * On failure the contents of aBuf after this call will be undefined and the
--- a/xpcom/glue/tests/gtest/TestFileUtils.cpp
+++ b/xpcom/glue/tests/gtest/TestFileUtils.cpp
@@ -30,35 +30,36 @@ WriteFile(
   const char* aFilename,
   const void* aContents,
   size_t aContentsLen)
 {
   int fd;
   ssize_t ret;
   size_t offt;
 
-  fd = TEMP_FAILURE_RETRY(
+  fd = MOZ_TEMP_FAILURE_RETRY(
     open(aFilename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR));
   if (fd == -1) {
     fprintf(stderr, "open(): %s: %s\n", aFilename, strerror(errno));
     return false;
   }
 
   offt = 0;
   do {
-    ret = TEMP_FAILURE_RETRY(write(fd, (char*)aContents + offt, aContentsLen - offt));
+    ret = MOZ_TEMP_FAILURE_RETRY(
+      write(fd, (char*)aContents + offt, aContentsLen - offt));
     if (ret == -1) {
       fprintf(stderr, "write(): %s: %s\n", aFilename, strerror(errno));
       close(fd);
       return false;
     }
     offt += ret;
   } while (offt < aContentsLen);
 
-  ret = TEMP_FAILURE_RETRY(close(fd));
+  ret = MOZ_TEMP_FAILURE_RETRY(close(fd));
   if (ret == -1) {
     fprintf(stderr, "close(): %s: %s\n", aFilename, strerror(errno));
     return false;
   }
   return true;
 }
 
 TEST(ReadSysFile, Nonexistent) {