use access from gcc 11

This commit is contained in:
Mathieu Maret 2023-11-08 21:52:55 +01:00
parent a459111348
commit a179a6a0a7
3 changed files with 21 additions and 17 deletions

View File

@ -27,19 +27,9 @@ int memcmp(const void *aptr, const void *bptr, size_t size)
/* How many bytes are copied each iteration of the word copy loop. */
#define LITTLEBLOCKSIZE (sizeof (long))
/* Threshhold for punting to the byte copier. */
/* Threshold for punting to the byte copier. */
#define TOO_SMALL(LEN) ((LEN) < BIGBLOCKSIZE)
void *memmove(void *dst, const void *src, size_t n)
{
char *dstChar = dst;
const char *srcChar = src;
for (size_t i = 0; i < n; i++) {
*(dstChar++) = *(srcChar++);
}
return dst;
}
void *memcpy(void *dst0, const void *src0, size_t len0)
{
#if 0
@ -88,6 +78,16 @@ void *memcpy(void *dst0, const void *src0, size_t len0)
#endif
}
void *memmove(void *dst, const void *src, size_t n)
{
char *dstChar = dst;
const char *srcChar = src;
for (size_t i = 0; i < n; i++) {
*(dstChar++) = *(srcChar++);
}
return dst;
}
void *memset(void *src, int c, size_t n)
{
for (char *ptr = (char *)src; n > 0; n--, ptr++) {

View File

@ -14,21 +14,21 @@
/** compares the first @param n bytes (each interpreted as
* unsigned char) of the memory areas @param s1 and @param s2.
*/
int memcmp(const void *s1, const void *s2, size_t n);
__attribute__ ((access (read_only, 1, 3), access (read_only, 2, 3))) int memcmp(const void *s1, const void *s2, size_t n);
/**
* copies n bytes from memory area src to memory area dest. The memory areas may overlap
*/
void *memmove(void *dest, const void *src, size_t n);
void *memcpy(void *dest, const void *src, size_t n);
void *memset(void *s, int c, size_t n);
__attribute__ ((access (write_only, 1, 3), access (read_only, 2, 3))) void *memmove(void *dest, const void *src, size_t n);
__attribute__ ((access (write_only, 1, 3), access (read_only, 2, 3))) void *memcpy(void *dest, const void *src, size_t n);
__attribute__ ((access (write_only, 1, 3))) void *memset(void *s, int c, size_t n);
char *itoa(long long int value, char *str, int base);
int atoi(const char *str);
void reverse(char s[]);
int strlen(const char s[]);
unsigned int strnlen(const char *s, size_t count);
__attribute__ ((access (read_only, 1, 2))) unsigned int strnlen(const char *s, size_t count);
int strcmp(const char s1[], const char s2[]);
char *strzcpy(char *dst, const char *src, int len);
__attribute__ ((access (read_only, 2), access (write_only, 1, 3))) char *strzcpy(char *dst, const char *src, int len);
int puts(const char *str);
int putc(const char str);
int vsnprintf(char *str, size_t size, const char *format, va_list ap);

View File

@ -496,6 +496,10 @@ void testRingBuffer()
void run_test(void)
{
// Example of checking thx to access attributs
//int a[4] = {0};
//int b[3] = {0};
//memcpy(b, a, sizeof(a));
uint freemem, usedmem;
uint afterFreemem, afterUsedmem;