Skip to content

Instantly share code, notes, and snippets.

@wjx
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wjx/f95e08e84679d724dc41 to your computer and use it in GitHub Desktop.
Save wjx/f95e08e84679d724dc41 to your computer and use it in GitHub Desktop.
Android adb TEMP_FAILURE_RETRY
//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);
}
//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