mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2025-05-03 23:42:43 +03:00
libzutil: zfs_strcmp_pathname: don't allocate, remove strtok
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: John Kennedy <john.kennedy@delphix.com> Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz> Closes #12094
This commit is contained in:
parent
a0cb347cea
commit
2fdd61a30b
@ -141,18 +141,17 @@ zfs_strcmp_pathname(const char *name, const char *cmp, int wholedisk)
|
|||||||
int path_len, cmp_len;
|
int path_len, cmp_len;
|
||||||
char path_name[MAXPATHLEN];
|
char path_name[MAXPATHLEN];
|
||||||
char cmp_name[MAXPATHLEN];
|
char cmp_name[MAXPATHLEN];
|
||||||
char *dir, *dup;
|
char *dir, *tmp = NULL;
|
||||||
|
|
||||||
/* Strip redundant slashes if one exists due to ZPOOL_IMPORT_PATH */
|
/* Strip redundant slashes if they exist due to ZPOOL_IMPORT_PATH */
|
||||||
memset(cmp_name, 0, MAXPATHLEN);
|
cmp_name[0] = '\0';
|
||||||
dup = strdup(cmp);
|
(void) strlcpy(path_name, cmp, sizeof (path_name));
|
||||||
dir = strtok(dup, "/");
|
for (dir = strtok_r(path_name, "/", &tmp);
|
||||||
while (dir) {
|
dir != NULL;
|
||||||
|
dir = strtok_r(NULL, "/", &tmp)) {
|
||||||
strlcat(cmp_name, "/", sizeof (cmp_name));
|
strlcat(cmp_name, "/", sizeof (cmp_name));
|
||||||
strlcat(cmp_name, dir, sizeof (cmp_name));
|
strlcat(cmp_name, dir, sizeof (cmp_name));
|
||||||
dir = strtok(NULL, "/");
|
|
||||||
}
|
}
|
||||||
free(dup);
|
|
||||||
|
|
||||||
if (name[0] != '/')
|
if (name[0] != '/')
|
||||||
return (zfs_strcmp_shortname(name, cmp_name, wholedisk));
|
return (zfs_strcmp_shortname(name, cmp_name, wholedisk));
|
||||||
|
Loading…
Reference in New Issue
Block a user