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
@adriweb
Copy link
Member

adriweb commented Nov 1, 2025

nobody complained and all new tests look good and pass, so merging I guess :P

@adriweb adriweb merged commit 03a410c into master Nov 1, 2025
9 checks passed
@adriweb adriweb deleted the add_strlcat branch November 1, 2025 12:22
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.

2 participants