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
17size_t strlen(const char *str);
18#define strlen(s) __builtin_strlen(s)
19
20char *strcpy(char *dst, const char *src);
21#define strcpy(d, s) __builtin_strcpy(d, s)
22
23char *strncpy(char *dst, const char *src, size_t n);
24#define strncpy(d, s, n) __builtin_strncpy(d, s, n)
25
26int strcmp(const char *s1, const char *s2);
27#define strcmp(s1, s2) __builtin_strcmp(s1, s2)
28
29int strncmp(const char *s1, const char *s2, size_t n);
30#define strncmp(s1, s2, n) __builtin_strncmp(s1, s2, n)
31
32void *memset(void *s, int c, size_t n);
33#define memset(d, c, n) __builtin_memset(d, c, n)
34
35void *memcpy(void *dst, const void *src, size_t n);
36#define memcpy(d, s, n) __builtin_memcpy(d, s, n)
37
38int memcmp(const void *s1, const void *s2, size_t n);
39#define memcmp(s1, s2, n) __builtin_memcmp(s1, s2, n)
40
41size_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)
49int __printf(3, 0)
50 vsnprintf_internal(char *buf, size_t size, const char *fmt, va_list args,
51 unsigned int flags);
52
53static 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
59int __printf(3, 4)
60 snprintf(char *buf, size_t size, const char *fmt, ...);
61
62/* Internal helpers of vsnprintf(), for custom arch formatting. */
63char *fmt_number(char *str, char *end, long long val, unsigned int base,
64 int width, int precision, unsigned int flags);
65char *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. */
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 */
static unsigned int str(void)
Definition: lib.h:366
#define __printf(f, v)
Definition: compiler.h:12
#define max(a, b)
Definition: lib.h:36
size_t strnlen(const char *str, size_t max)
Definition: string.c:13
#define memset(d, c, n)
Definition: libc.h:33
int vsnprintf_internal(char *buf, size_t size, const char *fmt, va_list args, unsigned int flags)
Definition: vsnprintf.c:276
char * fmt_string(char *str, char *end, const char *val, int width, int precision, unsigned int flags)
Definition: vsnprintf.c:171
#define strncmp(s1, s2, n)
Definition: libc.h:30
#define strcpy(d, s)
Definition: libc.h:21
#define strcmp(s1, s2)
Definition: libc.h:27
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
#define strncpy(d, s, n)
Definition: libc.h:24
#define memcmp(s1, s2, n)
Definition: libc.h:39
char * fmt_number(char *str, char *end, long long val, unsigned int base, int width, int precision, unsigned int flags)
Definition: vsnprintf.c:73
#define strlen(s)
Definition: libc.h:18
int snprintf(char *buf, size_t size, const char *fmt,...)
Definition: stdio.c:3
#define memcpy(d, s, n)
Definition: libc.h:36
static int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
Definition: libc.h:54
__builtin_va_list va_list
Definition: stdarg.h:9
Common declarations for all tests.