-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add more string.h
functions
#139
Conversation
libsrc/string/memccpy.c
Outdated
void *memccpy(void *dst, const void *src, int c, size_t n) { | ||
void *b = memchr(src, c, n); | ||
if (b != NULL) | ||
n = b - src; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is my mistake, but the compiler should warn about subtraction between two void
pointers.
(gcc -pedantic
says error: arithmetic on pointers to void is a GNU extension [-Werror,-Wgnu-pointer-arith]
)
Could you cast these pointers to char*
before subtraction?
libsrc/string/strerror.c
Outdated
}; | ||
|
||
char *strerror(int no) { | ||
if (no < 0 || no > sizeof(strerrors) / sizeof(*strerrors)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
>=
?
libsrc/string/strcpy.c
Outdated
; | ||
return os; | ||
stpcpy(dst, src); | ||
return dst; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you leave this function unchanged?
Because I think stpcpy
is more minor.
libsrc/string/strncpy.c
Outdated
; | ||
return os; | ||
stpncpy(dst, src, n); | ||
return dst; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you leave this function unchanged?
2446fab
to
231b119
Compare
Thank you for the changes. |
I haven’t tested them thoroughly, but at least
strtok
seems to be working fine.I want to work on more libc functions later, but I figured I should start with something simple to begin with!
If you find any mistakes, please let me know, and I can correct them!