commit | 99d7907611725e23b6fad3ae7acff4926504e687 | [log] [tgz] |
---|---|---|
author | Elliott Hughes <enh@google.com> | Mon Dec 14 17:07:19 2009 -0800 |
committer | Elliott Hughes <enh@google.com> | Mon Dec 14 17:07:19 2009 -0800 |
tree | 74eb2d8ded9708c4768aab30022cc6307bc39c1e | |
parent | 278d960aae1b2f0b8a3fa0c8056ba4aded96b133 [diff] [blame] |
Fix usleep(3) return type to be POSIX-compliant. POSIX usleep(3) returns 0 on successful completion, -1 otherwise: http://www.opengroup.org/onlinepubs/007908799/xsh/usleep.html This was found by an external user porting native code: http://groups.google.com/group/android-porting/browse_thread/thread/674848f001db0292
diff --git a/libc/unistd/usleep.c b/libc/unistd/usleep.c index 75458b1..19e8ee8 100644 --- a/libc/unistd/usleep.c +++ b/libc/unistd/usleep.c
@@ -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 @@ 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; } }