(C) How to create a file of a specific size?

It was suggested I use lseek() but can't I just use fseek? I need the size to be 2 MB. The file is supposed to be a "virtual disk" for my file system project. Here's some code for how I might do it.

int fd;
fd = fopen("disk.txt", w+);
fseek(fd, 2000000, SEEK_SET);

Is this basically what I'm supposed to do? After I create the file, I'll be using mmap() to map the file to static memory so I can use it as a file system.

Posted Dec 6, 2018, 1:03 AM UTC

01
Loading comments…