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