From 11380315ae88cf739524e2f55aca35caef1245ba Mon Sep 17 00:00:00 2001 From: silverwizard Date: Sun, 27 Oct 2019 14:57:49 -0400 Subject: [PATCH] Made DPU accept -c in order to output to stdout --- dpu.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/dpu.c b/dpu.c index 2b4c318..0c85819 100644 --- a/dpu.c +++ b/dpu.c @@ -7,11 +7,15 @@ int main (int argc, char **argv){ char name[FILENAME_MAX]; FILE *bob,*joe,*moe; - int thing, factor, arg; - int modifier; + int out, thing, factor, arg, modifier; + out = 0; factor=0; - while((modifier=getopt(argc,argv,"0123456789"))+1){ + while((modifier=getopt(argc,argv,"0123456789c"))+1){ switch(modifier){ + case 'c': + joe = stdout; + out = 1; + break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': factor=factor*10+modifier-'0'; @@ -40,15 +44,17 @@ int main (int argc, char **argv){ return EXIT_FAILURE; } strlcpy(name,argv[arg],sizeof(name)); - strlcat(name,".dpu",sizeof(name)); + strlcat(name,".dpu",sizeof(name)); if((bob = fopen(argv[arg],"r"))==NULL){ fputs("NO YOU FOOL, A REAL ONE!\n",stderr); return EXIT_FAILURE; } - if((joe = fopen(name,"w"))==NULL){ - fputs("Ummm, you seem to have an unwritable file or directory or something silly called the output file, this is dumb. Please stop.\n",stderr); - return EXIT_FAILURE; - } + if(!out){ + if((joe = fopen(name,"w"))==NULL){ + fputs("Ummm, you seem to have an unwritable file or directory or something silly called the output file, this is dumb. Please stop.\n",stderr); + return EXIT_FAILURE; + } + } if((moe = fopen("/dev/urandom","r"))==NULL){ fputs("So, you aren't random enough. Annoying.\n",stderr); return EXIT_FAILURE; -- 2.37.3