Skip to content

Instantly share code, notes, and snippets.

@mu578
Created October 27, 2023 19:27
Show Gist options
  • Save mu578/13e446c3665f020ad1f4ec8083fca007 to your computer and use it in GitHub Desktop.
Save mu578/13e446c3665f020ad1f4ec8083fca007 to your computer and use it in GitHub Desktop.
Useless C
// cc u1.c -pedantic -Wno-newline-eof -o u1.executable
#include <stdio.h>
# if defined(_MSC_VER)
# include <windows.h>
static int usleep(__int64 usec)
{
HANDLE timer;
LARGE_INTEGER fire;
fire.QuadPart = -(10 * usec);
timer = CreateWaitableTimer(NULL, TRUE, NULL);
SetWaitableTimer(timer, &fire, 0, NULL, NULL, FALSE);
WaitForSingleObject(timer, INFINITE);
CloseHandle(timer);
return 0;
}
# else
# include <unistd.h>
# endif
int main(int argc, const char * argv[])
{
int i = 1;
(void)argc;
(void)argv;
for (; i < 10; ++i) {
fprintf(stderr, "\033c\033[0;31m%d\033[0m", i);
usleep(1000 * 1000);
}
fprintf(stderr, "\033c");
return 0;
}
/* EOF */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment