pipe.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /* Create a pipe.
  2. Copyright (C) 2009-2023 Free Software Foundation, Inc.
  3. This file is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Lesser General Public License as
  5. published by the Free Software Foundation; either version 2.1 of the
  6. License, or (at your option) any later version.
  7. This file 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 Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License
  12. along 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