mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-28 08:12:28 +00:00
Improve fcntl(F_{SET,GET}FL) implementation (#32)
This commit is contained in:
parent
4072e40bb8
commit
39bb91fc44
2 changed files with 78 additions and 18 deletions
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/nt/enum/accessmask.h"
|
||||
#include "libc/nt/enum/fileflagandattributes.h"
|
||||
|
@ -31,24 +32,15 @@ textwindows int fcntl$nt(int fd, int cmd, unsigned arg) {
|
|||
if (__isfdkind(fd, kFdFile) || __isfdkind(fd, kFdSocket)) {
|
||||
switch (cmd) {
|
||||
case F_GETFL:
|
||||
return g_fds.p[fd].flags;
|
||||
return g_fds.p[fd].flags & (O_ACCMODE | O_APPEND | O_ASYNC | O_DIRECT |
|
||||
O_NOATIME | O_NONBLOCK);
|
||||
case F_SETFL:
|
||||
if (ReOpenFile(
|
||||
g_fds.p[fd].handle,
|
||||
(arg & O_APPEND)
|
||||
? kNtFileAppendData
|
||||
: (arg & O_ACCMODE) == O_RDONLY
|
||||
? kNtGenericExecute | kNtFileGenericRead
|
||||
: kNtGenericExecute | kNtFileGenericRead |
|
||||
kNtFileGenericWrite,
|
||||
(arg & O_EXCL) == O_EXCL
|
||||
? kNtFileShareExclusive
|
||||
: kNtFileShareRead | kNtFileShareWrite | kNtFileShareDelete,
|
||||
kNtFileAttributeNotContentIndexed | kNtFileAttributeNormal)) {
|
||||
return (g_fds.p[fd].flags = arg);
|
||||
} else {
|
||||
return __winerr();
|
||||
}
|
||||
/*
|
||||
* - O_APPEND doesn't appear to be tunable at cursory glance
|
||||
* - O_NONBLOCK might require we start doing all i/o in threads
|
||||
* - O_DSYNC / O_RSYNC / O_SYNC maybe if we fsync() everything
|
||||
*/
|
||||
return einval();
|
||||
case F_GETFD:
|
||||
if (g_fds.p[fd].flags & O_CLOEXEC) {
|
||||
return FD_CLOEXEC;
|
||||
|
@ -64,7 +56,7 @@ textwindows int fcntl$nt(int fd, int cmd, unsigned arg) {
|
|||
return 0;
|
||||
}
|
||||
default:
|
||||
return 0; /* TODO(jart): Implement me. */
|
||||
return einval();
|
||||
}
|
||||
} else {
|
||||
return ebadf();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue