Back to index

glibc  2.9
opendir-tst1.c
Go to the documentation of this file.
00001 /* Copyright (C) 1998, 2000 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <dirent.h>
00021 #include <errno.h>
00022 #include <fcntl.h>
00023 #include <stdio.h>
00024 #include <stdlib.h>
00025 #include <string.h>
00026 #include <unistd.h>
00027 
00028 /* Name of the FIFO.  */
00029 char tmpname[] = "fifoXXXXXX";
00030 
00031 
00032 /* Do the real work.  */
00033 static int
00034 real_test (void)
00035 {
00036   DIR *dirp;
00037 
00038   /* This should not block for an FIFO.  */
00039   dirp = opendir (tmpname);
00040 
00041   /* Successful.  */
00042   if (dirp != NULL)
00043     {
00044       /* Oh, oh, how can this work?  */
00045       fputs ("`opendir' succeeded on a FIFO???\n", stdout);
00046       closedir (dirp);
00047       return 1;
00048     }
00049 
00050   if (errno != ENOTDIR)
00051     {
00052       fprintf (stdout, "`opendir' return error `%s' instead of `%s'\n",
00053               strerror (errno), strerror (ENOTDIR));
00054       return 1;
00055     }
00056 
00057   return 0;
00058 }
00059 
00060 
00061 static int
00062 do_test (int argc, char *argv[])
00063 {
00064   int retval;
00065 
00066   if (mktemp (tmpname) == NULL)
00067     {
00068       perror ("mktemp");
00069       return 1;
00070     }
00071 
00072   /* Try to generate a FIFO.  */
00073   if (mknod (tmpname, 0600 | S_IFIFO, 0) < 0)
00074     {
00075       perror ("mknod");
00076       /* We cannot make this an error.  */
00077       return 0;
00078     }
00079 
00080   retval = real_test ();
00081 
00082   remove (tmpname);
00083 
00084   return retval;
00085 }
00086 
00087 
00088 static void
00089 do_cleanup (void)
00090 {
00091   remove (tmpname);
00092 }
00093 #define CLEANUP_HANDLER do_cleanup ()
00094 
00095 
00096 /* Include the test skeleton.  */
00097 #include <test-skeleton.c>