mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2024-11-25 14:00:58 +00:00
add Q_strlcpy and Q_strlcat
This commit is contained in:
parent
392c04bc1d
commit
a26892cb90
2 changed files with 39 additions and 0 deletions
|
@ -223,6 +223,10 @@ int Q_strncasecmp(char *s1, char *s2, int n);
|
|||
/* portable string lowercase */
|
||||
char *Q_strlwr(char *s);
|
||||
|
||||
/* portable safe string copy/concatenate */
|
||||
int Q_strlcpy(char *dst, const char *src, int size);
|
||||
int Q_strlcat(char *dst, const char *src, int size);
|
||||
|
||||
/* ============================================= */
|
||||
|
||||
short BigShort(short l);
|
||||
|
|
|
@ -1132,6 +1132,41 @@ Q_strlwr ( char *s )
|
|||
return ( p );
|
||||
}
|
||||
|
||||
int
|
||||
Q_strlcpy(char *dst, const char *src, int size)
|
||||
{
|
||||
const char *s = src;
|
||||
|
||||
while (*s)
|
||||
{
|
||||
if (size > 1)
|
||||
{
|
||||
*dst++ = *s;
|
||||
size--;
|
||||
}
|
||||
s++;
|
||||
}
|
||||
if (size > 0)
|
||||
{
|
||||
*dst = '\0';
|
||||
}
|
||||
|
||||
return s - src;
|
||||
}
|
||||
|
||||
int
|
||||
Q_strlcat(char *dst, const char *src, int size)
|
||||
{
|
||||
char *d = dst;
|
||||
|
||||
while (*d)
|
||||
{
|
||||
d++;
|
||||
}
|
||||
|
||||
return (d - dst) + Q_strlcpy(d, src, size - (d - dst));
|
||||
}
|
||||
|
||||
/*
|
||||
* =====================================================================
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue