Blame lib/openat-priv.h

Packit 709fb3
/* Internals for openat-like functions.
Packit 709fb3
Packit 709fb3
   Copyright (C) 2005-2006, 2009-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_PRIV
Packit 709fb3
#define _GL_HEADER_OPENAT_PRIV
Packit 709fb3
Packit 709fb3
#include <errno.h>
Packit 709fb3
#include <limits.h>
Packit 709fb3
#include <stdlib.h>
Packit 709fb3
Packit 709fb3
/* Maximum number of bytes that it is safe to allocate as a single
Packit 709fb3
   array on the stack, and that is known as a compile-time constant.
Packit 709fb3
   The assumption is that we'll touch the array very quickly, or a
Packit 709fb3
   temporary very near the array, provoking an out-of-memory trap.  On
Packit 709fb3
   some operating systems, there is only one guard page for the stack,
Packit 709fb3
   and a page size can be as small as 4096 bytes.  Subtract 64 in the
Packit 709fb3
   hope that this will let the compiler touch a nearby temporary and
Packit 709fb3
   provoke a trap.  */
Packit 709fb3
#define SAFER_ALLOCA_MAX (4096 - 64)
Packit 709fb3
Packit 709fb3
#define SAFER_ALLOCA(m) ((m) < SAFER_ALLOCA_MAX ? (m) : SAFER_ALLOCA_MAX)
Packit 709fb3
Packit 709fb3
#if defined PATH_MAX
Packit 709fb3
# define OPENAT_BUFFER_SIZE SAFER_ALLOCA (PATH_MAX)
Packit 709fb3
#elif defined _XOPEN_PATH_MAX
Packit 709fb3
# define OPENAT_BUFFER_SIZE SAFER_ALLOCA (_XOPEN_PATH_MAX)
Packit 709fb3
#else
Packit 709fb3
# define OPENAT_BUFFER_SIZE SAFER_ALLOCA (1024)
Packit 709fb3
#endif
Packit 709fb3
Packit 709fb3
char *openat_proc_name (char buf[OPENAT_BUFFER_SIZE], int fd, char const *file);
Packit 709fb3
Packit 709fb3
/* Trying to access a BUILD_PROC_NAME file will fail on systems without
Packit 709fb3
   /proc support, and even on systems *with* ProcFS support.  Return
Packit 709fb3
   nonzero if the failure may be legitimate, e.g., because /proc is not
Packit 709fb3
   readable, or the particular .../fd/N directory is not present.  */
Packit 709fb3
#define EXPECTED_ERRNO(Errno)                   \
Packit 709fb3
  ((Errno) == ENOTDIR || (Errno) == ENOENT      \
Packit 709fb3
   || (Errno) == EPERM || (Errno) == EACCES     \
Packit 709fb3
   || (Errno) == ENOSYS /* Solaris 8 */         \
Packit 709fb3
   || (Errno) == EOPNOTSUPP /* FreeBSD */)
Packit 709fb3
Packit 709fb3
/* Wrapper function shared among linkat and renameat.  */
Packit 709fb3
int at_func2 (int fd1, char const *file1,
Packit 709fb3
              int fd2, char const *file2,
Packit 709fb3
              int (*func) (char const *file1, char const *file2));
Packit 709fb3
Packit 709fb3
#endif /* _GL_HEADER_OPENAT_PRIV */