Blame lib/openat-priv.h

Packit Service 2723c6
/* Internals for openat-like functions.
Packit Service 2723c6
Packit Service 2723c6
   Copyright (C) 2005-2006, 2009-2018 Free Software Foundation, Inc.
Packit Service 2723c6
Packit Service 2723c6
   This program is free software: you can redistribute it and/or modify
Packit Service 2723c6
   it under the terms of the GNU General Public License as published by
Packit Service 2723c6
   the Free Software Foundation; either version 3 of the License, or
Packit Service 2723c6
   (at your option) any later version.
Packit Service 2723c6
Packit Service 2723c6
   This program is distributed in the hope that it will be useful,
Packit Service 2723c6
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 2723c6
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service 2723c6
   GNU General Public License for more details.
Packit Service 2723c6
Packit Service 2723c6
   You should have received a copy of the GNU General Public License
Packit Service 2723c6
   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
Packit Service 2723c6
Packit Service 2723c6
/* written by Jim Meyering */
Packit Service 2723c6
Packit Service 2723c6
#ifndef _GL_HEADER_OPENAT_PRIV
Packit Service 2723c6
#define _GL_HEADER_OPENAT_PRIV
Packit Service 2723c6
Packit Service 2723c6
#include <errno.h>
Packit Service 2723c6
#include <limits.h>
Packit Service 2723c6
#include <stdlib.h>
Packit Service 2723c6
Packit Service 2723c6
/* Maximum number of bytes that it is safe to allocate as a single
Packit Service 2723c6
   array on the stack, and that is known as a compile-time constant.
Packit Service 2723c6
   The assumption is that we'll touch the array very quickly, or a
Packit Service 2723c6
   temporary very near the array, provoking an out-of-memory trap.  On
Packit Service 2723c6
   some operating systems, there is only one guard page for the stack,
Packit Service 2723c6
   and a page size can be as small as 4096 bytes.  Subtract 64 in the
Packit Service 2723c6
   hope that this will let the compiler touch a nearby temporary and
Packit Service 2723c6
   provoke a trap.  */
Packit Service 2723c6
#define SAFER_ALLOCA_MAX (4096 - 64)
Packit Service 2723c6
Packit Service 2723c6
#define SAFER_ALLOCA(m) ((m) < SAFER_ALLOCA_MAX ? (m) : SAFER_ALLOCA_MAX)
Packit Service 2723c6
Packit Service 2723c6
#if defined PATH_MAX
Packit Service 2723c6
# define OPENAT_BUFFER_SIZE SAFER_ALLOCA (PATH_MAX)
Packit Service 2723c6
#elif defined _XOPEN_PATH_MAX
Packit Service 2723c6
# define OPENAT_BUFFER_SIZE SAFER_ALLOCA (_XOPEN_PATH_MAX)
Packit Service 2723c6
#else
Packit Service 2723c6
# define OPENAT_BUFFER_SIZE SAFER_ALLOCA (1024)
Packit Service 2723c6
#endif
Packit Service 2723c6
Packit Service 2723c6
char *openat_proc_name (char buf[OPENAT_BUFFER_SIZE], int fd, char const *file);
Packit Service 2723c6
Packit Service 2723c6
/* Trying to access a BUILD_PROC_NAME file will fail on systems without
Packit Service 2723c6
   /proc support, and even on systems *with* ProcFS support.  Return
Packit Service 2723c6
   nonzero if the failure may be legitimate, e.g., because /proc is not
Packit Service 2723c6
   readable, or the particular .../fd/N directory is not present.  */
Packit Service 2723c6
#define EXPECTED_ERRNO(Errno)                   \
Packit Service 2723c6
  ((Errno) == ENOTDIR || (Errno) == ENOENT      \
Packit Service 2723c6
   || (Errno) == EPERM || (Errno) == EACCES     \
Packit Service 2723c6
   || (Errno) == ENOSYS /* Solaris 8 */         \
Packit Service 2723c6
   || (Errno) == EOPNOTSUPP /* FreeBSD */)
Packit Service 2723c6
Packit Service 2723c6
/* Wrapper function shared among linkat and renameat.  */
Packit Service 2723c6
int at_func2 (int fd1, char const *file1,
Packit Service 2723c6
              int fd2, char const *file2,
Packit Service 2723c6
              int (*func) (char const *file1, char const *file2));
Packit Service 2723c6
Packit Service 2723c6
#endif /* _GL_HEADER_OPENAT_PRIV */