// vim: sw=4
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
int main(int argc, const char* argv[]) {
if (argc == 1) {
return -1;
}
int fd = open(argv[1],
O_CREAT | O_EXCL | O_WRONLY | O_SYNC | O_DIRECT,
S_IRUSR | S_IWUSR);
if (fd < 0) {
printf("open failed with error: %d\n", errno);
return 0;
}
const size_t sz = 1024 * 4;
char *data = NULL;
if (0 == posix_memalign((void **)&data, sz, sizeof(char) * sz)) {
if (write(fd, data, sizeof(char) * sz) < 0) {
printf("write failed with error: %d\n", errno);
}
free(data);
} else {
printf("posix_memalign failed with error: %d\n", errno);
}
close(fd);
return 0;
}
Comments