Author: Guillaume Chatelet Date: 2021-01-19T08:12:38Z New Revision: e517dff50a4f933d0729026901b14c7c1112a359
URL: https://github.com/llvm/llvm-project/commit/e517dff50a4f933d0729026901b14c7c1112a359 DIFF: https://github.com/llvm/llvm-project/commit/e517dff50a4f933d0729026901b14c7c1112a359.diff LOG: [libc][NFC] remove dependency on non standard ssize_t `ssize_t` is from POSIX and is not standard unfortunately. Rewritting the code so it doesn't depend on it. Differential Revision: https://reviews.llvm.org/D94760 Added: Modified: libc/src/string/memmove.cpp Removed: ################################################################################ diff --git a/libc/src/string/memmove.cpp b/libc/src/string/memmove.cpp index 8958027d1d58..0d4d3d174839 100644 --- a/libc/src/string/memmove.cpp +++ b/libc/src/string/memmove.cpp @@ -11,21 +11,25 @@ #include "src/stdlib/abs_utils.h" #include "src/string/memcpy.h" #include <stddef.h> // size_t, ptr diff _t -#include <unistd.h> // ssize_t namespace __llvm_libc { -// src_m and dest_m might be the beginning or end. -static inline void move_byte(unsigned char *dest_m, const unsigned char *src_m, - size_t count, ssize_t direction) { - for (ssize_t offset = 0; count; --count, offset += direction) +static inline void move_byte_forward(char *dest_m, const char *src_m, + size_t count) { + for (size_t offset = 0; count; --count, ++offset) + dest_m[offset] = src_m[offset]; +} + +static inline void move_byte_backward(char *dest_m, const char *src_m, + size_t count) { + for (size_t offset = count - 1; count; --count, --offset) dest_m[offset] = src_m[offset]; } LLVM_LIBC_FUNCTION(void *, memmove, (void *dest, const void *src, size_t count)) { - unsigned char *dest_c = reinterpret_cast<unsigned char *>(dest); - const unsigned char *src_c = reinterpret_cast<const unsigned char *>(src); + char *dest_c = reinterpret_cast<char *>(dest); + const char *src_c = reinterpret_cast<const char *>(src); // If the distance between src_c and dest_c is equal to or greater // than count (integer_abs(src_c - dest_c) >= count), they would not overlap. @@ -50,11 +54,11 @@ LLVM_LIBC_FUNCTION(void *, memmove, // src_c : [___abcde_] [_abcde___] // dest_c: [_abc--___] [___--cde_] - // TODO: Optimize `move_byte(...)` function. + // TODO: Optimize `move_byte_xxx(...)` functions. if (dest_c < src_c) - move_byte(dest_c, src_c, count, /*pointer add*/ 1); + move_byte_forward(dest_c, src_c, count); if (dest_c > src_c) - move_byte(dest_c + count - 1, src_c + count - 1, count, /*pointer add*/ -1); + move_byte_backward(dest_c, src_c, count); return dest; } _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits