split and span mess
[visor] / libvisor / src / vilibc.h
1 /*
2 visor - lightweight system-independent embeddable text editor framework
3 Copyright (C)  2019 John Tsiombikas <nuclear@member.fsf.org>
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program.  If not, see <https://www.gnu.org/licenses/>.
17 */
18 #ifndef VISOR_LIBC_H_
19 #define VISOR_LIBC_H_
20
21 /* XXX let's pretend we don't have a libc to test our own code
22 #ifdef __STDC_HOSTED__
23 #define HAVE_LIBC
24 #endif
25 */
26
27 #ifdef HAVE_LIBC
28 #include <stdlib.h>
29 #include <string.h>
30 #include <stdarg.h>
31 #include <ctype.h>
32 #include <limit.h>
33 #include <assert.h>
34 #else
35
36 int atoi(const char *str);
37 long atol(const char *str);
38 long strtol(const char *str, char **endp, int base);
39
40 void *memset(void *s, int c, unsigned long n);
41 void *memcpy(void *dest, const void *src, unsigned long n);
42 void *memmove(void *dest, const void *src, unsigned long n);
43 unsigned long strlen(const char *s);
44 char *strchr(const char *s, int c);
45 int strcmp(const char *s1, const char *s2);
46 char *strcpy(char *dest, const char *src);
47
48 #ifdef __GNUC__
49 typedef __builtin_va_list va_list;
50 #define va_start(v,l)   __builtin_va_start(v,l)
51 #define va_end(v)               __builtin_va_end(v)
52 #define va_arg(v,l)             __builtin_va_arg(v,l)
53 #else   /* !def __GNUC__ */
54 #error "stdargs implementation for this compiler missing (libvisor/src/vilibc.h)"
55 #endif
56
57 int sprintf(char *buf, const char *fmt, ...);
58 int vsprintf(char *buf, const char *fmt, va_list ap);
59 int snprintf(char *buf, unsigned long sz, const char *fmt, ...);
60 int vsnprintf(char *buf, unsigned long sz, const char *fmt, va_list ap);
61
62 int isalnum(int c);
63 int isalpha(int c);
64 #define isascii(c)      ((c) < 128)
65 int isblank(int c);
66 int isdigit(int c);
67 int isupper(int c);
68 int islower(int c);
69 int isprint(int c);
70 int isspace(int c);
71
72 int toupper(int c);
73 int tolower(int c);
74
75 #define assert(x)
76
77 #endif  /* !HAVE_LIBC */
78
79 struct visor;
80 void vi_error(struct visor *vi, const char *fmt, ...);
81
82 #endif  /* VISOR_LIBC_H_ */