Annotation of embedaddon/libiconv/srclib/areadlink.c, revision 1.1.1.3

1.1       misho       1: /* areadlink.c -- readlink wrapper to return the link name in malloc'd storage
                      2:    Unlike xreadlink and xreadlink_with_size, don't ever call exit.
                      3: 
1.1.1.3 ! misho       4:    Copyright (C) 2001, 2003-2007, 2009-2019 Free Software Foundation, Inc.
1.1       misho       5: 
                      6:    This program is free software: you can redistribute it and/or modify
                      7:    it under the terms of the GNU General Public License as published by
                      8:    the Free Software Foundation; either version 3 of the License, or
                      9:    (at your option) any later version.
                     10: 
                     11:    This program is distributed in the hope that it will be useful,
                     12:    but WITHOUT ANY WARRANTY; without even the implied warranty of
                     13:    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     14:    GNU General Public License for more details.
                     15: 
                     16:    You should have received a copy of the GNU General Public License
1.1.1.3 ! misho      17:    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
1.1       misho      18: 
                     19: /* Written by Jim Meyering <jim@meyering.net>
                     20:    and Bruno Haible <bruno@clisp.org>.  */
                     21: 
                     22: #include <config.h>
                     23: 
                     24: /* Specification.  */
                     25: #include "areadlink.h"
                     26: 
1.1.1.2   misho      27: #include "careadlinkat.h"
1.1       misho      28: 
1.1.1.3 ! misho      29: #include <stdlib.h>
        !            30: #include <unistd.h>
        !            31: 
        !            32: /* Get the symbolic link value of FILENAME and put it into BUFFER, with
        !            33:    size BUFFER_SIZE.  This function acts like readlink but has
        !            34:    readlinkat's signature.  */
        !            35: static ssize_t
        !            36: careadlinkatcwd (int fd, char const *filename, char *buffer,
        !            37:                  size_t buffer_size)
        !            38: {
        !            39:   /* FD must be AT_FDCWD here, otherwise the caller is using this
        !            40:      function in contexts it was not meant for.  */
        !            41:   if (fd != AT_FDCWD)
        !            42:     abort ();
        !            43:   return readlink (filename, buffer, buffer_size);
        !            44: }
        !            45: 
1.1       misho      46: /* Call readlink to get the symbolic link value of FILENAME.
                     47:    Return a pointer to that NUL-terminated string in malloc'd storage.
                     48:    If readlink fails, return NULL and set errno.
1.1.1.2   misho      49:    If allocation fails, or if the link value is longer than SIZE_MAX :-),
1.1       misho      50:    return NULL and set errno to ENOMEM.  */
                     51: 
                     52: char *
                     53: areadlink (char const *filename)
                     54: {
1.1.1.2   misho      55:   return careadlinkat (AT_FDCWD, filename, NULL, 0, NULL, careadlinkatcwd);
1.1       misho      56: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>