Blame dirent/opendir-tst1.c

Packit 6c4009
/* Copyright (C) 1998-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
   Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#include <dirent.h>
Packit 6c4009
#include <errno.h>
Packit 6c4009
#include <fcntl.h>
Packit 6c4009
#include <stdio.h>
Packit 6c4009
#include <stdlib.h>
Packit 6c4009
#include <string.h>
Packit 6c4009
#include <unistd.h>
Packit 6c4009
#include <sys/stat.h>
Packit 6c4009
Packit 6c4009
/* Name of the FIFO.  */
Packit 6c4009
char tmpname[] = "fifoXXXXXX";
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Do the real work.  */
Packit 6c4009
static int
Packit 6c4009
real_test (void)
Packit 6c4009
{
Packit 6c4009
  DIR *dirp;
Packit 6c4009
Packit 6c4009
  /* This should not block for an FIFO.  */
Packit 6c4009
  dirp = opendir (tmpname);
Packit 6c4009
Packit 6c4009
  /* Successful.  */
Packit 6c4009
  if (dirp != NULL)
Packit 6c4009
    {
Packit 6c4009
      /* Oh, oh, how can this work?  */
Packit 6c4009
      fputs ("`opendir' succeeded on a FIFO???\n", stdout);
Packit 6c4009
      closedir (dirp);
Packit 6c4009
      return 1;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  if (errno != ENOTDIR)
Packit 6c4009
    {
Packit 6c4009
      fprintf (stdout, "`opendir' return error `%s' instead of `%s'\n",
Packit 6c4009
	       strerror (errno), strerror (ENOTDIR));
Packit 6c4009
      return 1;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  return 0;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
Packit 6c4009
static int
Packit 6c4009
do_test (void)
Packit 6c4009
{
Packit 6c4009
  int retval;
Packit 6c4009
Packit 6c4009
  if (mktemp (tmpname) == NULL)
Packit 6c4009
    {
Packit 6c4009
      perror ("mktemp");
Packit 6c4009
      return 1;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  /* Try to generate a FIFO.  */
Packit 6c4009
  if (mknod (tmpname, 0600 | S_IFIFO, 0) < 0)
Packit 6c4009
    {
Packit 6c4009
      perror ("mknod");
Packit 6c4009
      /* We cannot make this an error.  */
Packit 6c4009
      return 0;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  retval = real_test ();
Packit 6c4009
Packit 6c4009
  remove (tmpname);
Packit 6c4009
Packit 6c4009
  return retval;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
Packit 6c4009
static void
Packit 6c4009
do_cleanup (void)
Packit 6c4009
{
Packit 6c4009
  remove (tmpname);
Packit 6c4009
}
Packit 6c4009
#define CLEANUP_HANDLER do_cleanup
Packit 6c4009
Packit 6c4009
#include <support/test-driver.c>