sanitizer_libc.cc revision 230c3be6cdd094a187f48e27ba0961dbeee70344
1//===-- sanitizer_libc.cc -------------------------------------------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file is shared between AddressSanitizer and ThreadSanitizer
11// run-time libraries. See sanitizer_libc.h for details.
12//===----------------------------------------------------------------------===//
13#include "sanitizer_internal_defs.h"
14#include "sanitizer_libc.h"
15
16namespace __sanitizer {
17
18void MiniLibcStub() {
19}
20
21void *internal_memchr(const void *s, int c, uptr n) {
22  const char* t = (char*)s;
23  for (uptr i = 0; i < n; ++i, ++t)
24    if (*t == c)
25      return (void*)t;
26  return 0;
27}
28
29int internal_strcmp(const char *s1, const char *s2) {
30  while (true) {
31    unsigned c1 = *s1;
32    unsigned c2 = *s2;
33    if (c1 != c2) return (c1 < c2) ? -1 : 1;
34    if (c1 == 0) break;
35    s1++;
36    s2++;
37  }
38  return 0;
39}
40
41uptr internal_strlen(const char *s) {
42  uptr i = 0;
43  while (s[i]) i++;
44  return i;
45}
46
47char *internal_strncpy(char *dst, const char *src, uptr n) {
48  uptr i;
49  for (i = 0; i < n && src[i]; i++)
50    dst[i] = src[i];
51  for (; i < n; i++)
52    dst[i] = '\0';
53  return dst;
54}
55
56}  // namespace __sanitizer
57