1 /* exclude.c -- exclude file names
3 Copyright 2001 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; see the file COPYING.
17 If not, write to the Free Software Foundation,
18 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20 /* Written by Jim Meyering <jim@meyering.net> */
28 # include <sys/types.h>
38 #include "xreadlink.h"
40 /* Call readlink to get the symbolic link value of FILENAME.
41 Return a pointer to that NUL-terminated string in malloc'd storage.
42 If readlink fails, return NULL (use errno to diagnose).
43 If realloc fails, or if the link value is longer than SIZE_MAX :-),
44 give a diagnostic and exit. */
47 xreadlink (char const *filename, size_t *link_length_arg)
49 /* The initial buffer size for the link value. A power of 2
50 detects arithmetic overflow earlier, but is not required. */
51 size_t buf_size = 128;
57 buffer = (char *) xrealloc (buffer, buf_size);
58 link_length = readlink (filename, buffer, buf_size);
64 if (link_length < buf_size)
66 *link_length_arg = link_length;
67 buffer[link_length] = 0;