Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib/gis: match prototype with declaration for G_strlcat and G_strlcpy #4332

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions lib/gis/strlcat.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
#include <stddef.h>
#include <string.h>

static size_t G__strlcat(char *restrict dst, const char *restrict src,
size_t dsize);

/**
* \brief Size-bounded string concatenation
*
Expand All @@ -51,12 +54,18 @@
* including the terminating NUL character). If the return value
* is >= dsize, truncation occurred.
*/

size_t G_strlcat(char *restrict dst, const char *restrict src, size_t dsize)
size_t G_strlcat(char *dst, const char *src, size_t dsize)
{
#ifdef HAVE_STRLCAT
return strlcat(dst, src, dsize);
#else
return G__strlcat(dst, src, dsize);
#endif
}

static size_t G__strlcat(char *restrict dst, const char *restrict src,
size_t dsize)
{
const char *odst = dst;
const char *osrc = src;
size_t n = dsize;
Expand All @@ -80,5 +89,4 @@ size_t G_strlcat(char *restrict dst, const char *restrict src, size_t dsize)
*dst = '\0';

return (dlen + (src - osrc)); /* count does not include NUL */
#endif
}
14 changes: 11 additions & 3 deletions lib/gis/strlcpy.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

#include <stddef.h>

static size_t G__strlcpy(char *restrict dst, const char *restrict src,
size_t dsize);

/**
* \brief Safe string copy function.
*
Expand All @@ -46,12 +49,18 @@
* \warning The src string must be a valid NUL-terminated C string. Passing an
* unterminated string may result in buffer overrun.
*/

size_t G_strlcpy(char *restrict dst, const char *restrict src, size_t dsize)
size_t G_strlcpy(char *dst, const char *src, size_t dsize)
{
#ifdef HAVE_STRLCPY
return strlcpy(dst, src, dsize);
#else
return G__strlcpy(dst, src, dsize);
#endif
}

static size_t G__strlcpy(char *restrict dst, const char *restrict src,
size_t dsize)
{
const char *osrc = src;
size_t nleft = dsize;

Expand All @@ -72,5 +81,4 @@ size_t G_strlcpy(char *restrict dst, const char *restrict src, size_t dsize)
}

return (src - osrc - 1); /* count does not include NUL */
#endif
}
Loading