opendir-tst1.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* Copyright (C) 1998-2026 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library 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 GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <https://www.gnu.org/licenses/>. */
  14. #include <dirent.h>
  15. #include <errno.h>
  16. #include <fcntl.h>
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20. #include <unistd.h>
  21. #include <sys/stat.h>
  22. /* Name of the FIFO. */
  23. char tmpname[] = "fifoXXXXXX";
  24. /* Do the real work. */
  25. static int
  26. real_test (void)
  27. {
  28. DIR *dirp;
  29. /* This should not block for an FIFO. */
  30. dirp = opendir (tmpname);
  31. /* Successful. */
  32. if (dirp != NULL)
  33. {
  34. /* Oh, oh, how can this work? */
  35. fputs ("`opendir' succeeded on a FIFO???\n", stdout);
  36. closedir (dirp);
  37. return 1;
  38. }
  39. if (errno != ENOTDIR)
  40. {
  41. fprintf (stdout, "`opendir' return error `%s' instead of `%s'\n",
  42. strerror (errno), strerror (ENOTDIR));
  43. return 1;
  44. }
  45. return 0;
  46. }
  47. static int
  48. do_test (void)
  49. {
  50. int retval;
  51. if (mktemp (tmpname) == NULL)
  52. {
  53. perror ("mktemp");
  54. return 1;
  55. }
  56. /* Try to generate a FIFO. */
  57. if (mknod (tmpname, 0600 | S_IFIFO, 0) < 0)
  58. {
  59. perror ("mknod");
  60. /* We cannot make this an error. */
  61. return 0;
  62. }
  63. retval = real_test ();
  64. remove (tmpname);
  65. return retval;
  66. }
  67. static void
  68. do_cleanup (void)
  69. {
  70. remove (tmpname);
  71. }
  72. #define CLEANUP_HANDLER do_cleanup
  73. #include <support/test-driver.c>