Changes in uspace/lib/posix/fcntl.c [ec18957a:9b1503e] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/posix/fcntl.c
rec18957a r9b1503e 38 38 #include "fcntl.h" 39 39 40 #include "libc/unistd.h"41 #include "libc/vfs/vfs.h"42 #include "errno.h"43 44 40 /** 45 * Performs set of operations on the opened files. 46 * 47 * @param fd File descriptor of the opened file. 48 * @param cmd Operation to carry out. 49 * @return Non-negative on success. Might have special meaning corresponding 50 * to the requested operation. 41 * 42 * @param fd 43 * @param cmd 44 * @param ... 45 * @return 51 46 */ 52 47 int posix_fcntl(int fd, int cmd, ...) 53 48 { 54 int rc; 55 int flags; 56 57 switch (cmd) { 58 case F_DUPFD: 59 case F_DUPFD_CLOEXEC: /* FD_CLOEXEC is not supported. */ 60 /* VFS does not provide means to express constraints on the new 61 * file descriptor so the third argument is ignored. */ 62 63 /* Retrieve node triplet corresponding to the file descriptor. */ 64 /* Empty statement after label. */; 65 fdi_node_t node; 66 rc = fd_node(fd, &node); 67 if (rc != EOK) { 68 errno = -rc; 69 return -1; 70 } 71 72 /* Reopen the node so the fresh file descriptor is generated. */ 73 int newfd = open_node(&node, 0); 74 if (newfd < 0) { 75 errno = -newfd; 76 return -1; 77 } 78 79 /* Associate the newly generated descriptor to the file description 80 * of the old file descriptor. Just reopened node will be automatically 81 * closed. */ 82 rc = dup2(fd, newfd); 83 if (rc != EOK) { 84 errno = -rc; 85 return -1; 86 } 87 88 return newfd; 89 case F_GETFD: 90 /* FD_CLOEXEC is not supported. There are no other flags. */ 91 return 0; 92 case F_SETFD: 93 /* FD_CLOEXEC is not supported. Ignore arguments and report success. */ 94 return 0; 95 case F_GETFL: 96 /* File status flags (i.e. O_APPEND) are currently private to the 97 * VFS server so it cannot be easily retrieved. */ 98 flags = 0; 99 /* File access flags are currently not supported for file descriptors. 100 * Provide full access. */ 101 flags |= O_RDWR; 102 return flags; 103 case F_SETFL: 104 /* File access flags are currently not supported for file descriptors. 105 * Ignore arguments and report success. */ 106 return 0; 107 case F_GETOWN: 108 case F_SETOWN: 109 case F_GETLK: 110 case F_SETLK: 111 case F_SETLKW: 112 /* Signals (SIGURG) and file locks are not supported. */ 113 errno = ENOTSUP; 114 return -1; 115 default: 116 /* Unknown command */ 117 errno = EINVAL; 118 return -1; 119 } 49 // TODO 50 not_implemented(); 120 51 } 121 52
Note:
See TracChangeset
for help on using the changeset viewer.