*
* Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
*
- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
+ * Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
#include "libbb.h"
char *retpath = NULL;
int len, rem;
- dir = opendir(ap->devpath);
- if (!dir)
- return NULL;
-
len = strlen(ap->devpath);
rem = DEVNAME_MAX-2 - len;
if (rem <= 0)
return NULL;
+
+ dir = opendir(ap->devpath);
+ if (!dir)
+ return NULL;
+
ap->devpath[len++] = '/';
while ((entry = readdir(dir)) != NULL) {
safe_strncpy(ap->devpath + len, entry->d_name, rem);
- if (stat(ap->devpath, &ap->st) != 0)
+ /* lstat: do not follow links */
+ if (lstat(ap->devpath, &ap->st) != 0)
continue;
if (S_ISBLK(ap->st.st_mode) && ap->st.st_rdev == ap->dev) {
retpath = xstrdup(ap->devpath);
return retpath;
}
-char *find_block_device(const char *path)
+char* FAST_FUNC find_block_device(const char *path)
{
struct arena a;