3 ms·
I wrote a UNIX utility called "epoch" that I use for tiny systems where I need to print the epoch but do not want to put a full-blown "date" command in the user
by 1vuio0pswjnm7 4y ago
I wrote a UNIX utility called "epoch" that I use for tiny systems where I need to print the epoch but do not want to put a full-blown "date" command in the userland. Here is the code
int printf(const char *__restrict, ...);
unsigned int time(unsigned int *tloc);
int main(){printf("%u\n",time((unsigned int *)0));}
- 1vuio0pswjnm7 4y agoOne can reduce the size of the static binary by about 50% by using return instead of printf (tested with musl) int printf(const char *__restrict, ...); unsigned int time(unsigned int *tloc); int main(){return time((unsigned int *)0);}
- d33 4y agoIf you're OK with compiler warnings, this can be golfed down to: echo 'main(){printf("%u\\n",time(0));}'>epoch.c&&make epoch
- d33 4y ago...on a separate note, wouldn't `date +%s` from coreutils do?