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

Function is_nul

src/system.h:522–569  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

520 Based on memeqzero in CCAN by Rusty Russell under CC0 (Public domain). */
521
522ATTRIBUTE_PURE
523static inline bool
524is_nul (void const *buf, size_t length)
525{
526 const unsigned char *p = buf;
527/* Using possibly unaligned access for the first 16 bytes
528 saves about 30-40 cycles, though it is strictly undefined behavior
529 and so would need __attribute__ ((__no_sanitize_undefined__))
530 to avoid -fsanitize=undefined warnings.
531 Considering coreutils is mainly concerned with relatively
532 large buffers, we'll just use the defined behavior. */
533#if 0 && (_STRING_ARCH_unaligned || _STRING_INLINE_unaligned)
534 unsigned long word;
535#else
536 unsigned char word;
537#endif
538
539 if (! length)
540 return true;
541
542 /* Check len bytes not aligned on a word. */
543 while (UNLIKELY (length & (sizeof word - 1)))
544 {
545 if (*p)
546 return false;
547 p++;
548 length--;
549 if (! length)
550 return true;
551 }
552
553 /* Check up to 16 bytes a word at a time. */
554 for (;;)
555 {
556 memcpy (&word, p, sizeof word);
557 if (word)
558 return false;
559 p += sizeof word;
560 length -= sizeof word;
561 if (! length)
562 return true;
563 if (UNLIKELY (length & 15) == 0)
564 break;
565 }
566
567 /* Now we know first 16 bytes are NUL, memeq with self. */
568 return memeq (buf, p, length);
569}
570
571/* Set Accum = 10*Accum + Digit_val and return true, where Accum is an
572 integer object and Digit_val an integer expression. However, if

Callers 2

iwriteFunction · 0.85
sparse_copyFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected