* this function is a POSIX compliant version, which shall perform a variety of * control functions on devices. * * @param fildes the file description * @param cmd the specified command, Common values include: * - `F_DUPFD`: Duplicate a file descriptor. * - `F_GETFD`: Get the file descriptor flags. * - `F_SETFD`: Set the file descriptor flags. * - `F_GETFL`: Get the file sta
| 629 | * set to indicate the error. |
| 630 | */ |
| 631 | int fcntl(int fildes, int cmd, ...) |
| 632 | { |
| 633 | int ret = -1; |
| 634 | struct dfs_file *file; |
| 635 | |
| 636 | file = fd_get(fildes); |
| 637 | if (file) |
| 638 | { |
| 639 | void *arg; |
| 640 | va_list ap; |
| 641 | |
| 642 | va_start(ap, cmd); |
| 643 | arg = va_arg(ap, void *); |
| 644 | va_end(ap); |
| 645 | |
| 646 | ret = dfs_file_ioctl(file, cmd, arg); |
| 647 | if (ret < 0) |
| 648 | { |
| 649 | ret = dfs_file_fcntl(fildes, cmd, (unsigned long)arg); |
| 650 | } |
| 651 | } |
| 652 | else |
| 653 | { |
| 654 | ret = -EBADF; |
| 655 | } |
| 656 | |
| 657 | if (ret < 0) |
| 658 | { |
| 659 | rt_set_errno(ret); |
| 660 | ret = -1; |
| 661 | } |
| 662 | |
| 663 | return ret; |
| 664 | } |
| 665 | RTM_EXPORT(fcntl); |
| 666 | |
| 667 | /** |
no test coverage detected