[libc-commits] [libc] 8a55daf - [libc][NFC] introduce inline_bzero

Guillaume Chatelet via libc-commits libc-commits at lists.llvm.org
Mon Sep 26 05:36:31 PDT 2022


Author: Guillaume Chatelet
Date: 2022-09-26T12:34:10Z
New Revision: 8a55dafdd0952529cbf9a03116035d1b0403e7ea

URL: https://github.com/llvm/llvm-project/commit/8a55dafdd0952529cbf9a03116035d1b0403e7ea
DIFF: https://github.com/llvm/llvm-project/commit/8a55dafdd0952529cbf9a03116035d1b0403e7ea.diff

LOG: [libc][NFC] introduce inline_bzero

Added: 
    

Modified: 
    libc/src/string/bzero.cpp
    libc/src/string/memory_utils/memset_implementations.h
    libc/src/string/stpncpy.cpp
    libc/src/string/string_utils.h

Removed: 
    


################################################################################
diff  --git a/libc/src/string/bzero.cpp b/libc/src/string/bzero.cpp
index c57c922f6eff6..f852089507ded 100644
--- a/libc/src/string/bzero.cpp
+++ b/libc/src/string/bzero.cpp
@@ -13,7 +13,7 @@
 namespace __llvm_libc {
 
 LLVM_LIBC_FUNCTION(void, bzero, (void *ptr, size_t count)) {
-  inline_memset(reinterpret_cast<char *>(ptr), 0, count);
+  inline_bzero(reinterpret_cast<char *>(ptr), count);
 }
 
 } // namespace __llvm_libc

diff  --git a/libc/src/string/memory_utils/memset_implementations.h b/libc/src/string/memory_utils/memset_implementations.h
index f1611a32807cb..f63cb787267be 100644
--- a/libc/src/string/memory_utils/memset_implementations.h
+++ b/libc/src/string/memory_utils/memset_implementations.h
@@ -133,6 +133,10 @@ inline static void inline_memset(char *dst, unsigned char value, size_t count) {
 #endif
 }
 
+inline static void inline_bzero(char *dst, size_t count) {
+  inline_memset(dst, 0, count);
+}
+
 } // namespace __llvm_libc
 
 #endif // LLVM_LIBC_SRC_STRING_MEMORY_UTILS_MEMSET_IMPLEMENTATIONS_H

diff  --git a/libc/src/string/stpncpy.cpp b/libc/src/string/stpncpy.cpp
index 25e916251bad8..127012c4c9efe 100644
--- a/libc/src/string/stpncpy.cpp
+++ b/libc/src/string/stpncpy.cpp
@@ -22,7 +22,7 @@ LLVM_LIBC_FUNCTION(char *, stpncpy,
     dest[i] = src[i];
   // When n>strlen(src), n-strlen(src) \0 are appended.
   if (n > i)
-    inline_memset(dest + i, 0, n - i);
+    inline_bzero(dest + i, n - i);
   return dest + i;
 }
 

diff  --git a/libc/src/string/string_utils.h b/libc/src/string/string_utils.h
index 708475e4e97f5..e94c28b383077 100644
--- a/libc/src/string/string_utils.h
+++ b/libc/src/string/string_utils.h
@@ -94,7 +94,7 @@ static inline size_t strlcpy(char *__restrict dst, const char *__restrict src,
     return len;
   size_t n = len < size - 1 ? len : size - 1;
   inline_memcpy(dst, src, n);
-  inline_memset(dst + n, 0, size - n);
+  inline_bzero(dst + n, size - n);
   return len;
 }
 


        


More information about the libc-commits mailing list