Bug 860827 - Move TEMP_FAILURE_RETRY to FileUtils.h and rename it. r=tbsaunde

This commit is contained in:
Vasil Dimov 2013-05-09 13:42:12 -04:00
parent 5f4f41fbe6
commit 1d18b77cc6
3 changed files with 15 additions and 14 deletions

View File

@ -119,22 +119,13 @@ mozilla::fallocate(PRFileDesc *aFD, int64_t aLength)
#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;
}
@ -145,7 +136,8 @@ mozilla::ReadSysFile(
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;
}

View File

@ -154,6 +154,14 @@ and run in non-GONK builds. */
#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

View File

@ -35,7 +35,7 @@ WriteFile(
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));
@ -44,7 +44,8 @@ WriteFile(
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);
@ -53,7 +54,7 @@ WriteFile(
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;