* @brief This function will creat a anonymous pipe. * * @param fildes[0] is the read handle. * fildes[1] is the write handle. * * @return Return the operation status. * When the return value is 0, it means the operation is successful. * When the return value is -1, it means the operation is failed. */
| 735 | * When the return value is -1, it means the operation is failed. |
| 736 | */ |
| 737 | int pipe(int fildes[2]) |
| 738 | { |
| 739 | rt_pipe_t *pipe; |
| 740 | char dname[8]; |
| 741 | char dev_name[32]; |
| 742 | int pipeno = 0; |
| 743 | |
| 744 | pipeno = resource_id_get(&id_mgr); |
| 745 | if (pipeno == -1) |
| 746 | { |
| 747 | return -1; |
| 748 | } |
| 749 | rt_snprintf(dname, sizeof(dname), "pipe%d", pipeno); |
| 750 | |
| 751 | pipe = rt_pipe_create(dname, RT_USING_POSIX_PIPE_SIZE); |
| 752 | if (pipe == RT_NULL) |
| 753 | { |
| 754 | resource_id_put(&id_mgr, pipeno); |
| 755 | return -1; |
| 756 | } |
| 757 | |
| 758 | pipe->is_named = RT_FALSE; /* unamed pipe */ |
| 759 | pipe->pipeno = pipeno; |
| 760 | rt_snprintf(dev_name, sizeof(dev_name), "/dev/%s", dname); |
| 761 | |
| 762 | fildes[1] = open(dev_name, O_WRONLY, 0); |
| 763 | if (fildes[1] < 0) |
| 764 | { |
| 765 | rt_pipe_delete(dname); |
| 766 | return -1; |
| 767 | } |
| 768 | |
| 769 | fildes[0] = open(dev_name, O_RDONLY, 0); |
| 770 | if (fildes[0] < 0) |
| 771 | { |
| 772 | close(fildes[1]); |
| 773 | rt_pipe_delete(dname); |
| 774 | return -1; |
| 775 | } |
| 776 | |
| 777 | return 0; |
| 778 | } |
| 779 | |
| 780 | /** |
| 781 | * @brief This function will create a named pipe. |
no test coverage detected