summaryrefslogtreecommitdiff
path: root/tools/common.h
diff options
context:
space:
mode:
authorVladimir Azarov <avm@intermediate-node.net>2024-11-05 20:24:40 +0100
committerVladimir Azarov <avm@intermediate-node.net>2024-11-05 21:49:55 +0100
commitf777f6a9450d2bd5fc7ec531e6fb69f79942499a (patch)
treedc33cd941f49708274a74548862ba7b133013c55 /tools/common.h
parent3972268b97b789a8212ea9bc7d1b9ce9905a68d8 (diff)
Musl make
Diffstat (limited to 'tools/common.h')
-rw-r--r--tools/common.h125
1 files changed, 117 insertions, 8 deletions
diff --git a/tools/common.h b/tools/common.h
index 43e2dda..4ca27bd 100644
--- a/tools/common.h
+++ b/tools/common.h
@@ -5,24 +5,34 @@
#include <stdarg.h>
+extern int main(int argc, char **argv, char **envp);
+
#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) })
+#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 *debug2str(char *s);
struct str {
char *start;
char *end;
};
+enum {
+ heap_saves_max = 16
+};
+
extern int errno;
extern char *progname;
void exit(int code);
+int chdir(char *path);
int read(int fd, char *buf, int len);
int write(int fd, char *buf, int len);
#define O_RDONLY 0
+#define O_DIRECTORY 0200000
int open(char *fname, int flags, int mode);
@@ -60,6 +70,34 @@ struct stat {
int stat(char *fname, struct stat *st);
int fstat(int fd, struct stat *st);
+struct dir {
+ int fd;
+
+ char *buf;
+ char *cur;
+ char *end;
+
+ char *path;
+};
+
+struct dirent {
+ unsigned long inode;
+ unsigned long offset;
+ unsigned short dsize;
+ unsigned char type;
+ char name[1];
+};
+
+int opendir(struct dir *dir, char *path);
+struct dirent *readdir(struct dir *dir);
+void closedir(struct dir *dir);
+
+#define F_OK 0
+
+int access(char *path, int mode);
+
+int dup2(int oldfd, int newfd);
+int pipe(int *fds);
int close(int fd);
#define MAP_PRIVATE 0x02
@@ -76,8 +114,46 @@ 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 *mremap(void *old_addr, unsigned long old_size,
+ unsigned long new_size, int flags, void *new_addr);
+
+int fork();
+
+#define WIFEXITED(s) (!WTERMSIG(s))
+#define WEXITSTATUS(s) (((s) >> 8) & 0xff)
+#define WIFSIGNALED(s) (((s) & 0xffff) -1 < 0xff)
+#define WTERMSIG(s) ((s) & 0x7f)
+
+int wait4(int pid, int *wstatus, int options, void *rusage);
+int execve(char *path, char **argv, char **envp);
+
+struct timeval {
+ unsigned long long sec;
+ unsigned long long msec;
+};
+
+struct rusage {
+ struct timeval utime;
+ struct timeval stime;
+ long maxrss;
+ long ixrss;
+ long idrss;
+ long isrss;
+ long minflt;
+ long majflt;
+ long nswap;
+ long inblock;
+ long oublock;
+ long msgsnd;
+ long msgrcv;
+ long nsignals;
+ long nvcsw;
+ long nivcsw;
+};
+
+#define RUSAGE_SELF 0
+
+int getrusage(int who, struct rusage *rusage);
void hexit(int code);
@@ -90,19 +166,52 @@ 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 error(char *fmt, ...);
+
+struct arena;
+
+typedef void arena_grow_func(struct arena *a, int size);
+
+struct arena {
+ char *start;
+ char *cur;
+ char *end;
-void save_heap_offset();
-void restore_heap_offset();
+ arena_grow_func *grow;
+};
+
+struct heap {
+ struct arena a;
+
+ char *saved[heap_saves_max];
+ int snum;
+
+ char *last_alloc;
+};
+
+extern struct heap heap;
+
+void heap_offset_save();
+void heap_offset_remove();
+void heap_offset_restore();
+
+void *mem_alloc(int size);
+void *amalloc(struct arena *a, int size);
void *malloc(int size);
+void realloc(void *p, int newsize);
int strzlen(char *s);
int strzeq(char *s1, char *s2);
int streq(struct str *s1, struct str *s2);
+int strge(struct str *s1, struct str *s2);
+void flush(struct iobuf *buf);
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 memcpy(void *restrict dest, void *restrict src, int len);
void memset(void *dest, char c, int len);
+int memeq(void *m1, void *m2, int len);
+
#endif