1 |
/* vi: set sw=4 ts=4: */ |
/* vi: set sw=4 ts=4: */ |
2 |
/* |
/* |
3 |
* xreadlink.c - safe implementation of readlink. |
* xreadlink.c - safe implementation of readlink. |
4 |
* Returns a NULL on failure... |
* Returns a NULL on failure... |
5 |
|
* |
6 |
|
* Licensed under GPLv2, see file LICENSE in this tarball for details. |
7 |
*/ |
*/ |
8 |
|
|
9 |
#include "libbb.h" |
#include "libbb.h" |
91 |
char *buf = xmalloc_readlink(path); |
char *buf = xmalloc_readlink(path); |
92 |
if (!buf) { |
if (!buf) { |
93 |
/* EINVAL => "file: Invalid argument" => puzzled user */ |
/* EINVAL => "file: Invalid argument" => puzzled user */ |
94 |
bb_error_msg("%s: cannot read link (not a symlink?)", path); |
const char *errmsg = "not a symlink"; |
95 |
|
int err = errno; |
96 |
|
if (err != EINVAL) |
97 |
|
errmsg = strerror(err); |
98 |
|
bb_error_msg("%s: cannot read link: %s", path, errmsg); |
99 |
} |
} |
100 |
return buf; |
return buf; |
101 |
} |
} |