Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
liblongpath-rsync
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liblongpath
liblongpath-rsync
Commits
368ad70e
Commit
368ad70e
authored
Jan 20, 2004
by
Wayne Davison
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added stringjoin() and pathjoin().
parent
b7cee949
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
0 deletions
+52
-0
util.c
util.c
+52
-0
No files found.
util.c
View file @
368ad70e
...
...
@@ -553,6 +553,58 @@ void strlower(char *s)
}
}
/* Join strings p1 & p2 into "dest" with a guaranteed '/' between them. (If
* p1 ends with a '/', no extra '/' is inserted.) Returns the length of both
* strings + 1 (if '/' was inserted), regardless of whether the whole thing
* fits into destsize (including the terminating '\0'). */
size_t
pathjoin
(
char
*
dest
,
size_t
destsize
,
const
char
*
p1
,
const
char
*
p2
)
{
size_t
len
=
strlcpy
(
dest
,
p1
,
destsize
);
if
(
len
<
destsize
-
1
)
{
if
(
!
len
||
dest
[
len
-
1
]
!=
'/'
)
dest
[
len
++
]
=
'/'
;
if
(
len
<
destsize
-
1
)
len
+=
strlcpy
(
dest
+
len
,
p2
,
destsize
-
len
);
else
{
dest
[
len
]
=
'\0'
;
len
+=
strlen
(
p2
);
}
}
else
len
+=
strlen
(
p2
)
+
1
;
/* Assume we'd insert a '/'. */
return
len
;
}
/* Join any number of strings together, putting them in "dest". The return
* value is the length of all the strings, regardless of whether they fit in
* destsize (including the terminating '\0'). Your list of string pointers
* should end with a NULL to indicate the end of the list. */
size_t
stringjoin
(
char
*
dest
,
size_t
destsize
,
...)
{
va_list
ap
;
size_t
len
,
ret
=
0
;
const
char
*
src
;
va_start
(
ap
,
destsize
);
while
(
1
)
{
if
(
!
(
src
=
va_arg
(
ap
,
const
char
*
)))
break
;
len
=
strlen
(
src
);
ret
+=
len
;
if
(
destsize
>
1
)
{
if
(
len
>=
destsize
)
len
=
destsize
-
1
;
memcpy
(
dest
,
src
,
len
);
destsize
-=
len
;
dest
+=
len
;
}
}
*
dest
=
'\0'
;
va_end
(
ap
);
return
ret
;
}
void
clean_fname
(
char
*
name
)
{
char
*
p
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment