root/maint/gnulib/tests/test-mkfifo.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. test_mkfifo

   1 /* Tests of mkfifo and friends.
   2    Copyright (C) 2009-2021 Free Software Foundation, Inc.
   3 
   4    This program is free software: you can redistribute it and/or modify
   5    it under the terms of the GNU General Public License as published by
   6    the Free Software Foundation; either version 3 of the License, or
   7    (at your option) any later version.
   8 
   9    This program is distributed in the hope that it will be useful,
  10    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12    GNU General Public License for more details.
  13 
  14    You should have received a copy of the GNU General Public License
  15    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
  16 
  17 /* Written by Eric Blake <ebb9@byu.net>, 2009.  */
  18 
  19 /* This file is designed to test mkfifo(n,m), mknod(n,m|S_IFIFO,0),
  20    mkfifoat(AT_FDCWD,n,m), and mknodat(AT_FDCWD,n,m|S_IFIFO,0).  FUNC
  21    is the function to test.  Assumes that BASE and ASSERT are already
  22    defined, and that appropriate headers are already included.  If
  23    PRINT, warn before skipping symlink tests with status 77.  */
  24 
  25 static int
  26 test_mkfifo (int (*func) (char const *, mode_t), bool print)
     /* [previous][next][first][last][top][bottom][index][help] */
  27 {
  28   int result = func (BASE "fifo", 0600);
  29   struct stat st;
  30   if (result == -1 && errno == ENOSYS)
  31     {
  32       if (print)
  33         fputs ("skipping test: no support for named fifos\n", stderr);
  34       return 77;
  35     }
  36   ASSERT (result == 0);
  37   ASSERT (stat (BASE "fifo", &st) == 0);
  38   ASSERT (S_ISFIFO (st.st_mode));
  39 
  40   /* Sanity checks of failures.  */
  41   errno = 0;
  42   ASSERT (func ("", S_IRUSR | S_IWUSR) == -1);
  43   ASSERT (errno == ENOENT);
  44   errno = 0;
  45   ASSERT (func (".", 0600) == -1);
  46   /* Allow HP-UX 11.11's EISDIR, even though POSIX says it's wrong,
  47      since it doesn't really hurt anything and we lack the energy to
  48      fix it.  */
  49   ASSERT (errno == EEXIST || errno == EINVAL || errno == EISDIR);
  50   errno = 0;
  51   ASSERT (func (BASE "fifo", 0600) == -1);
  52   ASSERT (errno == EEXIST);
  53   ASSERT (unlink (BASE "fifo") == 0);
  54   errno = 0;
  55   ASSERT (func (BASE "fifo/", 0600) == -1);
  56   ASSERT (errno == ENOENT || errno == ENOTDIR);
  57 
  58   /* Test trailing slash behavior.  */
  59   if (symlink (BASE "fifo", BASE "link"))
  60     {
  61       if (print)
  62         fputs ("skipping test: symlinks not supported on this file system\n",
  63                stderr);
  64       return 77;
  65     }
  66   errno = 0;
  67   ASSERT (func (BASE "link", 0600) == -1);
  68   ASSERT (errno == EEXIST);
  69   errno = 0;
  70   ASSERT (func (BASE "link/", 0600) == -1);
  71   ASSERT (errno == EEXIST || errno == ENOENT || errno == ENOTDIR);
  72   errno = 0;
  73   ASSERT (unlink (BASE "fifo") == -1);
  74   ASSERT (errno == ENOENT);
  75   ASSERT (unlink (BASE "link") == 0);
  76   return 0;
  77 }

/* [previous][next][first][last][top][bottom][index][help] */