pipe.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /* Create a pipe.
  2. Copyright (C) 2009-2021 Free Software Foundation, Inc.
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 3, or (at your option)
  6. any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License along
  12. with this program; if not, see <https://www.gnu.org/licenses/>. */
  13. #include <config.h>
  14. /* Specification. */
  15. #include <unistd.h>
  16. #if defined _WIN32 && ! defined __CYGWIN__
  17. /* Native Windows API. */
  18. /* Get _pipe(). */
  19. # include <io.h>
  20. /* Get _O_BINARY. */
  21. # include <fcntl.h>
  22. int
  23. pipe (int fd[2])
  24. {
  25. /* Mingw changes fd to {-1,-1} on failure, but this violates
  26. http://austingroupbugs.net/view.php?id=467 */
  27. int tmp[2];
  28. int result = _pipe (tmp, 4096, _O_BINARY);
  29. if (!result)
  30. {
  31. fd[0] = tmp[0];
  32. fd[1] = tmp[1];
  33. }
  34. return result;
  35. }
  36. #else
  37. # error "This platform lacks a pipe function, and Gnulib doesn't provide a replacement. This is a bug in Gnulib."
  38. #endif