Changeset f00af83 in mainline
- Timestamp:
- 2011-08-19T17:09:26Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 07b39338, 921b84f, be79a663
- Parents:
- 107f2e0
- Location:
- uspace/lib/posix
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/posix/fcntl.c
r107f2e0 rf00af83 52 52 int posix_fcntl(int fd, int cmd, ...) 53 53 { 54 int rc;55 54 int flags; 56 55 57 56 switch (cmd) { 58 57 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; 58 case F_DUPFD_CLOEXEC: 59 /* VFS currently does not provide the functionality to duplicate 60 * opened file descriptor. */ 61 // FIXME: implement this once dup() is available 62 errno = ENOTSUP; 63 return -1; 89 64 case F_GETFD: 90 65 /* FD_CLOEXEC is not supported. There are no other flags. */ -
uspace/lib/posix/stdio.c
r107f2e0 rf00af83 257 257 assert(stream != NULL); 258 258 259 /* Retrieve the node. */260 struct stat st;261 int rc;262 263 259 if (filename == NULL) { 264 rc = fstat(stream->fd, &st); 265 } else { 266 rc = stat(filename, &st); 267 if (-rc == ENOENT) { 268 /* file does not exist, create new file */ 269 FILE* tmp = fopen(filename, mode); 270 if (tmp != NULL) { 271 fclose(tmp); 272 /* try again */ 273 rc = stat(filename, &st); 274 } 275 } 276 } 277 278 if (rc != EOK) { 279 fclose(stream); 280 errno = -rc; 281 return NULL; 282 } 283 284 fdi_node_t node = { 285 .fs_handle = st.fs_handle, 286 .service_id = st.service_id, 287 .index = st.index 288 }; 260 /* POSIX allows this to be imlementation-defined. HelenOS currently 261 * does not support changing the mode. */ 262 // FIXME: handle mode change once it is supported 263 return stream; 264 } 289 265 290 266 /* Open a new stream. */ 291 FILE* new = fopen _node(&node, mode);267 FILE* new = fopen(filename, mode); 292 268 if (new == NULL) { 293 269 fclose(stream); 294 /* fopen_node() sets errno.*/270 /* errno was set by fopen() */ 295 271 return NULL; 296 272 }
Note:
See TracChangeset
for help on using the changeset viewer.