diff options
Diffstat (limited to 'tools/common.h')
-rw-r--r-- | tools/common.h | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/tools/common.h b/tools/common.h new file mode 100644 index 0000000..43e2dda --- /dev/null +++ b/tools/common.h @@ -0,0 +1,108 @@ +#ifndef COMMON_H +#define COMMON_H + +#include <bits/errno.h> + +#include <stdarg.h> + +#define NULL ((void *)0) +#define _S(s) s, (sizeof(s) - 1) +#define CSTR(s) ((struct str) { s, s + sizeof(s) - 1 }) +#define STR(s) ((struct str) { s, s + strzlen(s) }) + +struct str { + char *start; + char *end; +}; + +extern int errno; +extern char *progname; + +void exit(int code); +int read(int fd, char *buf, int len); +int write(int fd, char *buf, int len); + +#define O_RDONLY 0 + +int open(char *fname, int flags, int mode); + +/* + * Taken from linux/arch/x86/include/uapi/asm/stat.h + * Matches arch/x86_64/bits/stat.h + */ + +struct time { + unsigned long sec; + unsigned long usec; +}; + +struct stat { + unsigned long dev; + unsigned long ino; + unsigned long nlink; + + unsigned int mode; + unsigned int uid; + unsigned int gid; + unsigned int __pad0; + + unsigned long rdev; + unsigned long size; + unsigned long blksize; + unsigned long blocks; + + struct time atime; + struct time mtime; + struct time ctime; + long __unused[3]; +}; + +int stat(char *fname, struct stat *st); +int fstat(int fd, struct stat *st); + +int close(int fd); + +#define MAP_PRIVATE 0x02 +#define MAP_ANON 0x20 + +#define PROT_NONE 0 +#define PROT_READ 1 +#define PROT_WRITE 2 +#define PROT_EXEC 4 + +void *mmap(char *addr, unsigned long length, int prot, int flags, int fd, + unsigned long offset); +int munmap(char *addr, int length); + +#define MREMAP_MAYMOVE 1 + +int mremap(void *old_addr, unsigned long old_size, unsigned long new_size, + int flags, void *new_addr); + +void hexit(int code); + +extern struct iobuf stdout; +extern struct iobuf stderr; + +void print_strz(struct iobuf *buf, char *s); +void print_str(struct iobuf *buf, struct str *s); + +void printf(char *fmt, ...); +void eprintf(char *fmt, ...); +void evprintf(char *fmt, va_list vl); + +void save_heap_offset(); +void restore_heap_offset(); +void *malloc(int size); + +int strzlen(char *s); +int strzeq(char *s1, char *s2); + +int streq(struct str *s1, struct str *s2); +void perror(char *s); +void syscall_error(char *fname); + +void memmove(char *dest, char *src, int len); +void memcpy(void *dest, void *src, int len); +void memset(void *dest, char c, int len); +#endif |