diff options
author | наб <[email protected]> | 2021-05-20 22:45:08 +0200 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2021-05-26 14:50:35 -0700 |
commit | 2fdd61a30b517498f766b5a7d9eec6182c32cd72 (patch) | |
tree | 34aa8fd7741d4174ad7cb5d7c6bbab6bf978ef38 /lib/libzutil | |
parent | a0cb347ceac4840e988fc6148db21bffbf80cb68 (diff) |
libzutil: zfs_strcmp_pathname: don't allocate, remove strtok
Reviewed-by: Brian Behlendorf <[email protected]>
Reviewed-by: John Kennedy <[email protected]>
Signed-off-by: Ahelenia Ziemiańska <[email protected]>
Closes #12094
Diffstat (limited to 'lib/libzutil')
-rw-r--r-- | lib/libzutil/zutil_device_path.c | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/lib/libzutil/zutil_device_path.c b/lib/libzutil/zutil_device_path.c index 27ca80e50..be8d02673 100644 --- a/lib/libzutil/zutil_device_path.c +++ b/lib/libzutil/zutil_device_path.c @@ -141,18 +141,17 @@ zfs_strcmp_pathname(const char *name, const char *cmp, int wholedisk) int path_len, cmp_len; char path_name[MAXPATHLEN]; char cmp_name[MAXPATHLEN]; - char *dir, *dup; - - /* Strip redundant slashes if one exists due to ZPOOL_IMPORT_PATH */ - memset(cmp_name, 0, MAXPATHLEN); - dup = strdup(cmp); - dir = strtok(dup, "/"); - while (dir) { + char *dir, *tmp = NULL; + + /* Strip redundant slashes if they exist due to ZPOOL_IMPORT_PATH */ + cmp_name[0] = '\0'; + (void) strlcpy(path_name, cmp, sizeof (path_name)); + for (dir = strtok_r(path_name, "/", &tmp); + dir != NULL; + dir = strtok_r(NULL, "/", &tmp)) { strlcat(cmp_name, "/", sizeof (cmp_name)); strlcat(cmp_name, dir, sizeof (cmp_name)); - dir = strtok(NULL, "/"); } - free(dup); if (name[0] != '/') return (zfs_strcmp_shortname(name, cmp_name, wholedisk)); |