I tried using the fallocate()
or the posix_fallocate()
function in my CPP program, but my compiler kept telling me, that it couldn't find that function. So I created this minimal program:
#include <fcntl.h>
int main() {
int fd = open("lol", O_RDWR|O_CREAT, 0666);
if (fd < 0) return 1;
return posix_fallocate(fd, 0, 400000);
}
But when I'm trying to compile it, my compiler tells me:
c++ -g -O2 -Wall -Wextra -std=c++2a test.cc -o test
test.cc:5:12: error: use of undeclared identifier 'posix_fallocate'
return posix_fallocate(fd, 0, 400000);
^
1 error generated.
make: *** [test] Error 1
As you can see, I'm using c++20. I tried this on my Mac with Catalina and clang. It works fine on a Linux shell that I tried.
Why is that and is there a way to make fallocate()
work on a Mac?