1 /* Test that values of pathconf and fpathconf are consistent for a file.
2 Copyright (C) 2013-2021 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
27 static void prepare (void);
28 #define PREPARE(argc, argv) prepare ()
30 static int do_test (void);
31 #define TEST_FUNCTION do_test ()
33 #include "../test-skeleton.c"
41 size_t test_dir_len
= strlen (test_dir
);
42 static const char dir_name
[] = "/tst-pathconf.XXXXXX";
44 size_t dirbuflen
= test_dir_len
+ sizeof (dir_name
);
45 dirbuf
= xmalloc (dirbuflen
);
47 snprintf (dirbuf
, dirbuflen
, "%s%s", test_dir
, dir_name
);
48 if (mkdtemp (dirbuf
) == NULL
)
50 printf ("Cannot create temporary directory: %s\n", strerror (errno
));
54 add_temp_file (dirbuf
);
56 dir_fd
= open (dirbuf
, O_RDONLY
);
59 printf ("Cannot open directory: %s\n", strerror (errno
));
69 static const char *fifo_name
= "some-fifo";
71 size_t filenamelen
= strlen (dirbuf
) + strlen (fifo_name
) + 2;
72 char *filename
= xmalloc (filenamelen
);
74 snprintf (filename
, filenamelen
, "%s/%s", dirbuf
, fifo_name
);
76 /* Create a fifo in the directory. */
77 int e
= mkfifo (filename
, 0777);
80 printf ("fifo creation failed (%s)\n", strerror (errno
));
85 long dir_pathconf
= pathconf (dirbuf
, _PC_PIPE_BUF
);
89 printf ("pathconf on directory failed: %s\n", strerror (errno
));
94 long fifo_pathconf
= pathconf (filename
, _PC_PIPE_BUF
);
96 if (fifo_pathconf
< 0)
98 printf ("pathconf on file failed: %s\n", strerror (errno
));
103 int fifo
= open (filename
, O_RDONLY
| O_NONBLOCK
);
107 printf ("fifo open failed (%s)\n", strerror (errno
));
112 long dir_fpathconf
= fpathconf (dir_fd
, _PC_PIPE_BUF
);
114 if (dir_fpathconf
< 0)
116 printf ("fpathconf on directory failed: %s\n", strerror (errno
));
121 long fifo_fpathconf
= fpathconf (fifo
, _PC_PIPE_BUF
);
123 if (fifo_fpathconf
< 0)
125 printf ("fpathconf on file failed: %s\n", strerror (errno
));
130 if (fifo_pathconf
!= fifo_fpathconf
)
132 printf ("fifo pathconf (%ld) != fifo fpathconf (%ld)\n", fifo_pathconf
,
138 if (dir_pathconf
!= fifo_pathconf
)
140 printf ("directory pathconf (%ld) != fifo pathconf (%ld)\n",
141 dir_pathconf
, fifo_pathconf
);
146 if (dir_fpathconf
!= fifo_fpathconf
)
148 printf ("directory fpathconf (%ld) != fifo fpathconf (%ld)\n",
149 dir_fpathconf
, fifo_fpathconf
);
159 if (unlink (filename
) != 0)
161 printf ("Could not remove fifo (%s)\n", strerror (errno
));