diff options
Diffstat (limited to 'include/base')
-rw-r--r-- | include/base/fmt.h | 4 | ||||
-rw-r--r-- | include/base/io.h | 8 | ||||
-rw-r--r-- | include/base/memory.h (renamed from include/base/mem.h) | 9 | ||||
-rw-r--r-- | include/base/string.h | 79 |
4 files changed, 56 insertions, 44 deletions
diff --git a/include/base/fmt.h b/include/base/fmt.h index 4c187fd..92e3261 100644 --- a/include/base/fmt.h +++ b/include/base/fmt.h @@ -54,12 +54,12 @@ int fmt·fprint(int fd, char *fmt, ...); void fmt·panic(char *fmt, ...); int fmt·sprint(char *buf, char *fmt, ...); -int fmt·nsprint(int len, char *buf, char *fmt, ...); +int fmt·nsprint(char *buf, int len, char *fmt, ...); char *fmt·esprint(char *buf, char *end, char *fmt, ...); int fmt·vprint(char *fmt, va_list args); int fmt·vfprint(int fd, char *fmt, va_list args); -int fmt·vnsprint(int len, char *buf, char *fmt, va_list args); +int fmt·vnsprint(char *buf, int len, char *fmt, va_list args); char *fmt·vesprint(char *buf, char *end, char *fmt, va_list args); /* low-level interface: used for custom printing verbs */ diff --git a/include/base/io.h b/include/base/io.h index dae57ef..04b596f 100644 --- a/include/base/io.h +++ b/include/base/io.h @@ -61,14 +61,6 @@ typedef struct io·ReadWriter } io·ReadWriter; extern io·ReadWriter sys·ReadWriter; -/* XXX: change casing */ -enum -{ - ReadOK = R_OK, - WriteOK = W_OK, - ExecOK = X_OK, -}; - /* buffered i/o */ typedef struct io·Header io·Header; typedef struct io·Buffer io·Buffer; diff --git a/include/base/mem.h b/include/base/memory.h index 6f14c8e..d80b34c 100644 --- a/include/base/mem.h +++ b/include/base/memory.h @@ -58,8 +58,9 @@ void mem·freearena(mem·Arena *A); extern mem·Allocator mem·ArenaAllocator; /* mem functions */ -int mem·move(void *dst, void *src, uintptr size); +int mem·move(void *dst, uintptr size, void *src); +int mem·copy(void *dst, uintptr size, void *src); +int mem·compare(void *, uintptr size, void *); void *mem·findc(void *dst, uintptr len, int c); -int mem·set(void *dst, int val, uintptr size); -int mem·set64(void *dst, uint64 val, uintptr size); - +int mem·set(void *dst, uintptr size, int val); +int mem·set64(void *dst, uintptr size, uint64 val); diff --git a/include/base/string.h b/include/base/string.h index 0800f60..a6d6612 100644 --- a/include/base/string.h +++ b/include/base/string.h @@ -1,34 +1,53 @@ #pragma once -typedef byte* string; +typedef char* string; + +/* basic c string (nul terminated) functions */ +intptr str·len(char *s); + +char *str·findc(char *s, int c); +char *str·nfindc(char *s, intptr n, int c); +char *str·efindc(char *s, char *e, int c); + +char *str·find(char *s, char *sub); +char *str·nfind(char *s, intptr n, char *sub); +char *str·efind(char *s, char *e, char *sub); + +char *str·copy(char *dst, char *src); +char *str·ncopy(char *dst, intptr n, char *src); +char *str·ecopy(char *dst, char *end, char *src); + +char *str·append(char *dst, char *src); +char *str·nappend(char *dst, intptr n, char *src); +char *str·eappend(char *dst, char *end, char *src); + +int str·compare(char *, char *); +int str·ncompare(char *, intptr len, char *); +int str·ecompare(char *, char *end, char *); + +int str·atoi(char *s); +char *str·itoa(char *s, int x); /* augmented string functions */ -string str·makecap(const char *s, vlong len, vlong cap); -string str·makelen(const char *s, vlong len); -string str·make(const char *s); -string str·makef(const char *fmt, ...); -void str·free(string s); -int str·len(const string s); -int str·cap(const string s); -void str·clear(string *s); -void str·grow(string *s, vlong delta); -void str·fit(string *s); -int str·appendlen(string *s, vlong len, const char *b); -int str·append(string *s, const char *b); -int str·appendf(string *s, const char *fmt, ...); -int str·appendbyte(string *s, const char b); -bool str·equals(const string s, const string t); -int str·find(string s, const char* substr); -void str·lower(string s); -void str·upper(string s); -int str·read(string s, int size, int n, void *buf); -void str·replace(string s, const byte* from, const byte* to); -string* str·split(string s, const byte* tok); -string str·join(vlong len, byte** fields, const byte* sep); - -/* raw C string functions */ -char *str·copyn(char *dst, char *src, int n); - -/* string parsing */ -int str·atoi(char *s); -char *str·itoa(char *s, int x); +string string·makecap(char *s, vlong len, vlong cap); +string string·makelen(char *s, vlong len); +string string·make(char *s); +string string·makef(char *fmt, ...); +void string·free(string s); +int string·len(string s); +int string·cap(string s); +void string·clear(string *s); +void string·grow(string *s, vlong delta); +void string·fit(string *s); +int string·appendlen(string *s, vlong len, char *b); +int string·append(string *s, char *b); +int string·appendf(string *s, char *fmt, ...); +int string·appendbyte(string *s, char b); +bool string·equals(string s, string t); +int string·find(string s, char *substr); +void string·lower(string s); +void string·upper(string s); +int string·read(string s, int size, int n, void *buf); +void string·replace(string s, byte* from, byte* to); +string* string·split(string s, byte* tok); +string string·join(vlong len, byte** fields, byte* sep); |