Blame lib/openat.h

Packit 709fb3
/* provide a replacement openat function
Packit 709fb3
   Copyright (C) 2004-2006, 2008-2017 Free Software Foundation, Inc.
Packit 709fb3
Packit 709fb3
   This program is free software: you can redistribute it and/or modify
Packit 709fb3
   it under the terms of the GNU General Public License as published by
Packit 709fb3
   the Free Software Foundation; either version 3 of the License, or
Packit 709fb3
   (at your option) any later version.
Packit 709fb3
Packit 709fb3
   This program is distributed in the hope that it will be useful,
Packit 709fb3
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 709fb3
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 709fb3
   GNU General Public License for more details.
Packit 709fb3
Packit 709fb3
   You should have received a copy of the GNU General Public License
Packit 709fb3
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
Packit 709fb3
Packit 709fb3
/* written by Jim Meyering */
Packit 709fb3
Packit 709fb3
#ifndef _GL_HEADER_OPENAT
Packit 709fb3
#define _GL_HEADER_OPENAT
Packit 709fb3
Packit 709fb3
#include <fcntl.h>
Packit 709fb3
Packit 709fb3
#include <sys/types.h>
Packit 709fb3
#include <sys/stat.h>
Packit 709fb3
#include <unistd.h>
Packit 709fb3
#include <stdbool.h>
Packit 709fb3
Packit 709fb3
#ifndef _GL_INLINE_HEADER_BEGIN
Packit 709fb3
 #error "Please include config.h first."
Packit 709fb3
#endif
Packit 709fb3
_GL_INLINE_HEADER_BEGIN
Packit 709fb3
Packit 709fb3
#if !HAVE_OPENAT
Packit 709fb3
Packit 709fb3
int openat_permissive (int fd, char const *file, int flags, mode_t mode,
Packit 709fb3
                       int *cwd_errno);
Packit 709fb3
bool openat_needs_fchdir (void);
Packit 709fb3
Packit 709fb3
#else
Packit 709fb3
Packit 709fb3
# define openat_permissive(Fd, File, Flags, Mode, Cwd_errno) \
Packit 709fb3
    openat (Fd, File, Flags, Mode)
Packit 709fb3
# define openat_needs_fchdir() false
Packit 709fb3
Packit 709fb3
#endif
Packit 709fb3
Packit 709fb3
_Noreturn void openat_restore_fail (int);
Packit 709fb3
_Noreturn void openat_save_fail (int);
Packit 709fb3
Packit 709fb3
/* Using these function names makes application code
Packit 709fb3
   slightly more readable than it would be with
Packit 709fb3
   fchownat (..., 0) or fchownat (..., AT_SYMLINK_NOFOLLOW).  */
Packit 709fb3
Packit 709fb3
#if GNULIB_FCHOWNAT
Packit 709fb3
Packit 709fb3
# ifndef FCHOWNAT_INLINE
Packit 709fb3
#  define FCHOWNAT_INLINE _GL_INLINE
Packit 709fb3
# endif
Packit 709fb3
Packit 709fb3
FCHOWNAT_INLINE int
Packit 709fb3
chownat (int fd, char const *file, uid_t owner, gid_t group)
Packit 709fb3
{
Packit 709fb3
  return fchownat (fd, file, owner, group, 0);
Packit 709fb3
}
Packit 709fb3
Packit 709fb3
FCHOWNAT_INLINE int
Packit 709fb3
lchownat (int fd, char const *file, uid_t owner, gid_t group)
Packit 709fb3
{
Packit 709fb3
  return fchownat (fd, file, owner, group, AT_SYMLINK_NOFOLLOW);
Packit 709fb3
}
Packit 709fb3
Packit 709fb3
#endif
Packit 709fb3
Packit 709fb3
#if GNULIB_FCHMODAT
Packit 709fb3
Packit 709fb3
# ifndef FCHMODAT_INLINE
Packit 709fb3
#  define FCHMODAT_INLINE _GL_INLINE
Packit 709fb3
# endif
Packit 709fb3
Packit 709fb3
FCHMODAT_INLINE int
Packit 709fb3
chmodat (int fd, char const *file, mode_t mode)
Packit 709fb3
{
Packit 709fb3
  return fchmodat (fd, file, mode, 0);
Packit 709fb3
}
Packit 709fb3
Packit 709fb3
FCHMODAT_INLINE int
Packit 709fb3
lchmodat (int fd, char const *file, mode_t mode)
Packit 709fb3
{
Packit 709fb3
  return fchmodat (fd, file, mode, AT_SYMLINK_NOFOLLOW);
Packit 709fb3
}
Packit 709fb3
Packit 709fb3
#endif
Packit 709fb3
Packit 709fb3
#if GNULIB_STATAT
Packit 709fb3
Packit 709fb3
# ifndef STATAT_INLINE
Packit 709fb3
#  define STATAT_INLINE _GL_INLINE
Packit 709fb3
# endif
Packit 709fb3
Packit 709fb3
STATAT_INLINE int
Packit 709fb3
statat (int fd, char const *name, struct stat *st)
Packit 709fb3
{
Packit 709fb3
  return fstatat (fd, name, st, 0);
Packit 709fb3
}
Packit 709fb3
Packit 709fb3
STATAT_INLINE int
Packit 709fb3
lstatat (int fd, char const *name, struct stat *st)
Packit 709fb3
{
Packit 709fb3
  return fstatat (fd, name, st, AT_SYMLINK_NOFOLLOW);
Packit 709fb3
}
Packit 709fb3
Packit 709fb3
#endif
Packit 709fb3
Packit 709fb3
/* For now, there are no wrappers named laccessat or leuidaccessat,
Packit 709fb3
   since gnulib doesn't support faccessat(,AT_SYMLINK_NOFOLLOW) and
Packit 709fb3
   since access rights on symlinks are of limited utility.  Likewise,
Packit 709fb3
   wrappers are not provided for accessat or euidaccessat, so as to
Packit 709fb3
   avoid dragging in -lgen on some platforms.  */
Packit 709fb3
Packit 709fb3
_GL_INLINE_HEADER_END
Packit 709fb3
Packit 709fb3
#endif /* _GL_HEADER_OPENAT */