mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +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:
parent
05f05d0dab
commit
3a5157e3ba
@ -28,19 +28,12 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
#include "stdlib_noniso.h"
|
#include "stdlib_noniso.h"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
char* ltoa(long value, char* result, int base) {
|
char* dtostrf(double number, signed char width, unsigned char prec, char *s) noexcept {
|
||||||
return itoa((int)value, result, base);
|
|
||||||
}
|
|
||||||
|
|
||||||
char* ultoa(unsigned long value, char* result, int base) {
|
|
||||||
return utoa((unsigned int)value, result, base);
|
|
||||||
}
|
|
||||||
|
|
||||||
char * dtostrf(double number, signed char width, unsigned char prec, char *s) {
|
|
||||||
bool negative = false;
|
bool negative = false;
|
||||||
|
|
||||||
if (isnan(number)) {
|
if (isnan(number)) {
|
||||||
@ -125,7 +118,7 @@ char * dtostrf(double number, signed char width, unsigned char prec, char *s) {
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
const char* strrstr(const char*__restrict p_pcString,
|
const char* strrstr(const char*__restrict p_pcString,
|
||||||
const char*__restrict p_pcPattern)
|
const char*__restrict p_pcPattern) noexcept
|
||||||
{
|
{
|
||||||
const char* pcResult = 0;
|
const char* pcResult = 0;
|
||||||
|
|
||||||
@ -149,4 +142,4 @@ const char* strrstr(const char*__restrict p_pcString,
|
|||||||
return pcResult;
|
return pcResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
} // extern "C"
|
||||||
|
@ -21,11 +21,13 @@
|
|||||||
|
|
||||||
#include "stdlib_noniso.h"
|
#include "stdlib_noniso.h"
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
// ulltoa() is slower than std::to_char() (1.6 times)
|
// ulltoa() is slower than std::to_char() (1.6 times)
|
||||||
// but is smaller by ~800B/flash and ~250B/rodata
|
// but is smaller by ~800B/flash and ~250B/rodata
|
||||||
|
|
||||||
// ulltoa fills str backwards and can return a pointer different from str
|
// ulltoa fills str backwards and can return a pointer different from str
|
||||||
char* ulltoa(unsigned long long val, char* str, int slen, unsigned int radix)
|
char* ulltoa(unsigned long long val, char* str, int slen, unsigned int radix) noexcept
|
||||||
{
|
{
|
||||||
str += --slen;
|
str += --slen;
|
||||||
*str = 0;
|
*str = 0;
|
||||||
@ -39,7 +41,7 @@ char* ulltoa(unsigned long long val, char* str, int slen, unsigned int radix)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// lltoa fills str backwards and can return a pointer different from str
|
// lltoa fills str backwards and can return a pointer different from str
|
||||||
char* lltoa (long long val, char* str, int slen, unsigned int radix)
|
char* lltoa(long long val, char* str, int slen, unsigned int radix) noexcept
|
||||||
{
|
{
|
||||||
bool neg;
|
bool neg;
|
||||||
if (val < 0)
|
if (val < 0)
|
||||||
@ -60,3 +62,13 @@ char* lltoa (long long val, char* str, int slen, unsigned int radix)
|
|||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char* ltoa(long value, char* result, int base) noexcept {
|
||||||
|
return itoa((int)value, result, base);
|
||||||
|
}
|
||||||
|
|
||||||
|
char* ultoa(unsigned long value, char* result, int base) noexcept {
|
||||||
|
return utoa((unsigned int)value, result, base);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // extern "C"
|
||||||
|
@ -22,38 +22,35 @@
|
|||||||
#ifndef STDLIB_NONISO_H
|
#ifndef STDLIB_NONISO_H
|
||||||
#define STDLIB_NONISO_H
|
#define STDLIB_NONISO_H
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"{
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int atoi(const char *s);
|
#ifdef __cplusplus
|
||||||
|
#define __STDLIB_NONISO_NOEXCEPT noexcept
|
||||||
|
#else
|
||||||
|
#define __STDLIB_NONISO_NOEXCEPT
|
||||||
|
#endif
|
||||||
|
|
||||||
long atol(const char* s);
|
char* ltoa (long val, char *s, int radix) __STDLIB_NONISO_NOEXCEPT;
|
||||||
|
|
||||||
double atof(const char* s);
|
char* lltoa (long long val, char* str, int slen, unsigned int radix) __STDLIB_NONISO_NOEXCEPT;
|
||||||
|
|
||||||
char* itoa (int val, char *s, int radix);
|
char* ultoa (unsigned long val, char *s, int radix) __STDLIB_NONISO_NOEXCEPT;
|
||||||
|
|
||||||
char* ltoa (long val, char *s, int radix);
|
char* ulltoa (unsigned long long val, char* str, int slen, unsigned int radix) __STDLIB_NONISO_NOEXCEPT;
|
||||||
|
|
||||||
char* lltoa (long long val, char* str, int slen, unsigned int radix);
|
char* dtostrf (double val, signed char width, unsigned char prec, char *s) __STDLIB_NONISO_NOEXCEPT;
|
||||||
|
|
||||||
char* utoa (unsigned int val, char *s, int radix);
|
const char* strrstr (const char*__restrict p_pcString,
|
||||||
|
const char*__restrict p_pcPattern) __STDLIB_NONISO_NOEXCEPT;
|
||||||
|
|
||||||
char* ultoa (unsigned long val, char *s, int radix);
|
#undef __STDLIB_NONISO_NOEXCEPT
|
||||||
|
|
||||||
char* ulltoa (unsigned long long val, char* str, int slen, unsigned int radix);
|
|
||||||
|
|
||||||
char* dtostrf (double val, signed char width, unsigned char prec, char *s);
|
|
||||||
|
|
||||||
void reverse(char* begin, char* end);
|
|
||||||
|
|
||||||
const char* strrstr(const char*__restrict p_pcString,
|
|
||||||
const char*__restrict p_pcPattern);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -30,6 +30,7 @@ GENHTML ?= genhtml
|
|||||||
CXXFLAGS += -std=gnu++17
|
CXXFLAGS += -std=gnu++17
|
||||||
CFLAGS += -std=gnu17
|
CFLAGS += -std=gnu17
|
||||||
|
|
||||||
|
# 32-bit mode is prefered, but not required
|
||||||
ifeq ($(FORCE32),1)
|
ifeq ($(FORCE32),1)
|
||||||
SIZEOFLONG = $(shell echo 'int main(){return sizeof(long);}'|$(CXX) -m32 -x c++ - -o sizeoflong 2>/dev/null && ./sizeoflong; echo $$?; rm -f sizeoflong;)
|
SIZEOFLONG = $(shell echo 'int main(){return sizeof(long);}'|$(CXX) -m32 -x c++ - -o sizeoflong 2>/dev/null && ./sizeoflong; echo $$?; rm -f sizeoflong;)
|
||||||
ifneq ($(SIZEOFLONG),4)
|
ifneq ($(SIZEOFLONG),4)
|
||||||
@ -50,6 +51,7 @@ endif
|
|||||||
OUTPUT_BINARY := $(BINDIR)/host_tests
|
OUTPUT_BINARY := $(BINDIR)/host_tests
|
||||||
LCOV_DIRECTORY := $(BINDIR)/../lcov
|
LCOV_DIRECTORY := $(BINDIR)/../lcov
|
||||||
|
|
||||||
|
# Hide full build commands by default
|
||||||
ifeq ($(V), 0)
|
ifeq ($(V), 0)
|
||||||
VERBC = @echo "C $@";
|
VERBC = @echo "C $@";
|
||||||
VERBCXX = @echo "C++ $@";
|
VERBCXX = @echo "C++ $@";
|
||||||
@ -66,6 +68,30 @@ endif
|
|||||||
|
|
||||||
$(shell mkdir -p $(BINDIR))
|
$(shell mkdir -p $(BINDIR))
|
||||||
|
|
||||||
|
# Core files sometimes override libc functions, check when necessary to hide them
|
||||||
|
# TODO proper configure script / other build system?
|
||||||
|
ifeq (,$(wildcard $(BINDIR)/.have_strlcpy))
|
||||||
|
$(shell echo -e '#include <cstring>\nint main(){char a[4]{}; char b[4]{}; strlcpy(&a[0], &b[0], sizeof(a)); return 0;}' | \
|
||||||
|
$(CXX) -x c++ - -o $(BINDIR)/.have_strlcpy 2>/dev/null || ( echo -e '#!/bin/sh\nexit 1' > $(BINDIR)/.have_strlcpy ; chmod +x $(BINDIR)/.have_strlcpy; ))
|
||||||
|
endif
|
||||||
|
|
||||||
|
$(shell $(BINDIR)/.have_strlcpy)
|
||||||
|
ifneq ($(.SHELLSTATUS), 0)
|
||||||
|
FLAGS += -DSTRLCPY_MISSING
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq (,$(wildcard $(BINDIR)/.have_strlcat))
|
||||||
|
$(shell echo -e '#include <cstring>\nint main(){char a[4]{}; strlcat(&a[0], "test", sizeof(a)); return 0;}' | \
|
||||||
|
$(CXX) -x c++ - -o $(BINDIR)/.have_strlcat 2>/dev/null || ( echo -e '#!/bin/sh\nexit 1' > $(BINDIR)/.have_strlcat ; chmod +x $(BINDIR)/.have_strlcat; ))
|
||||||
|
endif
|
||||||
|
|
||||||
|
$(shell $(BINDIR)/.have_strlcat)
|
||||||
|
ifneq ($(.SHELLSTATUS), 0)
|
||||||
|
FLAGS += -DSTRLCAT_MISSING
|
||||||
|
endif
|
||||||
|
|
||||||
|
# Actual build recipes
|
||||||
|
|
||||||
CORE_CPP_FILES := \
|
CORE_CPP_FILES := \
|
||||||
$(addprefix $(abspath $(CORE_PATH))/,\
|
$(addprefix $(abspath $(CORE_PATH))/,\
|
||||||
debug.cpp \
|
debug.cpp \
|
||||||
|
@ -56,18 +56,23 @@
|
|||||||
#define D8 8
|
#define D8 8
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <stdlib_noniso.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
// TODO: #include <stdlib_noniso.h> ?
|
char* utoa(unsigned value, char* result, int base);
|
||||||
char* itoa(int val, char* s, int radix);
|
char* itoa(int value, char* result, int base);
|
||||||
char* ltoa(long val, char* s, int radix);
|
#ifdef STRLCAT_MISSING
|
||||||
|
|
||||||
size_t strlcat(char* dst, const char* src, size_t size);
|
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);
|
size_t strlcpy(char* dst, const char* src, size_t size);
|
||||||
|
#endif
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -18,9 +18,10 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <math.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* is = begin;
|
||||||
char* ie = end - 1;
|
char* ie = end - 1;
|
||||||
@ -84,20 +85,3 @@ char* itoa(int value, char* result, int base)
|
|||||||
utoa(uvalue, result, base);
|
utoa(uvalue, result, base);
|
||||||
return out;
|
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
|
// https://gist.github.com/Fonger/98cc95ac39fbe1a7e4d9
|
||||||
|
|
||||||
#ifndef HAVE_STRLCAT
|
#include <cstddef>
|
||||||
/*
|
#include <cstdlib>
|
||||||
'_cups_strlcat()' - Safely concatenate two strings.
|
#include <cstring>
|
||||||
*/
|
|
||||||
|
|
||||||
size_t /* O - Length of string */
|
extern "C"
|
||||||
strlcat(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 */
|
#ifdef STRLCAT_MISSING
|
||||||
size_t dstlen; /* Length of destination string */
|
// '_cups_strlcat()' - Safely concatenate two strings.
|
||||||
|
|
||||||
/*
|
size_t /* O - Length of string */
|
||||||
Figure out how much room is left...
|
strlcat(char* dst, /* O - Destination string */
|
||||||
*/
|
const char* src, /* I - Source string */
|
||||||
|
size_t size) /* I - Size of destination string buffer */
|
||||||
dstlen = strlen(dst);
|
|
||||||
size -= dstlen + 1;
|
|
||||||
|
|
||||||
if (!size)
|
|
||||||
{
|
{
|
||||||
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 */
|
||||||
|
|
||||||
/*
|
#ifdef STRLCPY_MISSING
|
||||||
Figure out how much room is needed...
|
// '_cups_strlcpy()' - Safely copy two strings.
|
||||||
*/
|
|
||||||
|
|
||||||
srclen = strlen(src);
|
size_t /* O - Length of string */
|
||||||
|
strlcpy(char* dst, /* O - Destination string */
|
||||||
/*
|
const char* src, /* I - Source string */
|
||||||
Copy the appropriate amount...
|
size_t size) /* I - Size of destination string buffer */
|
||||||
*/
|
|
||||||
|
|
||||||
if (srclen > size)
|
|
||||||
{
|
{
|
||||||
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);
|
} // extern "C"
|
||||||
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 */
|
|
||||||
|
@ -208,7 +208,6 @@ void *ets_memset(void *s, int c, size_t n);
|
|||||||
void ets_timer_arm_new(ETSTimer *a, int b, int c, int isMstimer);
|
void ets_timer_arm_new(ETSTimer *a, int b, int c, int isMstimer);
|
||||||
void ets_timer_setfn(ETSTimer *t, ETSTimerFunc *fn, void *parg);
|
void ets_timer_setfn(ETSTimer *t, ETSTimerFunc *fn, void *parg);
|
||||||
void ets_timer_disarm(ETSTimer *a);
|
void ets_timer_disarm(ETSTimer *a);
|
||||||
int atoi(const char *nptr);
|
|
||||||
int ets_strncmp(const char *s1, const char *s2, int len);
|
int ets_strncmp(const char *s1, const char *s2, int len);
|
||||||
int ets_strcmp(const char *s1, const char *s2);
|
int ets_strcmp(const char *s1, const char *s2);
|
||||||
int ets_strlen(const char *s);
|
int ets_strlen(const char *s);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user