opendir-tst1.c 2.1 KB

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