Comment

Comment by signa11

umm this is kinda tongue-in-cheek

```

#include <time.h>

#include <stdio.h>

int main(int argc, char argv[]) { int i = 0; time_t timep;

        /*
         * ok so now we are printing something
        **/
        printf("Greetings!\n");

        /*
         * this is a for loop from 0..9
        **/
        for(i=0; i<10; i++) {
                time(&timep);
                localtime(&timep);
        }

        printf("Godspeed, dear friend!\n");
        return 0;
}

```

now, the canonical

```

$> gcc tz-test.c -o obj/tz-test

```

now do this

```

$> unset TZ

$> strace -ff ./obj/tz-test 2>&1 | grep 'local' | wc

     10      77     851
$> export TZ=:/etc/localtime

$> strace -ff ./obj/tz-test 2>&1 | grep 'local' | wc

      1       5      59

```

moral, always set TZ to avoid localtime(3) from stat'ing /etc/localtime :o)

parent signa11 2 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton