sanitizer_libc.cc revision 94b5036ee6ba866e1702848855b6d687d1e70afa
1cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com//===-- sanitizer_libc.cc -------------------------------------------------===//
2cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com//
3cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com//                     The LLVM Compiler Infrastructure
4cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com//
5cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com// This file is distributed under the University of Illinois Open Source
6cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com// License. See LICENSE.TXT for details.
7cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com//
8cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com//===----------------------------------------------------------------------===//
9cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com//
108cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com// This file is shared between AddressSanitizer and ThreadSanitizer
118cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com// run-time libraries. See sanitizer_libc.h for details.
128cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com//===----------------------------------------------------------------------===//
138cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#include "sanitizer_internal_defs.h"
148cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#include "sanitizer_libc.h"
158cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
168cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comnamespace __sanitizer {
178cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
188cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comvoid MiniLibcStub() {
198cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com}
208cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
218cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comvoid *internal_memchr(const void *s, int c, uptr n) {
228cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  const char* t = (char*)s;
238cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  for (uptr i = 0; i < n; ++i, ++t)
248cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    if (*t == c)
258cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com      return (void*)t;
268cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  return 0;
278cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com}
288cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
298cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comint internal_strcmp(const char *s1, const char *s2) {
308cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  while (true) {
318cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    unsigned c1 = *s1;
328cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    unsigned c2 = *s2;
338cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    if (c1 != c2) return (c1 < c2) ? -1 : 1;
348cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    if (c1 == 0) break;
358cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    s1++;
368cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    s2++;
378cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  }
388cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  return 0;
398cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com}
408cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
418cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comchar *internal_strncpy(char *dst, const char *src, uptr n) {
428cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  uptr i;
438cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  for (i = 0; i < n && src[i]; i++)
448cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    dst[i] = src[i];
458cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  for (; i < n; i++)
468cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    dst[i] = '\0';
478cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  return dst;
488cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com}
498cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
508cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com}  // namespace __sanitizer
518cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com