Skip to content

Conversation

@ZERICO2005
Copy link
Contributor

@ZERICO2005 ZERICO2005 commented Oct 5, 2025

Implements other common POSIX/GNU/BSD functions: strlcat, stpncpy, memmem, memrmem, strrstr, and strchrnul.

This implementation of memmem has a time complexity of O(N^2) although O(N) algorithms do exist. The worst cases only arise when looking for "az" in "abacadaeafag...". In general, the maximum calls to memcmp is proportional to the number of times that the first character of needle (in this case a) appears in haystack.

stpncpy is faster than strncpy at zero padding dst. I implemented the zero padding with lddr (1R + 1W + 1 per \0) whereas strncpy uses a 6F + 1R + 1W + 1 per \0 loop https://github.com/pcawte/AgDev/blob/main/src/libc/strncpy.src

@ZERICO2005 ZERICO2005 marked this pull request as ready for review October 5, 2025 23:59
@ZERICO2005 ZERICO2005 changed the title Implemented strlcat Implemented strlcat and stpncpy Oct 8, 2025
@ZERICO2005 ZERICO2005 changed the title Implemented strlcat and stpncpy Implemented strlcat, stpncpy, memmem, and strchrnul Oct 14, 2025
@ZERICO2005 ZERICO2005 changed the title Implemented strlcat, stpncpy, memmem, and strchrnul Implemented strlcat, stpncpy, mem(r)mem, and strchrnul Oct 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

1 participant