Xen Test Framework
libc.h
Go to the documentation of this file.
1 #ifndef XTF_LIBC_H
2 #define XTF_LIBC_H
3 
4 #include <xtf/types.h>
5 #include <xtf/compiler.h>
6 
7 /*
8  * Local declaration of bits of libc
9  *
10  * Use __builtin_???() wherever possible, to allow gcc to perform certain
11  * optimisations (e.g. constant folding) otherwise prevented by -fno-builtin.
12  *
13  * Where optimisations are not possible, the __builtin_???() varient will emit
14  * a call to ???(), which needs implementing in common/libc/
15  */
16 
17 size_t strlen(const char *str);
18 #define strlen(s) __builtin_strlen(s)
19 
20 char *strcpy(char *dst, const char *src);
21 #define strcpy(d, s) __builtin_strcpy(d, s)
22 
23 char *strncpy(char *dst, const char *src, size_t n);
24 #define strncpy(d, s, n) __builtin_strncpy(d, s, n)
25 
26 int strcmp(const char *s1, const char *s2);
27 #define strcmp(s1, s2) __builtin_strcmp(s1, s2)
28 
29 int strncmp(const char *s1, const char *s2, size_t n);
30 #define strncmp(s1, s2, n) __builtin_strncmp(s1, s2, n)
31 
32 void *memset(void *s, int c, size_t n);
33 #define memset(d, c, n) __builtin_memset(d, c, n)
34 
35 void *memcpy(void *dst, const void *src, size_t n);
36 #define memcpy(d, s, n) __builtin_memcpy(d, s, n)
37 
38 int memcmp(const void *s1, const void *s2, size_t n);
39 #define memcmp(s1, s2, n) __builtin_memcmp(s1, s2, n)
40 
41 size_t strnlen(const char *str, size_t max);
42 
43 /*
44  * Internal version of vsnprintf(), taking extra control flags.
45  *
46  * LF_TO_CRLF causes "\n" to be expanded to "\r\n" in the output buffer.
47  */
48 #define LF_TO_CRLF (1u << 7)
49 int __printf(3, 0)
50  vsnprintf_internal(char *buf, size_t size, const char *fmt, va_list args,
51  unsigned int flags);
52 
53 static inline int __printf(3, 0)
54  vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
55 {
56  return vsnprintf_internal(buf, size, fmt, args, 0);
57 }
58 
59 int __printf(3, 4)
60  snprintf(char *buf, size_t size, const char *fmt, ...);
61 
62 /* Internal helpers of vsnprintf(), for custom arch formatting. */
63 char *fmt_number(char *str, char *end, long long val, unsigned int base,
64  int width, int precision, unsigned int flags);
65 char *fmt_string(char *str, char *end, const char *val,
66  int width, int precision, unsigned int flags);
67 
68 /* Arch hook for vsnprintf() custom %p handling. */
69 bool arch_fmt_pointer(
70  char **str, char *end, const char **fmt_ptr, const void *arg,
71  int width, int precision, unsigned int flags);
72 
73 #endif /* XTF_LIBC_H */
74 
75 /*
76  * Local variables:
77  * mode: C
78  * c-file-style: "BSD"
79  * c-basic-offset: 4
80  * tab-width: 4
81  * indent-tabs-mode: nil
82  * End:
83  */
Common declarations for all tests.
#define strlen(s)
Definition: libc.h:18
#define max(a, b)
Definition: lib.h:36
bool arch_fmt_pointer(char **str, char *end, const char **fmt_ptr, const void *arg, int width, int precision, unsigned int flags)
Definition: decode.c:91
static int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
Definition: libc.h:54
int vsnprintf_internal(char *buf, size_t size, const char *fmt, va_list args, unsigned int flags)
Definition: vsnprintf.c:276
#define strncmp(s1, s2, n)
Definition: libc.h:30
#define memcpy(d, s, n)
Definition: libc.h:36
#define memset(d, c, n)
Definition: libc.h:33
char * fmt_number(char *str, char *end, long long val, unsigned int base, int width, int precision, unsigned int flags)
Definition: vsnprintf.c:73
static unsigned int str(void)
Definition: lib.h:366
#define strncpy(d, s, n)
Definition: libc.h:24
#define strcpy(d, s)
Definition: libc.h:21
#define __printf(f, v)
Definition: compiler.h:12
char * fmt_string(char *str, char *end, const char *val, int width, int precision, unsigned int flags)
Definition: vsnprintf.c:171
#define strcmp(s1, s2)
Definition: libc.h:27
__builtin_va_list va_list
Definition: stdarg.h:9
#define memcmp(s1, s2, n)
Definition: libc.h:39
size_t strnlen(const char *str, size_t max)
Definition: string.c:13
int snprintf(char *buf, size_t size, const char *fmt,...)
Definition: stdio.c:3