summaryrefslogtreecommitdiff
path: root/utils.c
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.cz>2015-06-12 16:09:33 +0200
committerDavid Sterba <dsterba@suse.cz>2015-06-12 16:44:48 +0200
commit6bfa3cae0590a1ed6a40b20ae48389a89b366fb2 (patch)
treeb35c6a9ff714241282c83dcd9cdb066b0b0c7e11 /utils.c
parent230ab9376c721a9349ed6997e404afd059ac9247 (diff)
downloadbtrfs-progs-6bfa3cae0590a1ed6a40b20ae48389a89b366fb2.tar.gz
btrfs-progs: add helper for copying paths
Check the source path length and do the copy. Signed-off-by: David Sterba <dsterba@suse.cz>
Diffstat (limited to 'utils.c')
-rw-r--r--utils.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/utils.c b/utils.c
index 591b2a1..b458e6b 100644
--- a/utils.c
+++ b/utils.c
@@ -2871,3 +2871,22 @@ int btrfs_check_nodesize(u32 nodesize, u32 sectorsize)
}
return 0;
}
+
+/*
+ * Copy a path argument from SRC to DEST and check the SRC length if it's at
+ * most PATH_MAX and fits into DEST. DESTLEN is supposed to be exact size of
+ * the buffer.
+ * The destination buffer is zero terminated.
+ * Return < 0 for error, 0 otherwise.
+ */
+int arg_copy_path(char *dest, const char *src, int destlen)
+{
+ size_t len = strlen(src);
+
+ if (len >= PATH_MAX || len >= destlen)
+ return -ENAMETOOLONG;
+
+ __strncpy__null(dest, src, destlen);
+
+ return 0;
+}