Sunday, June 23, 2019

MacOS/Darwin/Mach sleep weirdness

A system call to sleep returns 0 as it should, but set errno to 60 "ETIMEDOUT Operation timed out." which it really shouldn't, especially on a return of 0. https://pubs.opengroup.org/onlinepubs/009695399/functions/sleep.html states "No errors are defined." Here's some C proof.
#include <stdio.h>
#include <unistd.h>
#include <sys/errno.h>

int main(int argc, char **argv) {
    printf("this looks good: %d\n", sleep(1));
    printf("this does not: %d\n", errno);
}
And the output.
this looks good: 0
this does not: 60