Skip to content

Instantly share code, notes, and snippets.

@h2onda
Created August 26, 2015 04:54
Show Gist options
  • Save h2onda/66c4cf9c54882518bf9d to your computer and use it in GitHub Desktop.
Save h2onda/66c4cf9c54882518bf9d to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
int main(void)
{
int fd, ret;
char filename[] = "testfile";
long size = 1024 * 1024 * 1024;
fd = open(filename, O_RDWR|O_CREAT);
if (fd==-1) {
printf("open testfile is failed!:%s\n", strerror(errno));
exit(1);
}
ret = posix_fallocate(fd, (off_t)0, (off_t)size);
if (ret != 0) {
printf("posix_fallocate is failed!:%s\n", strerror(ret));
exit(1);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment