MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / pipe

Function pipe

components/drivers/ipc/pipe.c:737–778  ·  view source on GitHub ↗

* @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. */

Source from the content-addressed store, hash-verified

735 * When the return value is -1, it means the operation is failed.
736 */
737int 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.

Callers 1

sys_pipeFunction · 0.85

Calls 7

resource_id_getFunction · 0.85
rt_snprintfFunction · 0.85
rt_pipe_createFunction · 0.85
resource_id_putFunction · 0.85
rt_pipe_deleteFunction · 0.85
openFunction · 0.50
closeFunction · 0.50

Tested by

no test coverage detected