1
0
Fork 0

Update safe string copy for better debug flow and fix filename typo.

This commit is contained in:
wael 2022-03-05 16:52:37 +02:00
parent d1b2cb96a6
commit cd6121019b
No known key found for this signature in database
GPG Key ID: C0A5FBF4558963D4
2 changed files with 10 additions and 0 deletions

View File

@ -29,6 +29,9 @@
* Will return the length copied (and whether it overflowed or not).
*/
char *strscpy(char *restrict dest, const char* restrict src, size_t n) {
/* Sanity check. */
assert(dest && src);
/* Copy using memcpy. */
char *last = memccpy(dest, src, NULL_CHAR, n);

View File

@ -20,6 +20,13 @@
#define STRSCPY_H
/* Include string.h */
#include <string.h>
/* Include assert.h to allow code generation, but only run with debug flag. */
#ifdef DEBUG
#ifndef NDEBUG
#define NDEBUG
#endif /* NDEBUG. */
#endif /* DEBUG. */
#include <assert.h>
/* Constants. */
#define NULL_CHAR '\0'