Merge "Fix usleep(3) return type to be POSIX-compliant."

This commit is contained in:
Elliott Hughes 2010-01-07 15:54:35 -08:00 committed by Android (Google) Code Review
commit 0b5db51ea6
2 changed files with 8 additions and 5 deletions

View File

@ -145,7 +145,7 @@ extern int ftruncate(int, off_t);
extern int pause(void);
extern unsigned int alarm(unsigned int);
extern unsigned int sleep(unsigned int);
extern void usleep(unsigned long);
extern int usleep(unsigned long);
extern int gethostname(char *, size_t);
extern int sethostname(const char *, size_t);

View File

@ -28,7 +28,7 @@
#include <time.h>
#include <errno.h>
void usleep(unsigned long usec)
int usleep(unsigned long usec)
{
struct timespec ts;
@ -43,10 +43,13 @@ void usleep(unsigned long usec)
for (;;)
{
if ( nanosleep( &ts, &ts ) >= 0 )
break;
if ( nanosleep( &ts, &ts ) == 0 )
return 0;
// We try again if the nanosleep failure is EINTR.
// The other possible failures are EINVAL (which we should pass through),
// and ENOSYS, which doesn't happen.
if ( errno != EINTR )
break;
return -1;
}
}