root readme, directory structure, and copyright headers
[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 #else
34
35 int atoi(const char *str);
36 long atol(const char *str);
37 long strtol(const char *str, char **endp, int base);
38
39 void *memset(void *s, int c, unsigned long n);
40 void *memcpy(void *dest, const void *src, unsigned long n);
41 void *memmove(void *dest, const void *src, unsigned long n);
42 unsigned long strlen(const char *s);
43 char *strchr(const char *s, int c);
44 int strcmp(const char *s1, const char *s2);
45 char *strcpy(char *dest, const char *src);
46
47 #ifdef __GNUC__
48 typedef __builtin_va_list va_list;
49 #define va_start(v,l)   __builtin_va_start(v,l)
50 #define va_end(v)               __builtin_va_end(v)
51 #define va_arg(v,l)             __builtin_va_arg(v,l)
52 #else   /* !def __GNUC__ */
53 #error "stdargs implementation for this compiler missing (libvisor/src/vilibc.h)"
54 #endif
55
56 int sprintf(char *buf, const char *fmt, ...);
57 int vsprintf(char *buf, const char *fmt, va_list ap);
58 int snprintf(char *buf, unsigned long sz, const char *fmt, ...);
59 int vsnprintf(char *buf, unsigned long sz, const char *fmt, va_list ap);
60
61 int isalnum(int c);
62 int isalpha(int c);
63 #define isascii(c)      ((c) < 128)
64 int isblank(int c);
65 int isdigit(int c);
66 int isupper(int c);
67 int islower(int c);
68 int isprint(int c);
69 int isspace(int c);
70
71 int toupper(int c);
72 int tolower(int c);
73
74 #endif  /* !HAVE_LIBC */
75
76 struct visor;
77 void vi_error(struct visor *vi, const char *fmt, ...);
78
79 #endif  /* VISOR_LIBC_H_ */