MCPcopy Create free account
hub / github.com/coreutils/coreutils / find_field_delim

Function find_field_delim

src/cut.c:577–622  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

575 and must have room for a trailing NUL byte at BUF[LEN]. */
576
577ATTRIBUTE_PURE
578static char *
579find_field_delim (char *buf, size_t len)
580{
581 if (len < delim_mcel.len)
582 return NULL;
583
584#if ! __GLIBC__ /* Only S390 has optimized memmem on glibc-2.42 */
585 return memmem (buf, len, delim_bytes, delim_mcel.len);
586#else
587 if (delim_mcel.len == 1)
588 return memchr (buf, delim_bytes[0], len);
589
590 char const *p = buf;
591 char const *end = buf + len;
592
593 char saved = buf[len];
594 buf[len] = '\0'; /* for strstr. */
595
596 while (p < end)
597 {
598 char const *nul = memchr (p, '\0', end - p);
599 if (!nul)
600 {
601 char const *match = strstr (p, delim_bytes);
602 buf[len] = saved;
603 return (char *) match;
604 }
605
606 if (p < nul)
607 {
608 char const *match = strstr (p, delim_bytes);
609 if (match)
610 {
611 buf[len] = saved;
612 return (char *) match;
613 }
614 }
615
616 p = nul + 1;
617 }
618
619 buf[len] = saved;
620 return NULL;
621#endif
622}
623
624/* Return the number of trailing bytes in BUF that could be the initial
625 bytes of a delimiter split across buffers. */

Callers 2

find_field_terminatorFunction · 0.85
cut_fields_bytesearchFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected