Rewrite the wrappers of strncpy & strncat:
Add one argument about the allocation of the dest buffer Theses wrappers are internal (so no impact to API) and only used in a few place in m-string. This make the wrappers able to use the function strncpy_s & strncat_s for MSVC rather than using reimplementation of the original functions.
This commit is contained in:
1 parent
561f67b3b9
commit
cd357c5eb7
2 files changed
+16
-42
No files matched your search
@@ -1756,41 +1756,15 @@ m_core_fopen(const char filename[], const char opt[])
|
||||
if (err) return NULL;
|
||||
return f;
|
||||
}
|
||||
/* Rewrite strncpy (Cannot use strncpy_s as its semantic is too bothersome) */
|
||||
static inline void m_core_strncpy(char s1[], const char s2[], size_t size)
|
||||
{
|
||||
while (size > 0) {
|
||||
*s1 = *s2;
|
||||
s1 ++;
|
||||
s2 += (*s2 != 0);
|
||||
size --;
|
||||
}
|
||||
// No final null char (it may not appear in case of truncation)
|
||||
}
|
||||
/* Rewrite strncat (Cannot use strncat_s as its semantic is too bothersome) */
|
||||
static inline void m_core_strncat(char s1[], const char s2[], size_t size)
|
||||
{
|
||||
// Go to the end of s1
|
||||
while (*s1 != 0) {
|
||||
s1++;
|
||||
}
|
||||
// Copy at most size bytes of s2 in s1.
|
||||
while (size > 0)
|
||||
{
|
||||
*s1 = *s2;
|
||||
if (*s2 == 0) {
|
||||
break;
|
||||
}
|
||||
s1 ++;
|
||||
s2 ++;
|
||||
size --;
|
||||
}
|
||||
// Always a final null char.
|
||||
*s1 = 0;
|
||||
}
|
||||
|
||||
/* Wrapper around strncpy */
|
||||
#define m_core_strncpy(s1, alloc, s2, size) strncpy_s(s1, alloc, s2, size)
|
||||
|
||||
/* Wrapper around strncat */
|
||||
#define m_core_strncat(s1, alloc, s2, size) strncat_s(s1, alloc, s2, size)
|
||||
|
||||
/* Wrapper around fscanf_s */
|
||||
#define m_core_fscanf(...) fscanf_s(__VA_ARGS__)
|
||||
|
||||
/* Macro to be used in m_core_fscanf for argument associated
|
||||
* to the format %c, %s or %[
|
||||
* in order to specify the size of the argument */
|
||||
@@ -1801,9 +1775,9 @@ static inline void m_core_strncat(char s1[], const char s2[], size_t size)
|
||||
/* Wrapper around fopen */
|
||||
#define m_core_fopen(...) fopen(__VA_ARGS__)
|
||||
/* Wrapper around strncpy */
|
||||
#define m_core_strncpy(...) strncpy(__VA_ARGS__)
|
||||
#define m_core_strncpy(s1, alloc, s2, size) strncpy(s1, s2, size)
|
||||
/* Wrapper around strncat */
|
||||
#define m_core_strncat(s1, s2, size) strncat(s1, s2, size)
|
||||
#define m_core_strncat(s1, alloc, s2, size) strncat(s1, s2, size)
|
||||
/* Wrapper around fscanf */
|
||||
#define m_core_fscanf(...) fscanf(__VA_ARGS__)
|
||||
|
||||
|
||||
Reference in new issue
Block a user