Blame gettext-tools/gnulib-lib/xreadlink.c

Packit Bot 06c835
/* xreadlink.c -- readlink wrapper to return the link name in malloc'd storage
Packit Bot 06c835
Packit Bot 06c835
   Copyright (C) 2001, 2003-2007, 2009-2015 Free Software Foundation, Inc.
Packit Bot 06c835
Packit Bot 06c835
   This program is free software: you can redistribute it and/or modify
Packit Bot 06c835
   it under the terms of the GNU General Public License as published by
Packit Bot 06c835
   the Free Software Foundation; either version 3 of the License, or
Packit Bot 06c835
   (at your option) any later version.
Packit Bot 06c835
Packit Bot 06c835
   This program is distributed in the hope that it will be useful,
Packit Bot 06c835
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Bot 06c835
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Bot 06c835
   GNU General Public License for more details.
Packit Bot 06c835
Packit Bot 06c835
   You should have received a copy of the GNU General Public License
Packit Bot 06c835
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
Packit Bot 06c835
Packit Bot 06c835
/* Written by Jim Meyering <jim@meyering.net>
Packit Bot 06c835
   and Bruno Haible <bruno@clisp.org>.  */
Packit Bot 06c835
Packit Bot 06c835
#include <config.h>
Packit Bot 06c835
Packit Bot 06c835
/* Specification.  */
Packit Bot 06c835
#include "xreadlink.h"
Packit Bot 06c835
Packit Bot 06c835
#include <errno.h>
Packit Bot 06c835
Packit Bot 06c835
#include "areadlink.h"
Packit Bot 06c835
#include "xalloc.h"
Packit Bot 06c835
Packit Bot 06c835
/* Call readlink to get the symbolic link value of FILENAME.
Packit Bot 06c835
   Return a pointer to that NUL-terminated string in malloc'd storage.
Packit Bot 06c835
   If readlink fails, return NULL and set errno.
Packit Bot 06c835
   If realloc fails, or if the link value is longer than SIZE_MAX :-),
Packit Bot 06c835
   give a diagnostic and exit.  */
Packit Bot 06c835
Packit Bot 06c835
char *
Packit Bot 06c835
xreadlink (char const *filename)
Packit Bot 06c835
{
Packit Bot 06c835
  char *result = areadlink (filename);
Packit Bot 06c835
  if (result == NULL && errno == ENOMEM)
Packit Bot 06c835
    xalloc_die ();
Packit Bot 06c835
  return result;
Packit Bot 06c835
}