btrfs-progs: move path_cat_out helpers to path-utils
The path-util.[ch] is the right place, keep the send-utils.h prototypes as it's part of libbtrfs headers. Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
b79713a33e
commit
fbc12fd9ec
|
@ -393,6 +393,43 @@ int arg_copy_path(char *dest, const char *src, int destlen)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int path_cat_out(char *out, const char *p1, const char *p2)
|
||||
{
|
||||
int p1_len = strlen(p1);
|
||||
int p2_len = strlen(p2);
|
||||
|
||||
if (p1_len + p2_len + 2 >= PATH_MAX)
|
||||
return -ENAMETOOLONG;
|
||||
|
||||
if (p1_len && p1[p1_len - 1] == '/')
|
||||
p1_len--;
|
||||
if (p2_len && p2[p2_len - 1] == '/')
|
||||
p2_len--;
|
||||
sprintf(out, "%.*s/%.*s", p1_len, p1, p2_len, p2);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int path_cat3_out(char *out, const char *p1, const char *p2, const char *p3)
|
||||
{
|
||||
int p1_len = strlen(p1);
|
||||
int p2_len = strlen(p2);
|
||||
int p3_len = strlen(p3);
|
||||
|
||||
if (p1_len + p2_len + p3_len + 3 >= PATH_MAX)
|
||||
return -ENAMETOOLONG;
|
||||
|
||||
if (p1_len && p1[p1_len - 1] == '/')
|
||||
p1_len--;
|
||||
if (p2_len && p2[p2_len - 1] == '/')
|
||||
p2_len--;
|
||||
if (p3_len && p3[p3_len - 1] == '/')
|
||||
p3_len--;
|
||||
sprintf(out, "%.*s/%.*s/%.*s", p1_len, p1, p2_len, p2, p3_len, p3);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Subvolume helper functions */
|
||||
/*
|
||||
* test if name is a correct subvolume name
|
||||
|
|
|
@ -23,6 +23,8 @@ char *canonicalize_dm_name(const char *ptname);
|
|||
char *canonicalize_path(const char *path);
|
||||
|
||||
int arg_copy_path(char *dest, const char *src, int destlen);
|
||||
int path_cat_out(char *out, const char *p1, const char *p2);
|
||||
int path_cat3_out(char *out, const char *p1, const char *p2, const char *p3);
|
||||
|
||||
char *__strncpy_null(char *dest, const char *src, size_t n);
|
||||
/* Helper to always get proper size of the destination string */
|
||||
|
|
|
@ -749,40 +749,3 @@ void subvol_uuid_search_finit(struct subvol_uuid_search *s)
|
|||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
int path_cat_out(char *out, const char *p1, const char *p2)
|
||||
{
|
||||
int p1_len = strlen(p1);
|
||||
int p2_len = strlen(p2);
|
||||
|
||||
if (p1_len + p2_len + 2 >= PATH_MAX)
|
||||
return -ENAMETOOLONG;
|
||||
|
||||
if (p1_len && p1[p1_len - 1] == '/')
|
||||
p1_len--;
|
||||
if (p2_len && p2[p2_len - 1] == '/')
|
||||
p2_len--;
|
||||
sprintf(out, "%.*s/%.*s", p1_len, p1, p2_len, p2);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int path_cat3_out(char *out, const char *p1, const char *p2, const char *p3)
|
||||
{
|
||||
int p1_len = strlen(p1);
|
||||
int p2_len = strlen(p2);
|
||||
int p3_len = strlen(p3);
|
||||
|
||||
if (p1_len + p2_len + p3_len + 3 >= PATH_MAX)
|
||||
return -ENAMETOOLONG;
|
||||
|
||||
if (p1_len && p1[p1_len - 1] == '/')
|
||||
p1_len--;
|
||||
if (p2_len && p2[p2_len - 1] == '/')
|
||||
p2_len--;
|
||||
if (p3_len && p3[p3_len - 1] == '/')
|
||||
p3_len--;
|
||||
sprintf(out, "%.*s/%.*s/%.*s", p1_len, p1, p2_len, p2, p3_len, p3);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue