Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libutil Resolve symlinks and cook the targets instead of...
details: https://anonhg.NetBSD.org/src/rev/a54646f7b5ac
branches: trunk
changeset: 325392:a54646f7b5ac
user: mlelstv <mlelstv%NetBSD.org@localhost>
date: Sun Dec 22 14:31:51 2013 +0000
description:
Resolve symlinks and cook the targets instead of the symlink names.
diffstat:
lib/libutil/getdiskrawname.c | 22 ++++++++++++++++++++--
1 files changed, 20 insertions(+), 2 deletions(-)
diffs (78 lines):
diff -r 5e4645d3a20a -r a54646f7b5ac lib/libutil/getdiskrawname.c
--- a/lib/libutil/getdiskrawname.c Sun Dec 22 11:36:12 2013 +0000
+++ b/lib/libutil/getdiskrawname.c Sun Dec 22 14:31:51 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: getdiskrawname.c,v 1.1 2012/04/07 16:44:39 christos Exp $ */
+/* $NetBSD: getdiskrawname.c,v 1.2 2013/12/22 14:31:51 mlelstv Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: getdiskrawname.c,v 1.1 2012/04/07 16:44:39 christos Exp $");
+__RCSID("$NetBSD: getdiskrawname.c,v 1.2 2013/12/22 14:31:51 mlelstv Exp $");
#include <sys/stat.h>
@@ -37,18 +37,26 @@
#include <string.h>
#include <errno.h>
#include <util.h>
+#include <unistd.h>
const char *
getdiskrawname(char *buf, size_t bufsiz, const char *name)
{
const char *dp = strrchr(name, '/');
struct stat st;
+ ssize_t len;
if (dp == NULL) {
errno = EINVAL;
return NULL;
}
+ len = readlink(name, buf, bufsiz-1);
+ if (len > 0) {
+ buf[len] = '\0';
+ name = buf;
+ }
+
if (stat(name, &st) == -1)
return NULL;
@@ -67,11 +75,19 @@
{
const char *dp;
struct stat st;
+ ssize_t len;
if ((dp = strrchr(name, '/')) == NULL) {
errno = EINVAL;
return NULL;
}
+
+ len = readlink(name, buf, bufsiz-1);
+ if (len > 0) {
+ buf[len] = '\0';
+ name = buf;
+ }
+
if (stat(name, &st) == -1)
return NULL;
@@ -79,10 +95,12 @@
errno = EFTYPE;
return NULL;
}
+
if (dp[1] != 'r') {
errno = EINVAL;
return NULL;
}
+
(void)snprintf(buf, bufsiz, "%.*s/%s", (int)(dp - name), name, dp + 2);
return buf;
Home |
Main Index |
Thread Index |
Old Index