diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2010-12-22 17:24:33 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2010-12-22 17:24:33 +0000 |
commit | 5cc08b20970640a5dfe99bd5e2b7728ce3373982 (patch) | |
tree | 0b05c09cf190550f41284df1828fc42b3691395c /lib | |
parent | cd3d4dbd4b39216825ba347515d01ab3a180c02f (diff) |
Do not attempt to prepend /dev/ to path if it already contains a slash.
OK jsing@
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libutil/opendev.c | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/lib/libutil/opendev.c b/lib/libutil/opendev.c index 0be557b7ce1..f82d5fa9a9e 100644 --- a/lib/libutil/opendev.c +++ b/lib/libutil/opendev.c @@ -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. @@ -86,23 +86,25 @@ opendev(const char *path, int oflags, int dflags, char **realpath) 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 (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) *realpath = namebuf; |