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 support for strspn and strcspn #33

Closed
sosthene-nitrokey opened this issue Nov 20, 2024 · 2 comments
Closed

Add support for strspn and strcspn #33

sosthene-nitrokey opened this issue Nov 20, 2024 · 2 comments

Comments

@sosthene-nitrokey
Copy link

Hi!

We are developing the bindings for the C library littlefs (littlefs2-sys), and we have to include implementations of strspn and strcspn that are used by littlefs.

A PR made us aware of tinyrlibc, where it would seem to make more sense to have these implementations. Would these fit here?

@Sympatron
Copy link
Contributor

Sympatron commented Nov 20, 2024

I think it would fit very well.
My suggested implementation would be like this:

#[no_mangle]
pub unsafe extern "C" fn strcspn(str1: *const CChar, str2: *const CChar) -> CSizeT {
    let mut count = 0;
    let mut s = str1;

    while *s != 0 {
        if !strchr(str2, *s).is_null() {
            break;
        }
        count += 1;
        s = s.add(1);
    }

    count
}
#[no_mangle]
pub unsafe extern "C" fn strspn(str1: *const CChar, str2: *const CChar) -> CSizeT {
    let mut count = 0;
    let mut s = str1;

    while *s != 0 {
        if strchr(str2, *s).is_null() {
            break;
        }
        count += 1;
        s = s.add(1);
    }

    count
}

@jonathanpallant
Copy link
Collaborator

I'll work on this

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

No branches or pull requests

3 participants