memchr (with a small amount of shell native code ending in memcpy ) is the exact equivalent - for example, fgets it takes the maximum length that it will process (should be min the remaining input buffer the size and size of your output buffer) and scans until until it reaches the desired character (which will be '\n' ) or ends outside of the I / O space.
Note that for data already in the buffer in memory, you can skip the step of copying to a separate output buffer, unless you need to end output zero without changing the input. Many novice C programmers often make the mistake of thinking that they need zero completion when it would be quite simple to improve some of your interfaces in order to take a pair (pointer, length) that allows you to pass / process substrings without copying them. For example, you can pass them to printf using: printf("%.*s", (int)length, start);
source share