'fchown fails after shm_open on MacOS X C
I want to open a shared memory file on MacOSX Monterey and then change the mode for read only.
I get the error message "invalid argument". is this the expected behavior on shared mem files or I'm missing something?
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <errno.h>
int main() {
int fd = shm_open("some_name", O_CREAT | O_EXCL | O_RDWR, S_IWUSR | S_IRUSR | S_IRGRP); // 0640
if (fd == -1) {
perror("shm_open");
exit(EXIT_FAILURE);
}
if (fchmod(fd, S_IRUSR | S_IRGRP ) == -1) { // 440
perror("chmod");
exit(EXIT_FAILURE);
}
return 0;
}
I get the error chmod: Invalid argument
This code works fine on Linux. https://onlinegdb.com/d9KDZbl3H
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|