File: mklargefile.c

package info (click to toggle)
fsp 2.81.b24-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,904 kB
  • ctags: 1,423
  • sloc: ansic: 9,215; sh: 3,639; makefile: 212; lex: 130; csh: 77; python: 22
file content (62 lines) | stat: -rw-r--r-- 1,057 bytes parent folder | download | duplicates (3)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* this file is public domain */
/* return values:
 * 3 - invocation error
 * 2 - no LFS support
 * 1 - file creation failed
 * 0 - okay!
 */

#include "tweak.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>

int main(int argc,char *argv[])
{
    off_t GB=1024*1024*1024;
    FILE *fd;
    off_t pos;
    float size;

    if(argc<3)
    {
	printf("Makes a large file with hole using fseeko\n");
	printf("%s <filename> <floating point size in GB>\n",argv[0]);
	return 3;
    }

    fd = fopen(argv[1],"w");
    if(fd == NULL)
    {
	perror("fopen");
	return 1;
    }
    size=atof(argv[2]);
#if SIZEOF_OFF_T <= 4
    if(size>2)
    {
	printf("You do not have LFS your system.\nMaximum supported filesize is 2 GB.\n");
	return 2;
    }
#endif	
    pos=size*GB;
    if(fseeko(fd,pos,SEEK_SET))
    {
	perror("fseeko");
	return 1;
    }
    if(fwrite("!",1,1,fd)<1)
    {
	perror("write");
	return 1;
    }
    if(fclose(fd))
    {
	perror("fclose");
	return 1;
    }
    return 0;
}