-
-
Save nxghtmvrx/a2770038f16eaed1856706a71fd9f9b9 to your computer and use it in GitHub Desktop.
gnu compatible sleep tool.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #define _POSIX_C_SOURCE 200809L | |
| #include <sys/time.h> | |
| #include <time.h> | |
| #include <stdlib.h> | |
| int main(int argc, char** argv) { | |
| int i; | |
| char* end; | |
| int times; | |
| for(i = 1; i < argc; i++) { | |
| float s = strtof(argv[i], &end); | |
| switch(*end) { | |
| case 'm': | |
| times = 60; | |
| break; | |
| case 'h': | |
| times = 60 * 60; | |
| break; | |
| case 'd': | |
| times = 60 * 60 * 24; | |
| break; | |
| default: | |
| times = 1; | |
| } | |
| while(times--) { | |
| unsigned long long nsec = (s * 1000000000.f); | |
| nanosleep(&(struct timespec) {nsec / 1000000000, nsec % 1000000000}, NULL); | |
| } | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment