Fix i686-pc-cygwin build failure.
[official-gcc.git] / libsanitizer / sanitizer_common / sanitizer_libc.h
blobd26ec8704c0832daebb9333b283b34427e358f2a
1 //===-- sanitizer_libc.h ----------------------------------------*- C++ -*-===//
2 //
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
5 //
6 //===----------------------------------------------------------------------===//
7 //
8 // This file is shared between AddressSanitizer and ThreadSanitizer
9 // run-time libraries.
10 // These tools can not use some of the libc functions directly because those
11 // functions are intercepted. Instead, we implement a tiny subset of libc here.
12 // FIXME: Some of functions declared in this file are in fact POSIX, not libc.
13 //===----------------------------------------------------------------------===//
15 #ifndef SANITIZER_LIBC_H
16 #define SANITIZER_LIBC_H
18 // ----------- ATTENTION -------------
19 // This header should NOT include any other headers from sanitizer runtime.
20 #include "sanitizer_internal_defs.h"
22 namespace __sanitizer {
24 // internal_X() is a custom implementation of X() for use in RTL.
26 // String functions
27 s64 internal_atoll(const char *nptr);
28 void *internal_memchr(const void *s, int c, uptr n);
29 void *internal_memrchr(const void *s, int c, uptr n);
30 int internal_memcmp(const void* s1, const void* s2, uptr n);
31 void *internal_memcpy(void *dest, const void *src, uptr n);
32 void *internal_memmove(void *dest, const void *src, uptr n);
33 // Set [s, s + n) to 0. Both s and n should be 16-aligned.
34 void internal_bzero_aligned16(void *s, uptr n);
35 // Should not be used in performance-critical places.
36 void *internal_memset(void *s, int c, uptr n);
37 char* internal_strchr(const char *s, int c);
38 char *internal_strchrnul(const char *s, int c);
39 int internal_strcmp(const char *s1, const char *s2);
40 uptr internal_strcspn(const char *s, const char *reject);
41 char *internal_strdup(const char *s);
42 char *internal_strndup(const char *s, uptr n);
43 uptr internal_strlen(const char *s);
44 uptr internal_strlcat(char *dst, const char *src, uptr maxlen);
45 char *internal_strncat(char *dst, const char *src, uptr n);
46 int internal_strncmp(const char *s1, const char *s2, uptr n);
47 uptr internal_strlcpy(char *dst, const char *src, uptr maxlen);
48 char *internal_strncpy(char *dst, const char *src, uptr n);
49 uptr internal_strnlen(const char *s, uptr maxlen);
50 char *internal_strrchr(const char *s, int c);
51 // This is O(N^2), but we are not using it in hot places.
52 uptr internal_wcslen(const wchar_t *s);
53 char *internal_strstr(const char *haystack, const char *needle);
54 // Works only for base=10 and doesn't set errno.
55 s64 internal_simple_strtoll(const char *nptr, char **endptr, int base);
56 int internal_snprintf(char *buffer, uptr length, const char *format, ...);
58 // Return true if all bytes in [mem, mem+size) are zero.
59 // Optimized for the case when the result is true.
60 bool mem_is_zero(const char *mem, uptr size);
62 // I/O
63 // Define these as macros so we can use them in linker initialized global
64 // structs without dynamic initialization.
65 #define kInvalidFd ((fd_t)-1)
66 #define kStdinFd ((fd_t)0)
67 #define kStdoutFd ((fd_t)1)
68 #define kStderrFd ((fd_t)2)
70 uptr internal_ftruncate(fd_t fd, uptr size);
72 // OS
73 void NORETURN internal__exit(int exitcode);
74 unsigned int internal_sleep(unsigned int seconds);
76 uptr internal_getpid();
77 uptr internal_getppid();
79 // Threading
80 uptr internal_sched_yield();
82 // Error handling
83 bool internal_iserror(uptr retval, int *rverrno = nullptr);
85 } // namespace __sanitizer
87 #endif // SANITIZER_LIBC_H