File: makeimage.cpp

package info (click to toggle)
afflib 3.6.6-1.1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 5,320 kB
  • sloc: cpp: 21,493; ansic: 14,745; sh: 11,235; makefile: 538; python: 95
file content (36 lines) | stat: -rw-r--r-- 626 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
 * makeimage.cpp:
 * 
 * Make an image with a given number of sectors.
 */

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

const char *progname = "makeimage";

void usage()
{
    errx(1,"usage: %s file blockcount\n",progname);
}

int main(int argc,char **argv)
{
    if(argc!=3) usage();

    int  count = atoi(argv[2]);
    char buf[512];

    FILE *out = fopen(argv[1],"wb");
    if(!out) err(1,"fopen(%s)",argv[1]);

    memset(buf,' ',sizeof(buf));
    buf[511] = '\000';
    for(int i=0;i<count;i++){
	sprintf(buf,"Block %d\n",i);
	fwrite(buf,sizeof(buf),1,out);
    }
    fclose(out);
}