mirror of
https://github.com/esp8266/Arduino.git
synced 2025-08-08 11:22:40 +03:00
Mock - update func signatures for latest glibc (#9117)
glibc 2.38 includes strlcpy and strlcat, attempt to detect them before use
This commit is contained in:
@@ -56,18 +56,23 @@
|
||||
#define D8 8
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <stdlib_noniso.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
// TODO: #include <stdlib_noniso.h> ?
|
||||
char* itoa(int val, char* s, int radix);
|
||||
char* ltoa(long val, char* s, int radix);
|
||||
|
||||
char* utoa(unsigned value, char* result, int base);
|
||||
char* itoa(int value, char* result, int base);
|
||||
#ifdef STRLCAT_MISSING
|
||||
size_t strlcat(char* dst, const char* src, size_t size);
|
||||
#endif
|
||||
#ifdef STRLCPY_MISSING
|
||||
size_t strlcpy(char* dst, const char* src, size_t size);
|
||||
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@@ -18,9 +18,10 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <math.h>
|
||||
#include "stdlib_noniso.h"
|
||||
|
||||
void reverse(char* begin, char* end)
|
||||
#include <stdlib_noniso.h>
|
||||
|
||||
static void reverse(char* begin, char* end)
|
||||
{
|
||||
char* is = begin;
|
||||
char* ie = end - 1;
|
||||
@@ -84,20 +85,3 @@ char* itoa(int value, char* result, int base)
|
||||
utoa(uvalue, result, base);
|
||||
return out;
|
||||
}
|
||||
|
||||
int atoi(const char* s)
|
||||
{
|
||||
return (int)atol(s);
|
||||
}
|
||||
|
||||
long atol(const char* s)
|
||||
{
|
||||
char* tmp;
|
||||
return strtol(s, &tmp, 10);
|
||||
}
|
||||
|
||||
double atof(const char* s)
|
||||
{
|
||||
char* tmp;
|
||||
return strtod(s, &tmp);
|
||||
}
|
||||
|
@@ -1,84 +1,78 @@
|
||||
// https://gist.github.com/Fonger/98cc95ac39fbe1a7e4d9
|
||||
|
||||
#ifndef HAVE_STRLCAT
|
||||
/*
|
||||
'_cups_strlcat()' - Safely concatenate two strings.
|
||||
*/
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
size_t /* O - Length of string */
|
||||
strlcat(char* dst, /* O - Destination string */
|
||||
const char* src, /* I - Source string */
|
||||
size_t size) /* I - Size of destination string buffer */
|
||||
extern "C"
|
||||
{
|
||||
size_t srclen; /* Length of source string */
|
||||
size_t dstlen; /* Length of destination string */
|
||||
#ifdef STRLCAT_MISSING
|
||||
// '_cups_strlcat()' - Safely concatenate two strings.
|
||||
|
||||
/*
|
||||
Figure out how much room is left...
|
||||
*/
|
||||
|
||||
dstlen = strlen(dst);
|
||||
size -= dstlen + 1;
|
||||
|
||||
if (!size)
|
||||
size_t /* O - Length of string */
|
||||
strlcat(char* dst, /* O - Destination string */
|
||||
const char* src, /* I - Source string */
|
||||
size_t size) /* I - Size of destination string buffer */
|
||||
{
|
||||
return (dstlen); /* No room, return immediately... */
|
||||
size_t srclen; /* Length of source string */
|
||||
size_t dstlen; /* Length of destination string */
|
||||
|
||||
// Figure out how much room is left...
|
||||
|
||||
dstlen = strlen(dst);
|
||||
size -= dstlen + 1;
|
||||
|
||||
if (!size)
|
||||
{
|
||||
return (dstlen); /* No room, return immediately... */
|
||||
}
|
||||
|
||||
// Figure out how much room is needed...
|
||||
|
||||
srclen = strlen(src);
|
||||
|
||||
// Copy the appropriate amount...
|
||||
|
||||
if (srclen > size)
|
||||
{
|
||||
srclen = size;
|
||||
}
|
||||
|
||||
memcpy(dst + dstlen, src, srclen);
|
||||
dst[dstlen + srclen] = '\0';
|
||||
|
||||
return (dstlen + srclen);
|
||||
}
|
||||
#endif /* STRLCAT_MISSING */
|
||||
|
||||
/*
|
||||
Figure out how much room is needed...
|
||||
*/
|
||||
#ifdef STRLCPY_MISSING
|
||||
// '_cups_strlcpy()' - Safely copy two strings.
|
||||
|
||||
srclen = strlen(src);
|
||||
|
||||
/*
|
||||
Copy the appropriate amount...
|
||||
*/
|
||||
|
||||
if (srclen > size)
|
||||
size_t /* O - Length of string */
|
||||
strlcpy(char* dst, /* O - Destination string */
|
||||
const char* src, /* I - Source string */
|
||||
size_t size) /* I - Size of destination string buffer */
|
||||
{
|
||||
srclen = size;
|
||||
size_t srclen; /* Length of source string */
|
||||
|
||||
// Figure out how much room is needed...
|
||||
|
||||
size--;
|
||||
|
||||
srclen = strlen(src);
|
||||
|
||||
// Copy the appropriate amount...
|
||||
|
||||
if (srclen > size)
|
||||
{
|
||||
srclen = size;
|
||||
}
|
||||
|
||||
memcpy(dst, src, srclen);
|
||||
dst[srclen] = '\0';
|
||||
|
||||
return (srclen);
|
||||
}
|
||||
#endif /* STRLCPY_MISSING */
|
||||
|
||||
memcpy(dst + dstlen, src, srclen);
|
||||
dst[dstlen + srclen] = '\0';
|
||||
|
||||
return (dstlen + srclen);
|
||||
}
|
||||
#endif /* !HAVE_STRLCAT */
|
||||
|
||||
#ifndef HAVE_STRLCPY
|
||||
/*
|
||||
'_cups_strlcpy()' - Safely copy two strings.
|
||||
*/
|
||||
|
||||
size_t /* O - Length of string */
|
||||
strlcpy(char* dst, /* O - Destination string */
|
||||
const char* src, /* I - Source string */
|
||||
size_t size) /* I - Size of destination string buffer */
|
||||
{
|
||||
size_t srclen; /* Length of source string */
|
||||
|
||||
/*
|
||||
Figure out how much room is needed...
|
||||
*/
|
||||
|
||||
size--;
|
||||
|
||||
srclen = strlen(src);
|
||||
|
||||
/*
|
||||
Copy the appropriate amount...
|
||||
*/
|
||||
|
||||
if (srclen > size)
|
||||
{
|
||||
srclen = size;
|
||||
}
|
||||
|
||||
memcpy(dst, src, srclen);
|
||||
dst[srclen] = '\0';
|
||||
|
||||
return (srclen);
|
||||
}
|
||||
#endif /* !HAVE_STRLCPY */
|
||||
} // extern "C"
|
||||
|
Reference in New Issue
Block a user