Skip to content
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

Merged
merged 1 commit into from
Feb 24, 2024
Merged

Conversation

ghost
Copy link

@ghost ghost commented Feb 23, 2024

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!

@tyfkda tyfkda self-requested a review February 24, 2024 02:47
void *memccpy(void *dst, const void *src, int c, size_t n) {
void *b = memchr(src, c, n);
if (b != NULL)
n = b - src;
Copy link
Owner

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?

};

char *strerror(int no) {
if (no < 0 || no > sizeof(strerrors) / sizeof(*strerrors))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

>= ?

;
return os;
stpcpy(dst, src);
return dst;
}
Copy link
Owner

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.

;
return os;
stpncpy(dst, src, n);
return dst;
}
Copy link
Owner

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?

@ghost ghost force-pushed the more-string-functions branch from 2446fab to 231b119 Compare February 24, 2024 13:54
@tyfkda
Copy link
Owner

tyfkda commented Feb 24, 2024

Thank you for the changes.

@tyfkda tyfkda merged commit f5a6438 into tyfkda:main Feb 24, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants