#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define BUF_SIZE        (512 * 1024)
int
main(int argc, char *argv[])
{
    unsigned long long size  = 0;
    FILE *fp;
    char c = 0;

    char buf[BUF_SIZE];

    if (argc < 3) {
        printf("Usage: makepad <size bytes> <file>\n");
        exit(0);
    }
    memset (buf, 0, sizeof(buf));

    size = strtoull(argv[1], NULL, 0);
    fp = fopen(argv[2], "wb");
    if (fp == NULL) {
        fprintf(stderr, "%s: Can't open file %s for writing\n",
                         argv[0], argv[2]);
        return(1);
    }

    while(size > BUF_SIZE) {
        if (fwrite(buf, BUF_SIZE, 1, fp) != 1) {
            fprintf(stderr, "%s: Can't write all bytes to file %s\n",
                             argv[0], argv[2]);
            return(1);
        }
        size -= BUF_SIZE;
    }

    while(size--) {
        if (fwrite(&c, 1, 1, fp) != 1) {
            fprintf(stderr, "%s: Can't write all bytes to file %s\n",
                             argv[0], argv[2]);
            return(1);
        }
    }
    fclose(fp);
    return 0;
}
