pipe.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2012-09-30 Bernard first version.
  9. * 2017-11-08 JasonJiaJie fix memory leak issue when close a pipe.
  10. */
  11. #include <rthw.h>
  12. #include <rtdevice.h>
  13. #include <stdint.h>
  14. #include <sys/errno.h>
  15. #if defined(RT_USING_POSIX_DEVIO) && defined(RT_USING_POSIX_PIPE)
  16. #include <unistd.h>
  17. #include <fcntl.h>
  18. #include <poll.h>
  19. #include <sys/ioctl.h>
  20. /**
  21. * @brief This function will open a pipe.
  22. *
  23. * @param fd is the file descriptor.
  24. *
  25. * @return Return the operation status.
  26. * When the return value is 0, it means the operation is successful.
  27. * When the return value is -1, it means the file descriptor is invalid.
  28. * When the return value is -RT_ENOMEM, it means insufficient memory allocation failed.
  29. */
  30. static int pipe_fops_open(struct dfs_fd *fd)
  31. {
  32. int rc = 0;
  33. rt_device_t device;
  34. rt_pipe_t *pipe;
  35. pipe = (rt_pipe_t *)fd->data;
  36. if (!pipe) return -1;
  37. device = &(pipe->parent);
  38. rt_mutex_take(&(pipe->lock), RT_WAITING_FOREVER);
  39. if (device->ref_count == 0)
  40. {
  41. pipe->fifo = rt_ringbuffer_create(pipe->bufsz);
  42. if (pipe->fifo == RT_NULL)
  43. {
  44. rc = -RT_ENOMEM;
  45. goto __exit;
  46. }
  47. }
  48. switch (fd->flags & O_ACCMODE)
  49. {
  50. case O_RDONLY:
  51. pipe->readers ++;
  52. break;
  53. case O_WRONLY:
  54. pipe->writers ++;
  55. break;
  56. case O_RDWR:
  57. pipe->readers ++;
  58. pipe->writers ++;
  59. break;
  60. }
  61. device->ref_count ++;
  62. __exit:
  63. rt_mutex_release(&(pipe->lock));
  64. return rc;
  65. }
  66. /**
  67. * @brief This function will close a pipe.
  68. *
  69. * @param fd is the file descriptor.
  70. *
  71. * @return Return the operation status.
  72. * When the return value is 0, it means the operation is successful.
  73. * When the return value is -1, it means the file descriptor is invalid.
  74. */
  75. static int pipe_fops_close(struct dfs_fd *fd)
  76. {
  77. rt_device_t device;
  78. rt_pipe_t *pipe;
  79. pipe = (rt_pipe_t *)fd->data;
  80. if (!pipe) return -1;
  81. device = &(pipe->parent);
  82. rt_mutex_take(&(pipe->lock), RT_WAITING_FOREVER);
  83. switch (fd->flags & O_ACCMODE)
  84. {
  85. case O_RDONLY:
  86. pipe->readers --;
  87. break;
  88. case O_WRONLY:
  89. pipe->writers --;
  90. break;
  91. case O_RDWR:
  92. pipe->readers --;
  93. pipe->writers --;
  94. break;
  95. }
  96. if (pipe->writers == 0)
  97. {
  98. rt_wqueue_wakeup(&(pipe->reader_queue), (void*)(POLLIN | POLLERR | POLLHUP));
  99. }
  100. if (pipe->readers == 0)
  101. {
  102. rt_wqueue_wakeup(&(pipe->writer_queue), (void*)(POLLOUT | POLLERR | POLLHUP));
  103. }
  104. if (device->ref_count == 1)
  105. {
  106. if (pipe->fifo != RT_NULL)
  107. rt_ringbuffer_destroy(pipe->fifo);
  108. pipe->fifo = RT_NULL;
  109. }
  110. device->ref_count --;
  111. rt_mutex_release(&(pipe->lock));
  112. if (device->ref_count == 0 && pipe->is_named == RT_FALSE)
  113. {
  114. /* delete the unamed pipe */
  115. rt_pipe_delete(device->parent.name);
  116. }
  117. return 0;
  118. }
  119. /**
  120. * @brief This function will get the pipe space size depends on the command.
  121. *
  122. * @param fd is the file descriptor.
  123. *
  124. * @param cmd is the command. It determines what data will get.
  125. *
  126. * FIONREAD The command to get the number of bytes in the pipe.
  127. *
  128. * FIONWRITE The command to get the number of bytes can be written to the pipe.
  129. *
  130. * @param args is the pointer to the data to store the read data.
  131. *
  132. * @return Return the operation status.
  133. * When the return value is 0, it means the operation is successful.
  134. * When the return value is -EINVAL, it means the command is invalid.
  135. */
  136. static int pipe_fops_ioctl(struct dfs_fd *fd, int cmd, void *args)
  137. {
  138. rt_pipe_t *pipe;
  139. int ret = 0;
  140. pipe = (rt_pipe_t *)fd->data;
  141. switch (cmd)
  142. {
  143. case FIONREAD:
  144. *((int*)args) = rt_ringbuffer_data_len(pipe->fifo);
  145. break;
  146. case FIONWRITE:
  147. *((int*)args) = rt_ringbuffer_space_len(pipe->fifo);
  148. break;
  149. default:
  150. ret = -EINVAL;
  151. break;
  152. }
  153. return ret;
  154. }
  155. /**
  156. * @brief This function will read data from pipe.
  157. *
  158. * @param fd is the file descriptor.
  159. *
  160. * @param buf is the buffer to store the read data.
  161. *
  162. * @param count is the length of data to be read.
  163. *
  164. * @return Return the length of data read.
  165. * When the return value is 0, it means O_NONBLOCK is enabled and there is no thread that has the pipe open for writing.
  166. * When the return value is -EAGAIN, it means there are no data to be read.
  167. */
  168. static int pipe_fops_read(struct dfs_fd *fd, void *buf, size_t count)
  169. {
  170. int len = 0;
  171. rt_pipe_t *pipe;
  172. pipe = (rt_pipe_t *)fd->data;
  173. /* no process has the pipe open for writing, return end-of-file */
  174. if (pipe->writers == 0)
  175. return 0;
  176. rt_mutex_take(&(pipe->lock), RT_WAITING_FOREVER);
  177. while (1)
  178. {
  179. if (pipe->writers == 0)
  180. {
  181. goto out;
  182. }
  183. len = rt_ringbuffer_get(pipe->fifo, buf, count);
  184. if (len > 0)
  185. {
  186. break;
  187. }
  188. else
  189. {
  190. if (fd->flags & O_NONBLOCK)
  191. {
  192. len = -EAGAIN;
  193. goto out;
  194. }
  195. rt_mutex_release(&pipe->lock);
  196. rt_wqueue_wakeup(&(pipe->writer_queue), (void*)POLLOUT);
  197. rt_wqueue_wait(&(pipe->reader_queue), 0, -1);
  198. rt_mutex_take(&(pipe->lock), RT_WAITING_FOREVER);
  199. }
  200. }
  201. /* wakeup writer */
  202. rt_wqueue_wakeup(&(pipe->writer_queue), (void*)POLLOUT);
  203. out:
  204. rt_mutex_release(&pipe->lock);
  205. return len;
  206. }
  207. /**
  208. * @brief This function will write data to pipe.
  209. *
  210. * @param fd is the file descriptor.
  211. *
  212. * @param buf is a pointer to the data buffer to be written.
  213. *
  214. * @param count is the length of data to be write.
  215. *
  216. * @return Return the length of data written.
  217. * When the return value is -EAGAIN, it means O_NONBLOCK is enabled and there are no space to be written.
  218. * When the return value is -EPIPE, it means there is no thread that has the pipe open for reading.
  219. */
  220. static int pipe_fops_write(struct dfs_fd *fd, const void *buf, size_t count)
  221. {
  222. int len;
  223. rt_pipe_t *pipe;
  224. int wakeup = 0;
  225. int ret = 0;
  226. uint8_t *pbuf;
  227. pipe = (rt_pipe_t *)fd->data;
  228. if (pipe->readers == 0)
  229. {
  230. ret = -EPIPE;
  231. goto out;
  232. }
  233. if (count == 0)
  234. return 0;
  235. pbuf = (uint8_t*)buf;
  236. rt_mutex_take(&pipe->lock, -1);
  237. while (1)
  238. {
  239. if (pipe->readers == 0)
  240. {
  241. if (ret == 0)
  242. ret = -EPIPE;
  243. break;
  244. }
  245. len = rt_ringbuffer_put(pipe->fifo, pbuf, count - ret);
  246. ret += len;
  247. pbuf += len;
  248. wakeup = 1;
  249. if (ret == count)
  250. {
  251. break;
  252. }
  253. else
  254. {
  255. if (fd->flags & O_NONBLOCK)
  256. {
  257. if (ret == 0)
  258. {
  259. ret = -EAGAIN;
  260. }
  261. break;
  262. }
  263. }
  264. rt_mutex_release(&pipe->lock);
  265. rt_wqueue_wakeup(&(pipe->reader_queue), (void*)POLLIN);
  266. /* pipe full, waiting on suspended write list */
  267. rt_wqueue_wait(&(pipe->writer_queue), 0, -1);
  268. rt_mutex_take(&pipe->lock, -1);
  269. }
  270. rt_mutex_release(&pipe->lock);
  271. if (wakeup)
  272. {
  273. rt_wqueue_wakeup(&(pipe->reader_queue), (void*)POLLIN);
  274. }
  275. out:
  276. return ret;
  277. }
  278. /**
  279. * @brief This function will get the pipe status.
  280. *
  281. * @param fd is the file descriptor.
  282. *
  283. * @param req is the request type.
  284. *
  285. * @return mask of the pipe status.
  286. * POLLIN means there is data to be read.
  287. * POLLHUP means there is no thread that occupied the pipe to open for writing.
  288. * POLLOUT means there is space to be written.
  289. * POLLERR means there is no thread that occupied the pipe to open for reading.
  290. */
  291. static int pipe_fops_poll(struct dfs_fd *fd, rt_pollreq_t *req)
  292. {
  293. int mask = 0;
  294. rt_pipe_t *pipe;
  295. int mode = 0;
  296. pipe = (rt_pipe_t *)fd->data;
  297. rt_poll_add(&(pipe->reader_queue), req);
  298. rt_poll_add(&(pipe->writer_queue), req);
  299. switch (fd->flags & O_ACCMODE)
  300. {
  301. case O_RDONLY:
  302. mode = 1;
  303. break;
  304. case O_WRONLY:
  305. mode = 2;
  306. break;
  307. case O_RDWR:
  308. mode = 3;
  309. break;
  310. }
  311. if (mode & 1)
  312. {
  313. if (rt_ringbuffer_data_len(pipe->fifo) != 0)
  314. {
  315. mask |= POLLIN;
  316. }
  317. if (pipe->writers == 0)
  318. {
  319. mask |= POLLHUP;
  320. }
  321. }
  322. if (mode & 2)
  323. {
  324. if (rt_ringbuffer_space_len(pipe->fifo) != 0)
  325. {
  326. mask |= POLLOUT;
  327. }
  328. if (pipe->readers == 0)
  329. {
  330. mask |= POLLERR;
  331. }
  332. }
  333. return mask;
  334. }
  335. static const struct dfs_file_ops pipe_fops =
  336. {
  337. pipe_fops_open,
  338. pipe_fops_close,
  339. pipe_fops_ioctl,
  340. pipe_fops_read,
  341. pipe_fops_write,
  342. RT_NULL,
  343. RT_NULL,
  344. RT_NULL,
  345. pipe_fops_poll,
  346. };
  347. #endif /* defined(RT_USING_POSIX_DEVIO) && defined(RT_USING_POSIX_PIPE) */
  348. /**
  349. * @brief This function will open the pipe and actually creates the pipe buffer.
  350. *
  351. * @param device is a pointer to the pipe device descriptor.
  352. *
  353. * @param oflag is the open method, but it is not used yet.
  354. *
  355. * @return Return the operation status.
  356. * When the return value is RT_EOK, the operation is successful.
  357. * When the return value is -RT_EINVAL, it means the device handle is empty.
  358. * When the return value is -RT_ENOMEM, it means insufficient memory allocation failed.
  359. */
  360. static rt_err_t rt_pipe_open(rt_device_t device, rt_uint16_t oflag)
  361. {
  362. rt_pipe_t *pipe = (rt_pipe_t *)device;
  363. rt_err_t ret = RT_EOK;
  364. if (device == RT_NULL)
  365. {
  366. ret = -RT_EINVAL;
  367. goto __exit;
  368. }
  369. rt_mutex_take(&(pipe->lock), RT_WAITING_FOREVER);
  370. if (pipe->fifo == RT_NULL)
  371. {
  372. pipe->fifo = rt_ringbuffer_create(pipe->bufsz);
  373. if (pipe->fifo == RT_NULL)
  374. {
  375. ret = -RT_ENOMEM;
  376. }
  377. }
  378. rt_mutex_release(&(pipe->lock));
  379. __exit:
  380. return ret;
  381. }
  382. /**
  383. * @brief This function will close the pipe and release the pipe buffer.
  384. *
  385. * @param device is a pointer to the pipe device descriptor.
  386. *
  387. * @return Return the operation status.
  388. * When the return value is RT_EOK, the operation is successful.
  389. * When the return value is -RT_EINVAL, it means the device handle is empty.
  390. */
  391. static rt_err_t rt_pipe_close(rt_device_t device)
  392. {
  393. rt_pipe_t *pipe = (rt_pipe_t *)device;
  394. if (device == RT_NULL) return -RT_EINVAL;
  395. rt_mutex_take(&(pipe->lock), RT_WAITING_FOREVER);
  396. if (device->ref_count == 1)
  397. {
  398. rt_ringbuffer_destroy(pipe->fifo);
  399. pipe->fifo = RT_NULL;
  400. }
  401. rt_mutex_release(&(pipe->lock));
  402. return RT_EOK;
  403. }
  404. /**
  405. * @brief This function will read the specified length of data from the pipe.
  406. *
  407. * @param device is a pointer to the pipe device descriptor.
  408. *
  409. * @param pos is a parameter compatible with POSIX standard interface (currently meaningless, just pass in 0).
  410. *
  411. * @param buffer is a pointer to the buffer to store the read data.
  412. *
  413. * @param count is the length of data to be read.
  414. *
  415. * @return Return the length of data read.
  416. * When the return value is 0, it means the pipe device handle is empty or the count is 0.
  417. */
  418. static rt_size_t rt_pipe_read(rt_device_t device, rt_off_t pos, void *buffer, rt_size_t count)
  419. {
  420. uint8_t *pbuf;
  421. rt_size_t read_bytes = 0;
  422. rt_pipe_t *pipe = (rt_pipe_t *)device;
  423. if (device == RT_NULL)
  424. {
  425. rt_set_errno(EINVAL);
  426. return 0;
  427. }
  428. if (count == 0) return 0;
  429. pbuf = (uint8_t*)buffer;
  430. rt_mutex_take(&(pipe->lock), RT_WAITING_FOREVER);
  431. while (read_bytes < count)
  432. {
  433. int len = rt_ringbuffer_get(pipe->fifo, &pbuf[read_bytes], count - read_bytes);
  434. if (len <= 0) break;
  435. read_bytes += len;
  436. }
  437. rt_mutex_release(&pipe->lock);
  438. return read_bytes;
  439. }
  440. /**
  441. * @brief This function will write the specified length of data to the pipe.
  442. *
  443. * @param device is a pointer to the pipe device descriptor.
  444. *
  445. * @param pos is a parameter compatible with POSIX standard interface (currently meaningless, just pass in 0).
  446. *
  447. * @param buffer is a pointer to the data buffer to be written.
  448. *
  449. * @param count is the length of data to be written.
  450. *
  451. * @return Return the length of data written.
  452. * When the return value is 0, it means the pipe device handle is empty or the count is 0.
  453. */
  454. static rt_size_t rt_pipe_write(rt_device_t device, rt_off_t pos, const void *buffer, rt_size_t count)
  455. {
  456. uint8_t *pbuf;
  457. rt_size_t write_bytes = 0;
  458. rt_pipe_t *pipe = (rt_pipe_t *)device;
  459. if (device == RT_NULL)
  460. {
  461. rt_set_errno(EINVAL);
  462. return 0;
  463. }
  464. if (count == 0) return 0;
  465. pbuf = (uint8_t*)buffer;
  466. rt_mutex_take(&pipe->lock, -1);
  467. while (write_bytes < count)
  468. {
  469. int len = rt_ringbuffer_put(pipe->fifo, &pbuf[write_bytes], count - write_bytes);
  470. if (len <= 0) break;
  471. write_bytes += len;
  472. }
  473. rt_mutex_release(&pipe->lock);
  474. return write_bytes;
  475. }
  476. /**
  477. * @brief This function is not used yet.
  478. *
  479. * @param dev is not used yet.
  480. *
  481. * @param cmd is not used yet.
  482. *
  483. * @param args is not used yet.
  484. *
  485. * @return Always return RT_EOK.
  486. */
  487. static rt_err_t rt_pipe_control(rt_device_t dev, int cmd, void *args)
  488. {
  489. return RT_EOK;
  490. }
  491. #ifdef RT_USING_DEVICE_OPS
  492. const static struct rt_device_ops pipe_ops =
  493. {
  494. RT_NULL,
  495. rt_pipe_open,
  496. rt_pipe_close,
  497. rt_pipe_read,
  498. rt_pipe_write,
  499. rt_pipe_control,
  500. };
  501. #endif /* RT_USING_DEVICE_OPS */
  502. /**
  503. * @brief This function will initialize a pipe device.
  504. * The system allocates a pipe handle from dynamic heap memory, initializes the pipe handle
  505. * with the specified value, and registers the pipe device with the system.
  506. *
  507. * @param name is the name of pipe device.
  508. *
  509. * @param bufsz is the size of pipe buffer.
  510. *
  511. * @return Return the pointer to the pipe device.
  512. * When the return value is RT_NULL, it means the initialization failed.
  513. */
  514. rt_pipe_t *rt_pipe_create(const char *name, int bufsz)
  515. {
  516. rt_pipe_t *pipe;
  517. rt_device_t dev;
  518. pipe = (rt_pipe_t *)rt_malloc(sizeof(rt_pipe_t));
  519. if (pipe == RT_NULL) return RT_NULL;
  520. rt_memset(pipe, 0, sizeof(rt_pipe_t));
  521. pipe->is_named = RT_TRUE; /* initialize as a named pipe */
  522. rt_mutex_init(&(pipe->lock), name, RT_IPC_FLAG_PRIO);
  523. rt_wqueue_init(&(pipe->reader_queue));
  524. rt_wqueue_init(&(pipe->writer_queue));
  525. RT_ASSERT(bufsz < 0xFFFF);
  526. pipe->bufsz = bufsz;
  527. dev = &(pipe->parent);
  528. dev->type = RT_Device_Class_Pipe;
  529. #ifdef RT_USING_DEVICE_OPS
  530. dev->ops = &pipe_ops;
  531. #else
  532. dev->init = RT_NULL;
  533. dev->open = rt_pipe_open;
  534. dev->read = rt_pipe_read;
  535. dev->write = rt_pipe_write;
  536. dev->close = rt_pipe_close;
  537. dev->control = rt_pipe_control;
  538. #endif
  539. dev->rx_indicate = RT_NULL;
  540. dev->tx_complete = RT_NULL;
  541. if (rt_device_register(&(pipe->parent), name, RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_REMOVABLE) != 0)
  542. {
  543. rt_free(pipe);
  544. return RT_NULL;
  545. }
  546. #if defined(RT_USING_POSIX_DEVIO) && defined(RT_USING_POSIX_PIPE)
  547. dev->fops = (void*)&pipe_fops;
  548. #endif
  549. return pipe;
  550. }
  551. /**
  552. * @brief This function will delete a pipe device.
  553. * The system will release the pipe handle and unregister the pipe device from the system.
  554. *
  555. * @param pipe is the pointer to the pipe device.
  556. *
  557. * @return Return the operation status.
  558. * When the return value is 0, it means the operation is successful.
  559. * When the return value is -RT_EINVAL, it means the pipe device is not found or the device isn't a pipe.
  560. * When the return value is -RT_EBUSY, it means the pipe device is busy.
  561. */
  562. int rt_pipe_delete(const char *name)
  563. {
  564. int result = 0;
  565. rt_device_t device;
  566. device = rt_device_find(name);
  567. if (device)
  568. {
  569. if (device->type == RT_Device_Class_Pipe)
  570. {
  571. rt_pipe_t *pipe;
  572. if (device->ref_count != 0)
  573. {
  574. return -RT_EBUSY;
  575. }
  576. pipe = (rt_pipe_t *)device;
  577. rt_mutex_detach(&(pipe->lock));
  578. rt_device_unregister(device);
  579. /* close fifo ringbuffer */
  580. if (pipe->fifo)
  581. {
  582. rt_ringbuffer_destroy(pipe->fifo);
  583. pipe->fifo = RT_NULL;
  584. }
  585. rt_free(pipe);
  586. }
  587. else
  588. {
  589. result = -RT_EINVAL;
  590. }
  591. }
  592. else
  593. {
  594. result = -RT_EINVAL;
  595. }
  596. return result;
  597. }
  598. #if defined(RT_USING_POSIX_DEVIO) && defined(RT_USING_POSIX_PIPE)
  599. /**
  600. * @brief This function will creat a anonymous pipe.
  601. *
  602. * @param fildes[0] is the read handle.
  603. * fildes[1] is the write handle.
  604. *
  605. * @return Return the operation status.
  606. * When the return value is 0, it means the operation is successful.
  607. * When the return value is -1, it means the operation is failed.
  608. */
  609. int pipe(int fildes[2])
  610. {
  611. rt_pipe_t *pipe;
  612. char dname[RT_NAME_MAX];
  613. char dev_name[RT_NAME_MAX * 4];
  614. static int pipeno = 0;
  615. rt_snprintf(dname, sizeof(dname), "pipe%d", pipeno++);
  616. pipe = rt_pipe_create(dname, RT_USING_POSIX_PIPE_SIZE);
  617. if (pipe == RT_NULL)
  618. {
  619. return -1;
  620. }
  621. pipe->is_named = RT_FALSE; /* unamed pipe */
  622. rt_snprintf(dev_name, sizeof(dev_name), "/dev/%s", dname);
  623. fildes[0] = open(dev_name, O_RDONLY, 0);
  624. if (fildes[0] < 0)
  625. {
  626. return -1;
  627. }
  628. fildes[1] = open(dev_name, O_WRONLY, 0);
  629. if (fildes[1] < 0)
  630. {
  631. close(fildes[0]);
  632. return -1;
  633. }
  634. return 0;
  635. }
  636. /**
  637. * @brief This function will create a named pipe.
  638. *
  639. * @param path is the name of pipe device.
  640. *
  641. * @param mode is not used yet.
  642. *
  643. * @return Return the operation status.
  644. * When the return value is 0, it means the operation is successful.
  645. * When the return value is -1, it means the operation is failed.
  646. */
  647. int mkfifo(const char *path, mode_t mode)
  648. {
  649. rt_pipe_t *pipe;
  650. pipe = rt_pipe_create(path, RT_USING_POSIX_PIPE_SIZE);
  651. if (pipe == RT_NULL)
  652. {
  653. return -1;
  654. }
  655. return 0;
  656. }
  657. #endif /* defined(RT_USING_POSIX_DEVIO) && defined(RT_USING_POSIX_PIPE) */