Browse Source

Do not attempt to prepend /dev/ to path if it already contains a slash.

OK jsing@
OPENBSD_4_9
millert 14 years ago
parent
commit
58a7be37c3
1 changed files with 19 additions and 17 deletions
  1. +19
    -17
      src/lib/libutil/opendev.c

+ 19
- 17
src/lib/libutil/opendev.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: opendev.c,v 1.13 2010/12/21 15:47:52 millert Exp $ */
/* $OpenBSD: opendev.c,v 1.14 2010/12/22 17:24:32 millert Exp $ */
/* /*
* Copyright (c) 2000, Todd C. Miller. All rights reserved. * Copyright (c) 2000, Todd C. Miller. All rights reserved.
@ -86,23 +86,25 @@ opendev(const char *path, int oflags, int dflags, char **realpath)
return -1; return -1;
} }
} }
if (fd == -1 && errno == ENOENT && (dflags & OPENDEV_PART)) {
/*
* First try raw partition (for removable drives)
*/
if (snprintf(namebuf, sizeof(namebuf), "%s%s%s%c",
_PATH_DEV, prefix, path, 'a' + getrawpartition())
< sizeof(namebuf)) {
fd = open(namebuf, oflags);
} else
errno = ENAMETOOLONG;
}
if (!slash && fd == -1 && errno == ENOENT) { if (!slash && fd == -1 && errno == ENOENT) {
if (snprintf(namebuf, sizeof(namebuf), "%s%s%s",
_PATH_DEV, prefix, path) < sizeof(namebuf)) {
fd = open(namebuf, oflags);
} else
errno = ENAMETOOLONG;
if (dflags & OPENDEV_PART) {
/*
* First try raw partition (for removable drives)
*/
if (snprintf(namebuf, sizeof(namebuf), "%s%s%s%c",
_PATH_DEV, prefix, path, 'a' + getrawpartition())
< sizeof(namebuf)) {
fd = open(namebuf, oflags);
} else
errno = ENAMETOOLONG;
}
if (fd == -1 && errno == ENOENT) {
if (snprintf(namebuf, sizeof(namebuf), "%s%s%s",
_PATH_DEV, prefix, path) < sizeof(namebuf)) {
fd = open(namebuf, oflags);
} else
errno = ENAMETOOLONG;
}
} }
if (realpath) if (realpath)
*realpath = namebuf; *realpath = namebuf;


Loading…
Cancel
Save