|
1 | 1 | /* |
2 | | - * Copyright (c) 2006-2023, RT-Thread Development Team |
| 2 | + * Copyright (c) 2006-2024 RT-Thread Development Team |
3 | 3 | * |
4 | 4 | * SPDX-License-Identifier: Apache-2.0 |
5 | 5 | * |
|
31 | 31 | * return a file descriptor according specified flags. |
32 | 32 | * |
33 | 33 | * @param file the path name of file. |
34 | | - * @param flags the file open flags. |
| 34 | + * @param flags the file open flags. Common values include: |
| 35 | + * - Access modes (mutually exclusive): |
| 36 | + * - `O_RDONLY`: Open for read-only access. |
| 37 | + * - `O_WRONLY`: Open for write-only access. |
| 38 | + * - `O_RDWR`: Open for both reading and writing. |
| 39 | + * - File status flags (can be combined with bitwise OR `|`): |
| 40 | + * - `O_CREAT`: Create the file if it does not exist. Requires a `mode` argument. |
| 41 | + * - `O_TRUNC`: Truncate the file to zero length if it already exists. |
| 42 | + * - `O_APPEND`: Append writes to the end of the file. |
| 43 | + * - `O_EXCL`: Ensure that `O_CREAT` creates the file exclusively. |
| 44 | + * - Other platform-specific flags |
35 | 45 | * |
36 | 46 | * @return the non-negative integer on successful open, others for failed. |
37 | 47 | */ |
@@ -81,6 +91,22 @@ RTM_EXPORT(open); |
81 | 91 | #ifndef AT_FDCWD |
82 | 92 | #define AT_FDCWD (-100) |
83 | 93 | #endif |
| 94 | + |
| 95 | +/** |
| 96 | + * @brief Opens a file relative to a directory file descriptor. |
| 97 | + * |
| 98 | + * @param dirfd The file descriptor of the directory to base the relative path on. |
| 99 | + * @param pathname The path to the file to be opened, relative to the directory specified by `dirfd`. |
| 100 | + * Can be an absolute path (in which case `dirfd` is ignored). |
| 101 | + * @param flags File access and status flags (e.g., `O_RDONLY`, `O_WRONLY`, `O_CREAT`). |
| 102 | + * |
| 103 | + * @return On success, returns a new file descriptor for the opened file. |
| 104 | + * On failure, returns `-1` and sets `errno` to indicate the error. |
| 105 | + * |
| 106 | + * @note When using relative paths, ensure `dirfd` is a valid directory descriptor. |
| 107 | + * When `pathname` is absolute, the `dirfd` argument is ignored. |
| 108 | + * |
| 109 | + */ |
84 | 110 | int openat(int dirfd, const char *path, int flag, ...) |
85 | 111 | { |
86 | 112 | struct dfs_file *d; |
@@ -171,7 +197,7 @@ int utimensat(int __fd, const char *__path, const struct timespec __times[2], in |
171 | 197 | } |
172 | 198 | } |
173 | 199 |
|
174 | | - //update time |
| 200 | + /*update time*/ |
175 | 201 | attr.ia_valid = ATTR_ATIME_SET | ATTR_MTIME_SET; |
176 | 202 | time(¤t_time); |
177 | 203 | if (UTIME_NOW == __times[0].tv_nsec) |
@@ -374,14 +400,22 @@ ssize_t write(int fd, const void *buf, size_t len) |
374 | 400 | RTM_EXPORT(write); |
375 | 401 |
|
376 | 402 | /** |
377 | | - * this function is a POSIX compliant version, which will seek the offset for |
| 403 | + * this function is a POSIX compliant version, which will Reposition the file offset for |
378 | 404 | * an open file descriptor. |
379 | 405 | * |
| 406 | + * The `lseek` function sets the file offset for the file descriptor `fd` |
| 407 | + * to a new value, determined by the `offset` and `whence` parameters. |
| 408 | + * It can be used to seek to specific positions in a file for reading or writing. |
| 409 | + * |
380 | 410 | * @param fd the file descriptor. |
381 | | - * @param offset the offset to be seeked. |
382 | | - * @param whence the directory of seek. |
| 411 | + * @param offset The offset, in bytes, to set the file position. |
| 412 | + * The meaning of `offset` depends on the value of `whence`. |
| 413 | + * @param whence the directive of seek. It can be one of: |
| 414 | + * - `SEEK_SET`: Set the offset to `offset` bytes from the beginning of the file. |
| 415 | + * - `SEEK_CUR`: Set the offset to its current location plus `offset` bytes. |
| 416 | + * - `SEEK_END`: Set the offset to the size of the file plus `offset` bytes. |
383 | 417 | * |
384 | | - * @return the current read/write position in the file, or -1 on failed. |
| 418 | + * @return the resulting read/write position in the file, or -1 on failed. |
385 | 419 | */ |
386 | 420 | off_t lseek(int fd, off_t offset, int whence) |
387 | 421 | { |
@@ -581,9 +615,15 @@ RTM_EXPORT(fsync); |
581 | 615 | * control functions on devices. |
582 | 616 | * |
583 | 617 | * @param fildes the file description |
584 | | - * @param cmd the specified command |
| 618 | + * @param cmd the specified command, Common values include: |
| 619 | + * - `F_DUPFD`: Duplicate a file descriptor. |
| 620 | + * - `F_GETFD`: Get the file descriptor flags. |
| 621 | + * - `F_SETFD`: Set the file descriptor flags. |
| 622 | + * - `F_GETFL`: Get the file status flags. |
| 623 | + * - `F_SETFL`: Set the file status flags. |
585 | 624 | * @param ... represents the additional information that is needed by this |
586 | | - * specific device to perform the requested function. |
| 625 | + * specific device to perform the requested function. For example: |
| 626 | + * - When `cmd` is `F_SETFL`, an additional integer argument specifies the new status flags. |
587 | 627 | * |
588 | 628 | * @return 0 on successful completion. Otherwise, -1 shall be returned and errno |
589 | 629 | * set to indicate the error. |
@@ -765,7 +805,7 @@ RTM_EXPORT(fstatfs); |
765 | 805 | * this function is a POSIX compliant version, which will make a directory |
766 | 806 | * |
767 | 807 | * @param path the directory path to be made. |
768 | | - * @param mode |
| 808 | + * @param mode The permission mode for the new directory (unused here, can be set to 0). |
769 | 809 | * |
770 | 810 | * @return 0 on successful, others on failed. |
771 | 811 | */ |
|
0 commit comments