mirror of
https://github.com/janet-lang/janet
synced 2025-05-04 16:34:15 +00:00
Fix os/open with :rw permissions on posix.
This commit is contained in:
parent
e731996a68
commit
60e0f32f1a
@ -2137,20 +2137,18 @@ JANET_CORE_FN(os_open,
|
|||||||
#ifdef JANET_LINUX
|
#ifdef JANET_LINUX
|
||||||
open_flags |= O_CLOEXEC;
|
open_flags |= O_CLOEXEC;
|
||||||
#endif
|
#endif
|
||||||
|
int read_flag = 0;
|
||||||
|
int write_flag = 0;
|
||||||
for (const uint8_t *c = opt_flags; *c; c++) {
|
for (const uint8_t *c = opt_flags; *c; c++) {
|
||||||
switch (*c) {
|
switch (*c) {
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
case 'r':
|
case 'r':
|
||||||
open_flags = (open_flags & O_WRONLY)
|
read_flag = 1;
|
||||||
? ((open_flags & ~O_WRONLY) | O_RDWR)
|
|
||||||
: (open_flags | O_RDONLY);
|
|
||||||
stream_flags |= JANET_STREAM_READABLE;
|
stream_flags |= JANET_STREAM_READABLE;
|
||||||
break;
|
break;
|
||||||
case 'w':
|
case 'w':
|
||||||
open_flags = (open_flags & O_RDONLY)
|
write_flag = 1;
|
||||||
? ((open_flags & ~O_RDONLY) | O_RDWR)
|
|
||||||
: (open_flags | O_WRONLY);
|
|
||||||
stream_flags |= JANET_STREAM_WRITABLE;
|
stream_flags |= JANET_STREAM_WRITABLE;
|
||||||
break;
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
@ -2174,6 +2172,15 @@ JANET_CORE_FN(os_open,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/* If both read and write, fix up to O_RDWR */
|
||||||
|
if (read_flag && !write_flag) {
|
||||||
|
open_flags |= O_RDONLY;
|
||||||
|
} else if (write_flag && !read_flag) {
|
||||||
|
open_flags |= O_WRONLY;
|
||||||
|
} else {
|
||||||
|
open_flags = O_RDWR;
|
||||||
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
fd = open(path, open_flags, mode);
|
fd = open(path, open_flags, mode);
|
||||||
} while (fd == -1 && errno == EINTR);
|
} while (fd == -1 && errno == EINTR);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user