Skip to content

Instantly share code, notes, and snippets.

@AlexAtkinson
Created July 14, 2022 01:05
Show Gist options
  • Save AlexAtkinson/631ecd558402a3b579a0334148d4f366 to your computer and use it in GitHub Desktop.
Save AlexAtkinson/631ecd558402a3b579a0334148d4f366 to your computer and use it in GitHub Desktop.
C: Get date +'%s%N' out of macos...
#!/usr/bin/env sh
cat << EOF > epochInµsec.c
#include <stdio.h>
#include <sys/time.h>
__asm__(".symver realpath,realpath@GLIBC_2.0");
int main(void)
{
struct timeval time_now;
gettimeofday(&time_now,NULL);
int s = time_now.tv_sec;
int us = time_now.tv_usec;
//printf("%ld%ld\n",time_now.tv_sec,time_now.tv_usec);
printf("%10d%06d\n",s,us);
return 0;
}
EOF
cc -o ts epochInµsec.c
./ts
rm -f ts epochInµsec.c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment