Fix compile errors and get rid of glib dependency

This commit is contained in:
Cacodemon345
2021-08-22 22:37:37 +06:00
parent 39fea69d5c
commit f6af2b0162
3 changed files with 38 additions and 2 deletions

View File

@@ -94,3 +94,40 @@ g_strv_length(gchar **str_array)
++i;
return i;
}
/* Implementation borrowed from GLib itself. */
gsize
g_strlcpy (gchar *dest,
const gchar *src,
gsize dest_size)
{
gchar *d = dest;
const gchar *s = src;
gsize n = dest_size;
if (dest == NULL) return 0;
if (src == NULL) return 0;
/* Copy as many bytes as will fit */
if (n != 0 && --n != 0)
do
{
gchar c = *s++;
*d++ = c;
if (c == 0)
break;
}
while (--n != 0);
/* If not enough room in dest, add NUL and traverse rest of src */
if (n == 0)
{
if (dest_size != 0)
*d = 0;
while (*s++)
;
}
return s - src - 1; /* count does not include NUL */
}