This commit is contained in:
Julian Barathieu 2018-12-28 22:16:22 +01:00
parent b6ea3c20fe
commit e76a30d1c5
4 changed files with 27 additions and 20 deletions

View File

@ -40,8 +40,8 @@ char *strncpy(char *dest, const char *src, size_t n)
{ {
size_t it; size_t it;
for (it = 0; it < n && src[it]; i++) { for (it = 0; it < n && src[it]; it++) {
dest[it] = src[i]; dest[it] = src[it];
} }
while (it < n) dest[it++] = 0; 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) 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'; dest[n--] = '\0';
while (n) dest[m++] = src[n--]; while ((*dest++ = src[n--]));
return orig;
} }
// //

View File

@ -21,21 +21,23 @@
#ifndef _OSK_SOURCE #ifndef _OSK_SOURCE
# define strlen _osk_strlen # define strlen _osk_strlen
# define strcpy _osk_strcpy # define strcpy _osk_strcpy
# define strncpy _osk_strncpy # define strncpy _osk_strncpy
# define reverse _osk_reverse # define strrev _osk_strrev
# define reverse _osk_reverse
# define sprintf _osk_sprintf # define sprintf _osk_sprintf
# define snprintf _osk_snprintf # define snprintf _osk_snprintf
# define vsprintf _osk_vsprintf # define vsprintf _osk_vsprintf
# define vsnprintf _osk_vsnprintf # define vsnprintf _osk_vsnprintf
#endif #endif
size_t strlen(const char *); size_t strlen(const char *);
char *strcpy(char *, const char *); char *strcpy(char *, const char *);
char *strncpy(char *, const char *, size_t); char *strncpy(char *, const char *, size_t);
char *strrev(char *dest, const char *src);
char *reverse(char *); char *reverse(char *);
int sprintf(char *, const char *, ...); int sprintf(char *, const char *, ...);

View File

@ -34,8 +34,6 @@ static inline void *memsetq(void *ptr, ullong uval, size_t qwords)
// //
// Set "bytes"-many bytes starting from ptr to val // 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) void *memset(void *ptr, int val, size_t bytes)
{ {

View File

@ -36,20 +36,24 @@ int main(int argc, char *argv[])
//printf("%p\n",xxx); //printf("%p\n",xxx);
//memset(xxx, 'x', sizex); //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 *str2 = malloc((strlen(str) + 3) * sizeof(char));
char *str3 = malloc((strlen(str) + 3) * sizeof(char));
strcpy(str2, str); 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] = '\n';
str2[s+1] = '\0'; //str2[s+1] = '\0';
printf(reverse(reverse(str2))); strrev(str2,str3);
printf("%lu - %s\n", strlen(str2), str2);
free(str2); free(str2);
free(str3);
/*size_t it; /*size_t it;
for (it = 0; it < sizex; it++) { for (it = 0; it < sizex; it++) {