summaryrefslogtreecommitdiff
path: root/src/system.h
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2012-03-01 11:56:41 +0000
committerPádraig Brady <P@draigBrady.com>2012-03-06 23:43:21 +0000
commit4b4a465798a212925670cc4fef7610678d221d69 (patch)
treef0e2bac1736f4294a17e43b874883f0647e2c574 /src/system.h
parent8195165839877eece7984dd08613323e96424cea (diff)
downloadcoreutils-4b4a465798a212925670cc4fef7610678d221d69.tar.xz
maint: refactor copy to use is_nul()
* src/dd.c: Move is_nul() from here to ... * src/system.h: ... here * src/copy.c (sparse_copy): Adjust to use the refactored is_nul()
Diffstat (limited to 'src/system.h')
-rw-r--r--src/system.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/system.h b/src/system.h
index f312f88d0..49cd08a3b 100644
--- a/src/system.h
+++ b/src/system.h
@@ -491,6 +491,27 @@ ptr_align (void const *ptr, size_t alignment)
return (void *) (p1 - (size_t) p1 % alignment);
}
+/* Return whether the buffer consists entirely of NULs.
+ Note the word after the buffer must be non NUL. */
+
+static inline bool _GL_ATTRIBUTE_PURE
+is_nul (const char *buf, size_t bufsize)
+{
+ typedef uintptr_t word;
+
+ /* Find first nonzero *word*, or the word with the sentinel. */
+ word *wp = (word *) buf;
+ while (*wp++ == 0)
+ continue;
+
+ /* Find the first nonzero *byte*, or the sentinel. */
+ char *cp = (char *) (wp - 1);
+ while (*cp++ == 0)
+ continue;
+
+ return cp > buf + bufsize;
+}
+
/* If 10*Accum + Digit_val is larger than the maximum value for Type,
then don't update Accum and return false to indicate it would
overflow. Otherwise, set Accum to that new value and return true.