Skip to content

Instantly share code, notes, and snippets.

@wjx wjx/stdio.c
Last active Aug 29, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.