Skip to content

Instantly share code, notes, and snippets.

@pmachapman
Created October 15, 2015 22:51
Show Gist options
  • Save pmachapman/313efd141efbf325f04d to your computer and use it in GitHub Desktop.
Save pmachapman/313efd141efbf325f04d to your computer and use it in GitHub Desktop.
Program to fill empty hard disk space with zeros, for MS-DOS (Similiar to SysInternal's SDelete for Windows)
/*
* Copyright (C) 2010 Shao Miller <shao.miller@yrdsb.edu.on.ca>
* Licensed under the GNU General Pulic License version 2 or later.
*/
#include <stdio.h>
#include <malloc.h>
int main(int argc, char *argv[])
{
FILE *f;
int buf_size, i, written;
char *m;
if (argc < 2) {
puts("FILL.COM (C) 2010 Shao Miller <shao.miller@yrdsb.edu.on.ca>\n"
"Licensed under the GNU General Public License ver. 2 or later.\n"
"\n"
"Usage: fill.com <0|1>\n"
" 0: Write 1 byte at a time\n"
" 1: Write 512 bytes at a time");
return -1;
}
switch (*argv[1]) {
case '0':
buf_size = 1;
break;
case '1':
buf_size = 512;
break;
default:
puts("Invalid argument. Use '0' (1 byte) or '1' (512 bytes)");
return -2;
}
m = malloc(buf_size);
if (!m) {
puts("Couldn't allocate a buffer");
return -3;
}
f = fopen("filler", "a+b");
if (!f) {
puts("Couldn't open file for writing.");
free(m);
return -4;
}
i = buf_size;
while (i--)
m[i] = ~0;
written = buf_size;
while (written)
ritten = fwrite(m, buf_size, 1, f);
fclose(f);
free(m);
return 0;
}
@pmachapman
Copy link
Author

Will compile using /tiny in Microsoft Quick C 2.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment