#include #include #include #include #include #define usage() \ printf("Usage: %s [-F filename] [-S size] \n",argv[0]); \ exit(1); extern int optind; extern int optopt; extern int opterr; extern char *optarg; int main(int argc, char **argv) { int opt; ulong size; char *filename; int fd, i; while ((opt = getopt(argc, argv, "F:S:")) != EOF) { switch (opt) { case 'F': /* filename */ filename = optarg; case 'S': /* size */ size = atol(optarg); break; default: usage(); break; } } if ((fd = open(filename, O_CREAT | O_RDWR, 0700)) != -1 ) { for (i=0; i<(size/10); i++) { write(fd, "0123456789", 10); } for (i=0; i<(size%10); i++) { write(fd, "1", 1); } fsync(fd); close(fd); } else { perror("open failed"); return(-1); } }