Blame lib/careadlinkat.h

Packit 33f14e
/* Read symbolic links into a buffer without size limitation, relative to fd.
Packit 33f14e
Packit 33f14e
   Copyright (C) 2011-2017 Free Software Foundation, Inc.
Packit 33f14e
Packit 33f14e
   This program is free software: you can redistribute it and/or modify
Packit 33f14e
   it under the terms of the GNU General Public License as published by
Packit 33f14e
   the Free Software Foundation; either version 3 of the License, or
Packit 33f14e
   (at your option) any later version.
Packit 33f14e
Packit 33f14e
   This program is distributed in the hope that it will be useful,
Packit 33f14e
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 33f14e
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 33f14e
   GNU General Public License for more details.
Packit 33f14e
Packit 33f14e
   You should have received a copy of the GNU General Public License
Packit 33f14e
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
Packit 33f14e
Packit 33f14e
/* Written by Paul Eggert, Bruno Haible, and Jim Meyering.  */
Packit 33f14e
Packit 33f14e
#ifndef _GL_CAREADLINKAT_H
Packit 33f14e
#define _GL_CAREADLINKAT_H
Packit 33f14e
Packit 33f14e
#include <fcntl.h>
Packit 33f14e
#include <unistd.h>
Packit 33f14e
Packit 33f14e
struct allocator;
Packit 33f14e
Packit 33f14e
/* Assuming the current directory is FD, get the symbolic link value
Packit 33f14e
   of FILENAME as a null-terminated string and put it into a buffer.
Packit 33f14e
   If FD is AT_FDCWD, FILENAME is interpreted relative to the current
Packit 33f14e
   working directory, as in openat.
Packit 33f14e
Packit 33f14e
   If the link is small enough to fit into BUFFER put it there.
Packit 33f14e
   BUFFER's size is BUFFER_SIZE, and BUFFER can be null
Packit 33f14e
   if BUFFER_SIZE is zero.
Packit 33f14e
Packit 33f14e
   If the link is not small, put it into a dynamically allocated
Packit 33f14e
   buffer managed by ALLOC.  It is the caller's responsibility to free
Packit 33f14e
   the returned value if it is nonnull and is not BUFFER.
Packit 33f14e
Packit 33f14e
   The PREADLINKAT function specifies how to read links.  It operates
Packit 33f14e
   like POSIX readlinkat()
Packit 33f14e
   <http://pubs.opengroup.org/onlinepubs/9699919799/functions/readlink.html>
Packit 33f14e
   but can assume that its first argument is the same as FD.
Packit 33f14e
Packit 33f14e
   If successful, return the buffer address; otherwise return NULL and
Packit 33f14e
   set errno.  */
Packit 33f14e
Packit 33f14e
char *careadlinkat (int fd, char const *filename,
Packit 33f14e
                    char *buffer, size_t buffer_size,
Packit 33f14e
                    struct allocator const *alloc,
Packit 33f14e
                    ssize_t (*preadlinkat) (int, char const *,
Packit 33f14e
                                            char *, size_t));
Packit 33f14e
Packit 33f14e
/* Suitable value for careadlinkat's FD argument.  */
Packit 33f14e
#if HAVE_READLINKAT
Packit 33f14e
/* AT_FDCWD is declared in <fcntl.h>.  */
Packit 33f14e
#else
Packit 33f14e
/* Define AT_FDCWD independently, so that the careadlinkat module does
Packit 33f14e
   not depend on the fcntl-h module.  We might as well use the same value
Packit 33f14e
   as fcntl-h.  */
Packit 33f14e
# ifndef AT_FDCWD
Packit 33f14e
#  define AT_FDCWD (-3041965)
Packit 33f14e
# endif
Packit 33f14e
#endif
Packit 33f14e
Packit 33f14e
#endif /* _GL_CAREADLINKAT_H */