Last active
August 29, 2015 14:20
-
-
Save wjx/f95e08e84679d724dc41 to your computer and use it in GitHub Desktop.
Android adb TEMP_FAILURE_RETRY
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//bionic/libc/stdio/stdio.c | |
int | |
__sread(void *cookie, char *buf, int n) | |
{ | |
FILE *fp = cookie; | |
int ret; | |
ret = TEMP_FAILURE_RETRY(read(fp->_file, buf, n)); | |
/* if the read succeeded, update the current offset */ | |
if (ret >= 0) | |
fp->_offset += ret; | |
else | |
fp->_flags &= ~__SOFF; /* paranoia */ | |
return (ret); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//system/core/adb/sysdeps.h | |
//Also see https://stackoverflow.com/questions/12081502/typeof-operator-in-c | |
//https://gustedt.wordpress.com/2011/01/09/dont-be-afraid-of-variably-modified-types/ | |
/* | |
* TEMP_FAILURE_RETRY is defined by some, but not all, versions of | |
* <unistd.h>. (Alas, it is not as standard as we'd hoped!) So, if it's | |
* not already defined, then define it here. | |
*/ | |
#ifndef TEMP_FAILURE_RETRY | |
/* Used to retry syscalls that can return EINTR. */ | |
#define TEMP_FAILURE_RETRY(exp) ({ \ | |
typeof (exp) _rc; \ | |
do { \ | |
_rc = (exp); \ | |
} while (_rc == -1 && errno == EINTR); \ | |
_rc; }) | |
#endif | |
static __inline__ int adb_read(int fd, void* buf, size_t len) | |
{ | |
return TEMP_FAILURE_RETRY( read( fd, buf, len ) ); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment