From e76a30d1c523d6d0a53b4469119a6ac935e14797 Mon Sep 17 00:00:00 2001 From: Julian Barathieu Date: Fri, 28 Dec 2018 22:16:22 +0100 Subject: [PATCH] Stuff --- src/kaleid/common/lib/string.c | 11 +++++++---- src/kaleid/common/string.h | 18 ++++++++++-------- src/kaleid/common/sub/memory.c | 2 -- src/kaleid/linux/test-common.c | 16 ++++++++++------ 4 files changed, 27 insertions(+), 20 deletions(-) diff --git a/src/kaleid/common/lib/string.c b/src/kaleid/common/lib/string.c index 89cf625..464ff2e 100644 --- a/src/kaleid/common/lib/string.c +++ b/src/kaleid/common/lib/string.c @@ -40,8 +40,8 @@ char *strncpy(char *dest, const char *src, size_t n) { size_t it; - for (it = 0; it < n && src[it]; i++) { - dest[it] = src[i]; + for (it = 0; it < n && src[it]; it++) { + dest[it] = src[it]; } while (it < n) dest[it++] = 0; @@ -53,11 +53,14 @@ char *strncpy(char *dest, const char *src, size_t n) // char *strrev(char *dest, const char *src) { - size_t m = 0, n = strlen(src); + char *orig = dest; + size_t n = strlen(src); dest[n--] = '\0'; - while (n) dest[m++] = src[n--]; + while ((*dest++ = src[n--])); + + return orig; } // diff --git a/src/kaleid/common/string.h b/src/kaleid/common/string.h index be51281..61056be 100644 --- a/src/kaleid/common/string.h +++ b/src/kaleid/common/string.h @@ -21,21 +21,23 @@ #ifndef _OSK_SOURCE -# define strlen _osk_strlen -# define strcpy _osk_strcpy -# define strncpy _osk_strncpy -# define reverse _osk_reverse +# define strlen _osk_strlen +# define strcpy _osk_strcpy +# define strncpy _osk_strncpy +# define strrev _osk_strrev +# define reverse _osk_reverse -# define sprintf _osk_sprintf -# define snprintf _osk_snprintf -# define vsprintf _osk_vsprintf -# define vsnprintf _osk_vsnprintf +# define sprintf _osk_sprintf +# define snprintf _osk_snprintf +# define vsprintf _osk_vsprintf +# define vsnprintf _osk_vsnprintf #endif size_t strlen(const char *); char *strcpy(char *, const char *); char *strncpy(char *, const char *, size_t); +char *strrev(char *dest, const char *src); char *reverse(char *); int sprintf(char *, const char *, ...); diff --git a/src/kaleid/common/sub/memory.c b/src/kaleid/common/sub/memory.c index 06407b9..aaecb6b 100644 --- a/src/kaleid/common/sub/memory.c +++ b/src/kaleid/common/sub/memory.c @@ -34,8 +34,6 @@ static inline void *memsetq(void *ptr, ullong uval, size_t qwords) // // Set "bytes"-many bytes starting from ptr to val -// This is most certainely overkill, but I enjoyed doing this -// Alignment stuff barely matters on modern processors // void *memset(void *ptr, int val, size_t bytes) { diff --git a/src/kaleid/linux/test-common.c b/src/kaleid/linux/test-common.c index d9b3aec..edae890 100644 --- a/src/kaleid/linux/test-common.c +++ b/src/kaleid/linux/test-common.c @@ -36,20 +36,24 @@ int main(int argc, char *argv[]) //printf("%p\n",xxx); //memset(xxx, 'x', sizex); - const char *str = "ceci est un string de test\n"; + const char *str = "ceci est un string de test!"; char *str2 = malloc((strlen(str) + 3) * sizeof(char)); + char *str3 = malloc((strlen(str) + 3) * sizeof(char)); strcpy(str2, str); - size_t s = strlen(str2); + //size_t s = strlen(str2); - printf(reverse(reverse(str2))); + strrev(str3,str2); + printf("%lu - %s\n", strlen(str3), str3); - str2[s] = '\n'; - str2[s+1] = '\0'; - printf(reverse(reverse(str2))); + //str2[s] = '\n'; + //str2[s+1] = '\0'; + strrev(str2,str3); + printf("%lu - %s\n", strlen(str2), str2); free(str2); + free(str3); /*size_t it; for (it = 0; it < sizex; it++) {