diff options
author | Bruno Haible <bruno@clisp.org> | 2021-01-05 04:23:48 +0100 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2021-01-05 04:34:31 +0100 |
commit | 5e6fdcd601b83417a3f29c27fa0eb4ead053e1ea (patch) | |
tree | cfafedd46081bc4dbf7f9cde60280c4105590ba3 /lib/mkfifoat.c | |
parent | 9a6782ac052fc3b07349fb8e0c08b7d5060d403d (diff) | |
download | gnulib-5e6fdcd601b83417a3f29c27fa0eb4ead053e1ea.tar.gz |
mkfifoat: Work around trailing slash bug in mkfifoat() on AIX 7.2.
* m4/mkfifoat.m4 (gl_FUNC_MKFIFOAT): Add a test whether mkfifoat rejects
trailing slashes. Set REPLACE_MKFIFOAT if not.
* lib/sys_stat.in.h (mkfifoat): Consider REPLACE_MKFIFOAT.
* lib/mkfifoat.c: Add an overriding implementation of mkfifoat().
* m4/sys_stat_h.m4 (gl_SYS_STAT_H_DEFAULTS): Initialize
REPLACE_MKFIFOAT.
* modules/sys_stat (Makefile.am): Substitute REPLACE_MKFIFOAT.
* modules/mkfifoat (Depends-on): Add fstatat.
(configure.ac): Consider REPLACE_MKFIFOAT.
* doc/posix-functions/mkfifoat.texi: Mention the AIX bug.
Diffstat (limited to 'lib/mkfifoat.c')
-rw-r--r-- | lib/mkfifoat.c | 64 |
1 files changed, 51 insertions, 13 deletions
diff --git a/lib/mkfifoat.c b/lib/mkfifoat.c index 65c43b6424..785a1a7617 100644 --- a/lib/mkfifoat.c +++ b/lib/mkfifoat.c @@ -23,9 +23,45 @@ #include <stdlib.h> -#if !HAVE_MKFIFO +#if HAVE_MKFIFOAT # include <errno.h> +# include <fcntl.h> +# include <string.h> + +int +rpl_mkfifoat (int fd, char const *file, mode_t mode) +#undef mkfifoat +{ + /* Use the original mkfifoat(), but correct the trailing slash handling. */ + size_t len = strlen (file); + if (len && file[len - 1] == '/') + { + struct stat st; + + if (fstatat (fd, file, &st, AT_SYMLINK_NOFOLLOW) < 0) + { + if (errno == EOVERFLOW) + /* It's surely a file, not a directory. */ + errno = ENOTDIR; + } + else + { + /* It's a directory, otherwise fstatat() would have reported an error + ENOTDIR. */ + errno = EEXIST; + } + return -1; + } + + return mkfifoat (fd, file, mode); +} + +#else + +# if !HAVE_MKFIFO + +# include <errno.h> /* Mingw lacks mkfifo, so this wrapper is trivial. */ @@ -37,7 +73,7 @@ mkfifoat (int fd _GL_UNUSED, char const *path _GL_UNUSED, return -1; } -#else /* HAVE_MKFIFO */ +# else /* HAVE_MKFIFO */ /* Create a named fifo FILE relative to directory FD, with access permissions in MODE. If possible, do it without changing the @@ -45,14 +81,16 @@ mkfifoat (int fd _GL_UNUSED, char const *path _GL_UNUSED, then mkfifo/restore_cwd. If either the save_cwd or the restore_cwd fails, then give a diagnostic and exit nonzero. */ -# define AT_FUNC_NAME mkfifoat -# define AT_FUNC_F1 mkfifo -# define AT_FUNC_POST_FILE_PARAM_DECLS , mode_t mode -# define AT_FUNC_POST_FILE_ARGS , mode -# include "at-func.c" -# undef AT_FUNC_NAME -# undef AT_FUNC_F1 -# undef AT_FUNC_POST_FILE_PARAM_DECLS -# undef AT_FUNC_POST_FILE_ARGS - -#endif /* HAVE_MKFIFO */ +# define AT_FUNC_NAME mkfifoat +# define AT_FUNC_F1 mkfifo +# define AT_FUNC_POST_FILE_PARAM_DECLS , mode_t mode +# define AT_FUNC_POST_FILE_ARGS , mode +# include "at-func.c" +# undef AT_FUNC_NAME +# undef AT_FUNC_F1 +# undef AT_FUNC_POST_FILE_PARAM_DECLS +# undef AT_FUNC_POST_FILE_ARGS + +# endif /* HAVE_MKFIFO */ + +#endif /* HAVE_MKFIFOAT */ |