Created
June 13, 2017 14:58
-
-
Save dwest/04648b26954713565e74c7c86c87ac5f to your computer and use it in GitHub Desktop.
yes.c mucking about
This file contains 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
/* See https://www.reddit.com/r/unix/comments/6gxduc/how_is_gnu_yes_so_fast/ for what this is all about, all credit to the original authors. */ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <unistd.h> | |
int main() { | |
char yes[2] = "y\n"; | |
int pagesize = getpagesize() * 8; | |
char *buff = malloc(pagesize); | |
int buffused = 0; | |
while(buffused < pagesize) { | |
memcpy(buff+buffused, yes, 2); | |
buffused += 2; | |
} | |
/* Very minor improvement by setting buffering off */ | |
setvbuf(stdout, NULL, _IONBF, 0); | |
while(fwrite(buff, pagesize, 1, stdout)); | |
return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment