From 69ed661a488c0e02bf5fee3dc21e6a31a99a8d85 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 17 Oct 2015 00:58:39 +0200 Subject: fix errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- Makefile | 4 ++- include/ctype.h | 5 ++++ include/errno.h | 11 ++++++- include/malloc.h | 4 +-- include/slibc/features.h | 4 +-- include/unistd.h | 7 +++++ src/malloc.c | 12 ++++++-- src/slibc-alloc.c | 77 +++++++++++++++++++++++++----------------------- src/stdio/printf.c | 2 +- src/stdio/scanf.c | 41 ++++++++++++++++++++------ src/stdlib/atoi.c | 28 ++++++++++++++---- src/string/memccpy.c | 8 ++--- src/string/strchr.c | 12 ++++---- src/string/strspn.c | 2 +- src/string/strstr.c | 52 ++++++++++++++++---------------- src/strings/index.c | 8 ++--- src/unistd/exec.c | 19 +++++++----- src/unistd/execat.c | 25 ++++++++++------ src/unistd/fexec.c | 6 ++-- src/wchar/wcschr.c | 12 ++++---- src/wchar/wcscmp.c | 6 ++-- src/wchar/wcsspn.c | 2 +- src/wchar/wcsstr.c | 46 ++++++++++++++--------------- src/wchar/wmemccpy.c | 4 +-- 24 files changed, 241 insertions(+), 156 deletions(-) diff --git a/Makefile b/Makefile index 8f2c7b2..ff643e8 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,9 @@ CCFLAGS_UNHOSTED = -nostdinc -ffreestanding # Preprocessor flags defined by slibc that are required to build the slibc. CCFLAGS_SLIBC_DEFS = -D_SLIBC_SOURCE=1 -D_GNU_SOURCE=1 -D_BSD_SOURCE=1 -D_SLIBC_SUPPRESS_WARNINGS=1 \ - -D_POSIX_C_SOURCE=999999L -D_XOPEN_SOURCE=9999 + -D_POSIX_C_SOURCE=999999L -D_XOPEN_SOURCE=9999 -D__BUILDING_SLIBC=1 +# __BUILDING_SLIBC is used to that make all prototypes visible, that are otherwise +# hidden because the library is compiled with a too old revision of C. # Flag that specifies which C dialect the library is written. CCFLAGS_CSTD = -std=gnu99 diff --git a/include/ctype.h b/include/ctype.h index 20fbb4a..96b94b9 100644 --- a/include/ctype.h +++ b/include/ctype.h @@ -27,6 +27,11 @@ +#define __NEED_locale_t + +#include + + /** * Check whether a character is an alphabetical * character or a decimal digit. diff --git a/include/errno.h b/include/errno.h index 18afa72..deb17d8 100644 --- a/include/errno.h +++ b/include/errno.h @@ -23,7 +23,16 @@ /* TODO include error definitions */ -#define ERANGE 34 +#define ENOMEM 1 +#define EINVAL 1 +#define ERANGE 1 +#define ENOENT 1 +#define EBADF 1 +#define ENOSYS 1 +#define ELOOP 1 +#define EISDIR 1 +#define EACCES 1 +#define ENOTSUP 1 diff --git a/include/malloc.h b/include/malloc.h index 6373668..c1d4a85 100644 --- a/include/malloc.h +++ b/include/malloc.h @@ -84,7 +84,7 @@ void* calloc(size_t, size_t) * @throws ENOMEM The process cannot allocate more memory. */ void* zalloc(size_t) - __warning("'zalloc' is klibc extension, use 'calloc(1, n)' instead of 'zalloc(n)'."), + __warning("'zalloc' is klibc extension, use 'calloc(1, n)' instead of 'zalloc(n)'.") __GCC_ONLY(__attribute__((malloc, warn_unused_result))); #endif @@ -235,7 +235,7 @@ void* pvalloc(size_t) __deprecated("'pvalloc' is deprecated, use 'memalign' or 'posix_memalign' instead."); #endif -#ifdef __C11__ +#if defined(__C11__) || defined(__BUILDING_SLIBC) /** * This function is identical to `memalign`, * except it can be freed with `free`. diff --git a/include/slibc/features.h b/include/slibc/features.h index b5b28eb..6951ea4 100644 --- a/include/slibc/features.h +++ b/include/slibc/features.h @@ -48,7 +48,7 @@ * @param ... The rest of the arguments. * @return The result casted to the same type as `first`. */ -#if defined(__CONST_CORRECT) +#ifdef __CONST_CORRECT # undef __CONST_CORRECT # undef __const_correct #endif @@ -70,7 +70,7 @@ # define __const_correct(function, first, ...) \ (_Generic(&(first), \ const wchar_t(*)[]: (const wchar_t*)function(first, __VA_ARGS__), \ - const char(*)[]: (const char*) function(first, __VA_ARGS__), \ + const char(*)[]: (const char*) function(first, __VA_ARGS__), \ const wchar_t**: (const wchar_t*)function(first, __VA_ARGS__), \ const char**: (const char*) function(first, __VA_ARGS__), \ const void**: (const void*) function(first, __VA_ARGS__), \ diff --git a/include/unistd.h b/include/unistd.h index fb4992d..5377e28 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -61,6 +61,13 @@ #define STDERR_FILENO 2 +/* TODO temporary values */ +#define F_OK 0 +#define X_OK 1 +#define W_OK 2 +#define R_OK 4 + + /** * Set the high end of the calling process's * data segment. diff --git a/src/malloc.c b/src/malloc.c index 6219fce..528c49f 100644 --- a/src/malloc.c +++ b/src/malloc.c @@ -18,9 +18,16 @@ #include #include #include -#include +/* TODO #include */ #include #include +/* TODO temporary constants from other headers { */ +#define PROT_READ 0 +#define PROT_WRITE 0 +#define MAP_PRIVATE 0 +#define MAP_ANONYMOUS 0 +#define _SC_PAGESIZE 0 +/* } */ @@ -203,7 +210,8 @@ void* memalign(size_t boundary, size_t size) size_t address; size_t shift = 0; - if (!boundary || (__builtin_ffsl(boundary) != boundary)) + if (!boundary || (__builtin_ffsl((long int)boundary) != boundary)) + /* `size_t` mat not be wider than `long int`. */ return errno = EINVAL, NULL; if (__builtin_uaddl_overflow(boundary - 1, size, &full_size)) return errno = ENOMEM, NULL; diff --git a/src/slibc-alloc.c b/src/slibc-alloc.c index ac81530..733051c 100644 --- a/src/slibc-alloc.c +++ b/src/slibc-alloc.c @@ -19,7 +19,7 @@ #include #include #include -#include +/* TODO #include */ @@ -37,7 +37,7 @@ */ void fast_free(void* segment) { - if (segument == NULL) + if (segment == NULL) return; munmap(PURE_ALLOC(segment), PURE_SIZE(segment)); } @@ -51,7 +51,7 @@ void fast_free(void* segment) */ void secure_free(void* segment) { - if (segument == NULL) + if (segment == NULL) return; explicit_bzero(PURE_ALLOC(segment), PURE_SIZE(segment)); fast_free(segment); @@ -82,7 +82,10 @@ void secure_free(void* segment) size_t allocsize(void* segment) { if (segment == NULL) - return errno = EINVAL, 0; + { + errno = EINVAL; + return 0; + } return *(size_t*)PURE_ALLOC(segment); } @@ -97,36 +100,36 @@ size_t allocsize(void* segment) * @param CLEAR_FREE:int Whether the old allocation is cleared if a new pointer is returned. * @return The new allocation, see `realloc` for more details. */ -#define REALLOC(ptr, size, CLEAR_OLD, CLEAR_NEW, CLEAR_FREE) \ - size_t old_size; \ - void* new_ptr; \ - \ - if (size == 0) \ - return secure_free(ptr), NULL; \ - \ - if (ptr == NULL) \ - return CLEAR_NEW ? malloc(size) : calloc(1, size); \ - \ - old_size = allocsize(ptr); \ - if (old_size == size) \ - return ptr; \ - \ - if (CLEAR_OLD ? (old_size > size) : 0) \ - explicit_bzero(((char*)ptr) + size, old_size - size); \ - \ - new_ptr = naive_realloc(ptr); \ - if (new_ptr != ptr) \ - { \ - if (new_ptr == NULL) \ - return NULL; \ - if (CLEAR_FREE) \ - explicit_bzero(PURE_ALLOC(ptr), PURE_SIZE(ptr)); \ - fast_free(ptr); \ - } \ - \ - if (CLEAR_NEW ? (old_size < size) : 0) \ - explicit_bzero(((char*)new_ptr) + old, size - old_size); \ - \ +#define REALLOC(ptr, size, CLEAR_OLD, CLEAR_NEW, CLEAR_FREE) \ + size_t old_size; \ + void* new_ptr; \ + \ + if (size == 0) \ + return secure_free(ptr), NULL; \ + \ + if (ptr == NULL) \ + return CLEAR_NEW ? malloc(size) : calloc(1, size); \ + \ + old_size = allocsize(ptr); \ + if (old_size == size) \ + return ptr; \ + \ + if (CLEAR_OLD ? (old_size > size) : 0) \ + explicit_bzero(((char*)ptr) + size, old_size - size); \ + \ + new_ptr = naive_realloc(ptr, size); \ + if (new_ptr != ptr) \ + { \ + if (new_ptr == NULL) \ + return NULL; \ + if (CLEAR_FREE) \ + explicit_bzero(PURE_ALLOC(ptr), PURE_SIZE(ptr)); \ + fast_free(ptr); \ + } \ + \ + if (CLEAR_NEW ? (old_size < size) : 0) \ + explicit_bzero(((char*)new_ptr) + old_size, size - old_size); \ + \ return new_ptr @@ -234,14 +237,14 @@ void* custom_realloc(void* ptr, size_t size, int clear_old, int clear_new, int c void* extalloc(void* ptr, size_t size, enum extalloc_mode mode) { int clear = mode & EXTALLOC_CLEAR; - size_t old_size; + size_t old_size = allocsize(ptr); void* new_ptr; if (clear ? (old_size > size) : 0) explicit_bzero(((char*)ptr) + size, old_size - size); - new_ptr = ((mode & EXTALLOC_MALLOC) ? naive_realloc : naive_extalloc)(ptr); - if ((new_ptr != ptr) && (ptr_new != NULL)) + new_ptr = ((mode & EXTALLOC_MALLOC) ? naive_realloc : naive_extalloc)(ptr, size); + if ((new_ptr != ptr) && (new_ptr != NULL)) { if (clear) explicit_bzero(PURE_ALLOC(ptr), PURE_SIZE(ptr)); diff --git a/src/stdio/printf.c b/src/stdio/printf.c index 5c35096..c88fc99 100644 --- a/src/stdio/printf.c +++ b/src/stdio/printf.c @@ -279,7 +279,7 @@ static int wwrite_buffer(const wchar_t* text, size_t length, struct buffer* buff enum extalloc_mode flags = EXTALLOC_MALLOC | (buffer->secure ? EXTALLOC_CLEAR : 0); wchar_t* new; - if (buffer->off + length > buffer->size) + if (buffer->off + length > *(buffer->size)) { if (buffer->off || !*(buffer->size)) new = (buffer->secure ? secure_realloc : fast_realloc) diff --git a/src/stdio/scanf.c b/src/stdio/scanf.c index 519d12a..9a88ec4 100644 --- a/src/stdio/scanf.c +++ b/src/stdio/scanf.c @@ -25,6 +25,19 @@ /* #include */ +# pragma GCC diagnostic ignored "-Wcast-qual" +# pragma GCC diagnostic ignored "-Wdiscarded-qualifiers" + + + +/* TODO add { */ +# define generic_scanf_read_func_t void* +# define generic_wscanf_read_func_t void* +extern int vgeneric_scanf(void*, void*, size_t, size_t, void*, void*, char*, va_list); +extern int vgeneric_wscanf(void*, void*, size_t, size_t, void*, void*, wchar_t*, va_list); +/* } */ + + #define V(C) \ int r; \ va_list args; \ @@ -35,16 +48,26 @@ #define S_CHAR(UNDERLAYING, MAXIMUM, LIMITED, DATA) \ return vgeneric_scanf((generic_scanf_read_func_t)UNDERLAYING, NULL, \ - MAXIMUM, LIMITED, NULL, DATA, format, data) + MAXIMUM, LIMITED, NULL, DATA, format, args) #define S_WCHAR(UNDERLAYING, MAXIMUM, LIMITED, DATA) \ return vgeneric_wscanf((generic_wscanf_read_func_t)UNDERLAYING, NULL, \ - MAXIMUM, LIMITED, NULL, DATA, format, data) + MAXIMUM, LIMITED, NULL, DATA, format, args) #define FLOCK(F) /* TODO lock stream */ #define FUNLOCK(F) /* TODO unlock stream */ +/* TODO implement underlaying scan functions { */ +extern int read_string(void); +extern int read_stream(void); +extern int read_fd(void); +extern int wread_string(void); +extern int wread_stream(void); +extern int wread_fd(void); +/* } */ + + /** * This function is identical to `fscanf` with @@ -186,7 +209,7 @@ int dscanf(int fd, const char* restrict format, ...) */ int vscanf(const char* restrict format, va_list args) { - return vscanf(stdout, format, args); + return vfscanf(stdout, format, args); } @@ -229,7 +252,7 @@ int vfscanf(FILE* restrict stream, const char* restrict format, va_list args) */ int vsscanf(const char* restrict input, const char* restrict format, va_list args) { - S_CHAR(read_string, 0, 0, input); + S_CHAR(read_string, 0, 0, (char*)input); } @@ -272,7 +295,7 @@ int vfscanf_unlocked(FILE* restrict stream, const char* restrict format, va_list */ int vsnscanf(const char* restrict input, size_t length, const char* restrict format, va_list args) { - S_CHAR(read_string, length, 1, input); + S_CHAR(read_string, length, 1, (char*)input); } @@ -392,7 +415,7 @@ int fwscanf_unlocked(FILE* restrict stream, const wchar_t* restrict format, ...) */ int snwscanf(const wchar_t* restrict input, size_t length, const wchar_t* restrict format, ...) { - V(snscanf(input, length, format, args)); + V(snwscanf(input, length, format, args)); } @@ -431,7 +454,7 @@ int dwscanf(int fd, const wchar_t* restrict format, ...) */ int vwscanf(const wchar_t* restrict format, va_list args) { - return vwscanf(stdout, format, args); + return vfwscanf(stdout, format, args); } @@ -474,7 +497,7 @@ int vfwscanf(FILE* restrict stream, const wchar_t* restrict format, va_list args */ int vswscanf(const wchar_t* restrict input, const wchar_t* restrict format, va_list args) { - S_WCHAR(wread_string, 0, 0, input); + S_WCHAR(wread_string, 0, 0, (wchar_t*)input); } @@ -517,7 +540,7 @@ int vfwscanf_unlocked(FILE* restrict stream, const wchar_t* restrict format, va_ */ int vsnwscanf(const wchar_t* restrict input, size_t length, const wchar_t* restrict format, va_list args) { - S_WCHAR(wread_string, length, 1, input); + S_WCHAR(wread_string, length, 1, (wchar_t*)input); } diff --git a/src/stdlib/atoi.c b/src/stdlib/atoi.c index 9c45803..187d29c 100644 --- a/src/stdlib/atoi.c +++ b/src/stdlib/atoi.c @@ -35,7 +35,23 @@ */ int atoi(const char* string) { - return (int)atol(string); + int rc = 0; + int neg = 0; + + while (isspace(*string)) + string++; + + switch (*string) + { + case '-': neg = 1; + case '+': string++; + default: break; + } + + while (isdigit(*string)) + rc = rc * 10 - (*string++ & 15); + + return neg ? rc : -rc; } @@ -54,7 +70,7 @@ int atoi(const char* string) */ long int atol(const char* string) { - long int rc; + long int rc = 0; int neg = 0; while (isspace(*string)) @@ -64,10 +80,11 @@ long int atol(const char* string) { case '-': neg = 1; case '+': string++; + default: break; } while (isdigit(*string)) - n = n * 10 - (*string++ & 15); + rc = rc * 10 - (*string++ & 15); return neg ? rc : -rc; } @@ -88,7 +105,7 @@ long int atol(const char* string) */ long long int atoll(const char* string) { - long long int rc; + long long int rc = 0; int neg = 0; while (isspace(*string)) @@ -98,10 +115,11 @@ long long int atoll(const char* string) { case '-': neg = 1; case '+': string++; + default: break; } while (isdigit(*string)) - n = n * 10 - (*string++ & 15); + rc = rc * 10 - (*string++ & 15); return neg ? rc : -rc; } diff --git a/src/string/memccpy.c b/src/string/memccpy.c index 4212419..0c73f8b 100644 --- a/src/string/memccpy.c +++ b/src/string/memccpy.c @@ -33,9 +33,9 @@ * number of copied characters; the address of * one character passed the last written character. */ -void* memccpy(void* restrict whither, const void* restrict whence, int c, size_t size) +void* (memccpy)(void* restrict whither, const void* restrict whence, int c, size_t size) { - char* stop = memchr(whence, c, size); + char* stop = (memchr)(whence, c, size); void* r = NULL; if (stop != NULL) size = (size_t)(stop - (const char*)whence), r = whither + size; @@ -60,9 +60,9 @@ void* memccpy(void* restrict whither, const void* restrict whence, int c, size_t * number of copied characters; the address of * one character passed the last written character. */ -void* memcmove(void* whither, const void* whence, int c, size_t size) +void* (memcmove)(void* whither, const void* whence, int c, size_t size) { - char* stop = memchr(whence, c, size); + char* stop = (memchr)(whence, c, size); void* r = NULL; if (stop != NULL) size = (size_t)(stop - (const char*)whence), r = whither + size; diff --git a/src/string/strchr.c b/src/string/strchr.c index bf79a0b..06f3ee6 100644 --- a/src/string/strchr.c +++ b/src/string/strchr.c @@ -31,7 +31,7 @@ * @return Pointer to the first occurrence of `c`, * `NULL` if none were found. */ -void* memchr(const void* segment, int c, size_t size) +void* (memchr)(const void* segment, int c, size_t size) { char* s = segment; while (size--) @@ -51,7 +51,7 @@ void* memchr(const void* segment, int c, size_t size) * @param c The sought after character. * @return Pointer to the first occurrence of `c`. */ -void* rawmemchr(const void* segment, int c) +void* (rawmemchr)(const void* segment, int c) { char* s = segment; for (;;) @@ -73,7 +73,7 @@ void* rawmemchr(const void* segment, int c) * @return Pointer to the last occurrence of `c`, * `NULL` if none were found. */ -void* memrchr(const void* segment, int c, size_t size) +void* (memrchr)(const void* segment, int c, size_t size) { char* s = segment; while (size--) @@ -96,7 +96,7 @@ void* memrchr(const void* segment, int c, size_t size) * @return Pointer to the first occurrence of `c`, * `NULL` if none were found. */ -char* strchr(const char* string, int c) +char* (strchr)(const char* string, int c) { for (;;) if (*string == c) @@ -120,7 +120,7 @@ char* strchr(const char* string, int c) * Pointer to the terminating NUL character * if none were found. */ -char* strchrnul(const char* string, int c) +char* (strchrnul)(const char* string, int c) { for (;; string++) if (*string == c) @@ -144,7 +144,7 @@ char* strchrnul(const char* string, int c) * @return Pointer to the last occurrence of `c`, * `NULL` if none were found. */ -char* strrchr(const char* string, int c) +char* (strrchr)(const char* string, int c) { char* r = NULL; for (;;) diff --git a/src/string/strspn.c b/src/string/strspn.c index f8d1dac..511a4bc 100644 --- a/src/string/strspn.c +++ b/src/string/strspn.c @@ -82,7 +82,7 @@ size_t strcspn(const char* string, const char* stopset) * `string` of a byte found in `stopset`. * `NULL` is returned if none is found. */ -char* strpbrk(const char* string, const char* stopset) +char* (strpbrk)(const char* string, const char* stopset) { char set[256]; char c; diff --git a/src/string/strstr.c b/src/string/strstr.c index 34b3120..a2c31f6 100644 --- a/src/string/strstr.c +++ b/src/string/strstr.c @@ -35,9 +35,9 @@ * @return Pointer to the first occurrence of the * substring, `NULL` if not found. */ -char* strstr(const char* haystack, const char* needle) +char* (strstr)(const char* haystack, const char* needle) { - return memmem(haystack, strlen(haystack), needle, strlen(needle)); + return (memmem)(haystack, strlen(haystack), needle, strlen(needle)); } @@ -50,9 +50,9 @@ char* strstr(const char* haystack, const char* needle) * @return Pointer to the first occurrence of the * substring, `NULL` if not found. */ -char* strcasestr(const char* haystack, const char* needle) +char* (strcasestr)(const char* haystack, const char* needle) { - return memcasemem(haystack, strlen(haystack), needle, strlen(needle)); + return (memcasemem)(haystack, strlen(haystack), needle, strlen(needle)); } @@ -69,9 +69,9 @@ char* strcasestr(const char* haystack, const char* needle) * @return Pointer to the first occurrence of the * substring, `NULL` if not found. */ -char* strnstr(const char* haystack, const char* needle, size_t maxlen) +char* (strnstr)(const char* haystack, const char* needle, size_t maxlen) { - return memmem(haystack, strnlen(haystack, maxlen), needle, strlen(needle)); + return (memmem)(haystack, strnlen(haystack, maxlen), needle, strlen(needle)); } @@ -87,9 +87,9 @@ char* strnstr(const char* haystack, const char* needle, size_t maxlen) * @return Pointer to the first occurrence of the * substring, `NULL` if not found. */ -char* strncasestr(const char* haystack, const char* needle, size_t maxlen) +char* (strncasestr)(const char* haystack, const char* needle, size_t maxlen) { - return memcasemem(haystack, strnlen(haystack, maxlen), needle, strlen(needle)); + return (memcasemem)(haystack, strnlen(haystack, maxlen), needle, strlen(needle)); } @@ -104,9 +104,9 @@ char* strncasestr(const char* haystack, const char* needle, size_t maxlen) * @param needle The sought after substring. * @return Pointer to the first occurrence of the substring. */ -char* rawstrstr(const char* haystack, const char* needle) +char* (rawstrstr)(const char* haystack, const char* needle) { - return memmem(haystack, SIZE_MAX, needle, strlen(needle)); + return (memmem)(haystack, SIZE_MAX, needle, strlen(needle)); } @@ -121,9 +121,9 @@ char* rawstrstr(const char* haystack, const char* needle) * @param needle The sought after substring. * @return Pointer to the first occurrence of the substring. */ -char* rawstrcasestr(const char* haystack, const char* needle) +char* (rawstrcasestr)(const char* haystack, const char* needle) { - return memcasemem(haystack, SIZE_MAX, needle, strlen(needle)); + return (memcasemem)(haystack, SIZE_MAX, needle, strlen(needle)); } @@ -141,15 +141,15 @@ char* rawstrcasestr(const char* haystack, const char* needle) * @return Pointer to the first occurrence of * the substring, `NULL` if not found. */ -void* memmem(const void* __haystack, size_t haystack_length, - const void* __needle, size_t needle_length) +void* (memmem)(const void* __haystack, size_t haystack_length, + const void* __needle, size_t needle_length) { const char* haystack = __haystack; const char* needle = __needle; if (haystack_length < needle_length) return NULL; if (haystack_length == needle_length) - return !memcmp(haystack, needle, haystack_length) ? haystack : NULL; + return !(memcmp)(haystack, needle, haystack_length) ? haystack : NULL; #include "substring.h" } @@ -168,15 +168,15 @@ void* memmem(const void* __haystack, size_t haystack_length, * @return Pointer to the first occurrence of * the substring, `NULL` if not found. */ -void* memcasemem(const void* __haystack, size_t haystack_length, - const void* __needle, size_t needle_length) +void* (memcasemem)(const void* __haystack, size_t haystack_length, + const void* __needle, size_t needle_length) { const char* haystack = __haystack; const char* needle = __needle; if (haystack_length < needle_length) return NULL; if (haystack_length == needle_length) - return !memcasecmp(haystack, needle, haystack_length) ? haystack : NULL; + return !(memcasecmp)(haystack, needle, haystack_length) ? haystack : NULL; #define CASE #include "substring.h" #undef CASE @@ -194,13 +194,13 @@ void* memcasemem(const void* __haystack, size_t haystack_length, * @return `string` if `string` begins with * `desired`, `NULL` otherwise. */ -char* strstarts(const char* string, const char* desired) +char* (strstarts)(const char* string, const char* desired) { size_t n = strlen(string); size_t m = strlen(desired); if (n < m) return NULL; - return memcmp(string, desired, m) ? NULL : string; + return (memcmp)(string, desired, m) ? NULL : string; } @@ -215,13 +215,13 @@ char* strstarts(const char* string, const char* desired) * @return The `string`, where `desired` beings if * `string` ends with `desired`, `NULL` otherwise. */ -char* strends(const char* string, const char* desired) +char* (strends)(const char* string, const char* desired) { size_t n = strlen(string); size_t m = strlen(desired); if (n < m) return NULL; - return memcmp(string + (n - m), desired, m) ? NULL : (string + n); + return (memcmp)(string + (n - m), desired, m) ? NULL : (string + n); } @@ -236,13 +236,13 @@ char* strends(const char* string, const char* desired) * @return `string` if `string` begins with * `desired`, `NULL` otherwise. */ -char* strcasestarts(const char* string, const char* desired) +char* (strcasestarts)(const char* string, const char* desired) { size_t n = strlen(string); size_t m = strlen(desired); if (n < m) return NULL; - return memcasecmp(string, desired, m) ? NULL : string; + return (memcasecmp)(string, desired, m) ? NULL : string; } @@ -257,12 +257,12 @@ char* strcasestarts(const char* string, const char* desired) * @return The `string`, where `desired` beings if * `string` ends with `desired`, `NULL` otherwise. */ -char* strcaseends(const char* string, const char* desired) +char* (strcaseends)(const char* string, const char* desired) { size_t n = strlen(string); size_t m = strlen(desired); if (n < m) return NULL; - return memcasecmp(string + (n - m), desired, m) ? NULL : (string + n); + return (memcasecmp)(string + (n - m), desired, m) ? NULL : (string + n); } diff --git a/src/strings/index.c b/src/strings/index.c index 82126f5..eb7e321 100644 --- a/src/strings/index.c +++ b/src/strings/index.c @@ -25,9 +25,9 @@ * * This is a deprecated BSD extension. */ -char* index(const char* string, int c) +char* (index)(const char* string, int c) { - return strchr(string, c); + return (strchr)(string, c); } @@ -36,8 +36,8 @@ char* index(const char* string, int c) * * This is a deprecated BSD extension. */ -char* rindex(const char* string, int c) +char* (rindex)(const char* string, int c) { - return strrchr(string, c); + return (strrchr)(string, c); } diff --git a/src/unistd/exec.c b/src/unistd/exec.c index 70b54f6..0b76259 100644 --- a/src/unistd/exec.c +++ b/src/unistd/exec.c @@ -21,6 +21,9 @@ #include #include #include +/* TODO temporary contants from other headers { */ +#define _CS_PATH 1 +/* } */ @@ -114,8 +117,8 @@ int execlp(const char* file, ... /*, NULL */) { int saved_errno; va_list argv; - va_start(argv, path); - vexec(path, argv, 0, 1); + va_start(argv, file); + vexec(file, argv, 0, 1); saved_errno = errno; va_end(argv); return errno = saved_errno, -1; @@ -180,8 +183,8 @@ int execlpe(const char* file, ... /*, NULL, char* const envp[] */) { int saved_errno; va_list argv; - va_start(argv, path); - vexec(path, argv, 1, 1); + va_start(argv, file); + vexec(file, argv, 1, 1); saved_errno = errno; va_end(argv); return errno = saved_errno, -1; @@ -236,7 +239,7 @@ int execv(const char* path, char* const argv[]) */ int execvp(const char* file, char* const argv[]) { - return execvpe(path, argv, environ); + return execvpe(file, argv, environ); } @@ -265,7 +268,7 @@ int execvp(const char* file, char* const argv[]) int execve(const char* path, char* const argv[], char* const envp[]) { return errno = ENOTSUP, -1; - (void) path, (void) argv, (void) enpv; + (void) path, (void) argv, (void) envp; /* TODO implement execve */ } @@ -314,7 +317,7 @@ int execvpe(const char* file, char* const argv[], char* const envp[]) if (!*file) return errno = ENOENT, -1; - path = getenv(PATH); + path = getenv("PATH"); if (path == NULL) { if ((len = confstr(_CS_PATH, NULL, 0))) @@ -352,7 +355,7 @@ int execvpe(const char* file, char* const argv[], char* const envp[]) free(path); free(pathname); - return errno = (eaccess ? EACCES : ENOENT), -1; + return errno = (eacces ? EACCES : ENOENT), -1; fail: saved_errno = errno; diff --git a/src/unistd/execat.c b/src/unistd/execat.c index a90fffb..bcff176 100644 --- a/src/unistd/execat.c +++ b/src/unistd/execat.c @@ -22,8 +22,15 @@ #include #include #include -#include -#include +/* TODO #include */ +/* TODO #include */ +/* TODO temporary contants/structs from other headers { */ +#define AT_FDCWD 1 +#define AT_EMPTY_PATH 1 +#define AT_SYMLINK_NOFOLLOW 1 +#define _CS_PATH 1 +struct stat { int st_mode; }; +/* } */ @@ -150,8 +157,8 @@ int execlpat(int dirfd, const char* file, ... /*, NULL, int flags */) { int saved_errno; va_list argv; - va_start(argv, path); - vexecat(dirfd, path, argv, 0, 1); + va_start(argv, file); + vexecat(dirfd, file, argv, 0, 1); saved_errno = errno; va_end(argv); return errno = saved_errno, -1; @@ -244,8 +251,8 @@ int execlpeat(int dirfd, const char* file, ... /*, NULL, char* const[] envp, int { int saved_errno; va_list argv; - va_start(argv, path); - vexecat(dirfd, path, argv, 1, 1); + va_start(argv, file); + vexecat(dirfd, file, argv, 1, 1); saved_errno = errno; va_end(argv); return errno = saved_errno, -1; @@ -330,7 +337,7 @@ int execvat(int dirfd, const char* path, char* const argv[], int flags) */ int execvpat(int dirfd, const char* file, char* const argv[], int flags) { - return execvpe(dirfd, path, argv, environ, flags); + return execvpeat(dirfd, file, argv, environ, flags); } @@ -452,7 +459,7 @@ int execvpeat(int dirfd, const char* file, char* const argv[], char* const envp[ if (strchr(file, '/') || !*file) return execveat(dirfd, file, argv, envp, flags); - path = getenv(PATH); + path = getenv("PATH"); if (path == NULL) { execveat(dirfd, file, argv, envp, flags); @@ -494,7 +501,7 @@ int execvpeat(int dirfd, const char* file, char* const argv[], char* const envp[ free(path); free(pathname); - return errno = (eaccess ? EACCES : ENOENT), -1; + return errno = (eacces ? EACCES : ENOENT), -1; fail: saved_errno = errno; diff --git a/src/unistd/fexec.c b/src/unistd/fexec.c index bf2c392..7a8d4f5 100644 --- a/src/unistd/fexec.c +++ b/src/unistd/fexec.c @@ -40,7 +40,7 @@ extern char** environ; * * @throws Any error specified for execve(2). */ -static void vexec(int fd, va_list argv, int fetch_envp) +static void vfexec(int fd, va_list argv, int fetch_envp) { char* const* envp = environ; size_t n = 0, i; @@ -84,7 +84,7 @@ int fexecl(int fd, ... /*, NULL */) { int saved_errno; va_list argv; - va_start(argv, path); + va_start(argv, fd); vfexec(fd, argv, 0); saved_errno = errno; va_end(argv); @@ -116,7 +116,7 @@ int fexecle(int fd, ... /*, NULL, char* const envp[] */) { int saved_errno; va_list argv; - va_start(argv, path); + va_start(argv, fd); vfexec(fd, argv, 1); saved_errno = errno; va_end(argv); diff --git a/src/wchar/wcschr.c b/src/wchar/wcschr.c index 9b87167..7acc032 100644 --- a/src/wchar/wcschr.c +++ b/src/wchar/wcschr.c @@ -32,7 +32,7 @@ * @return Pointer to the first occurrence of `c`, * `NULL` if none were found. */ -wchar_t* wmemchr(const wchar_t* segment, wchar_t c, size_t size) +wchar_t* (wmemchr)(const wchar_t* segment, wchar_t c, size_t size) { while (size--) if (*segment++ == c) @@ -52,7 +52,7 @@ wchar_t* wmemchr(const wchar_t* segment, wchar_t c, size_t size) * @param c The sought after character. * @return Pointer to the first occurrence of `c`. */ -wchar_t* rawwmemchr(const wchar_t* segment, wchar_t c) +wchar_t* (rawwmemchr)(const wchar_t* segment, wchar_t c) { for (;;) if (*segment++ == c) @@ -76,7 +76,7 @@ wchar_t* rawwmemchr(const wchar_t* segment, wchar_t c) * @return Pointer to the last occurrence of `c`, * `NULL` if none were found. */ -wchar_t* wmemrchr(const wchar_t* segment, wchar_t c, size_t size) +wchar_t* (wmemrchr)(const wchar_t* segment, wchar_t c, size_t size) { while (size--) if (segment[size] == c) @@ -95,7 +95,7 @@ wchar_t* wmemrchr(const wchar_t* segment, wchar_t c, size_t size) * @return Pointer to the first occurrence of `c`, * `NULL` if none were found. */ -wchar_t* wcschr(const wchar_t* string, wchar_t c) +wchar_t* (wcschr)(const wchar_t* string, wchar_t c) { for (;;) if (*string == c) @@ -120,7 +120,7 @@ wchar_t* wcschr(const wchar_t* string, wchar_t c) * Pointer to the terminating NUL character * if none were found. */ -wchar_t* wcschrnul(const wchar_t* string, wchar_t c) +wchar_t* (wcschrnul)(const wchar_t* string, wchar_t c) { for (;; string++) if (*string == c) @@ -144,7 +144,7 @@ wchar_t* wcschrnul(const wchar_t* string, wchar_t c) * @return Pointer to the last occurrence of `c`, * `NULL` if none were found. */ -wchar_t* wcsrchr(const wchar_t* string, wchar_t c) +wchar_t* (wcsrchr)(const wchar_t* string, wchar_t c) { wchar_t* r = NULL; for (;;) diff --git a/src/wchar/wcscmp.c b/src/wchar/wcscmp.c index ddbd228..980906d 100644 --- a/src/wchar/wcscmp.c +++ b/src/wchar/wcscmp.c @@ -17,7 +17,7 @@ */ #include #include -#include +/* TODO #include */ @@ -54,7 +54,7 @@ int wmemcasecmp(const wchar_t* a, const wchar_t* b, size_t size) { wchar_t c1, c2; for (; size--; a++, b++) - if (*a != *b); + if (*a != *b) { c1 = iswalpha(*a) ? towlower(*a) : *a; c2 = iswalpha(*b) ? towlower(*b) : *b; @@ -115,7 +115,7 @@ int wcsncmp(const wchar_t* a, const wchar_t* b, size_t length) size_t n = wcsnlen(a, length); size_t m = wcsnlen(b, length); int r = wmemcmp(a, b, (n < m ? n : m)); - return r ? r : n == m ? 0 : n < m ? -1 : +1 + return r ? r : n == m ? 0 : n < m ? -1 : +1; } diff --git a/src/wchar/wcsspn.c b/src/wchar/wcsspn.c index 63dc60b..e4a1190 100644 --- a/src/wchar/wcsspn.c +++ b/src/wchar/wcsspn.c @@ -79,7 +79,7 @@ size_t wcscspn(const wchar_t* string, const wchar_t* stopset) * `string` of a character found in `stopset`. * `NULL` is returned if none is found. */ -wchar_t* wcspbrk(const wchar_t* string, const wchar_t* stopset) +wchar_t* (wcspbrk)(const wchar_t* string, const wchar_t* stopset) { string += wcscspn(string, stopset); return *string ? string : NULL; diff --git a/src/wchar/wcsstr.c b/src/wchar/wcsstr.c index bc2bbec..36ae893 100644 --- a/src/wchar/wcsstr.c +++ b/src/wchar/wcsstr.c @@ -19,7 +19,7 @@ #include #include #include -#include +/* TODO #include */ #define WIDE @@ -31,9 +31,9 @@ /** * This function is identical to `wcsstr`. */ -wchar_t* wcswcs(const wchar_t* haystack, const wchar_t* needle) +wchar_t* (wcswcs)(const wchar_t* haystack, const wchar_t* needle) { - return wcsstr(haystack, needle); + return (wcsstr)(haystack, needle); } @@ -46,9 +46,9 @@ wchar_t* wcswcs(const wchar_t* haystack, const wchar_t* needle) * @return Pointer to the first occurrence of the * substring, `NULL` if not found. */ -wchar_t* wcsstr(const wchar_t* haystack, const wchar_t* needle) +wchar_t* (wcsstr)(const wchar_t* haystack, const wchar_t* needle) { - return wmemmem(haystack, wcslen(haystack), needle, wcslen(needle)); + return (wmemmem)(haystack, wcslen(haystack), needle, wcslen(needle)); } @@ -63,9 +63,9 @@ wchar_t* wcsstr(const wchar_t* haystack, const wchar_t* needle) * @return Pointer to the first occurrence of the * substring, `NULL` if not found. */ -wchar_t* wcscasestr(const wchar_t* haystack, const wchar_t* needle) +wchar_t* (wcscasestr)(const wchar_t* haystack, const wchar_t* needle) { - return wmemcasemem(haystack, wcslen(haystack), needle, wcslen(needle)); + return (wmemcasemem)(haystack, wcslen(haystack), needle, wcslen(needle)); } @@ -82,9 +82,9 @@ wchar_t* wcscasestr(const wchar_t* haystack, const wchar_t* needle) * @return Pointer to the first occurrence of the * substring, `NULL` if not found. */ -wchar_t* wcsnstr(const wchar_t* haystack, const wchar_t* needle, size_t maxlen) +wchar_t* (wcsnstr)(const wchar_t* haystack, const wchar_t* needle, size_t maxlen) { - return wmemmem(haystack, wcsnlen(haystack, maxlen), needle, wcslen(needle)); + return (wmemmem)(haystack, wcsnlen(haystack, maxlen), needle, wcslen(needle)); } @@ -100,9 +100,9 @@ wchar_t* wcsnstr(const wchar_t* haystack, const wchar_t* needle, size_t maxlen) * @return Pointer to the first occurrence of the * substring, `NULL` if not found. */ -wchar_t* wcsncasestr(const wchar_t* haystack, const wchar_t* needle, size_t maxlen) +wchar_t* (wcsncasestr)(const wchar_t* haystack, const wchar_t* needle, size_t maxlen) { - return wmemcasemem(haystack, wcsnlen(haystack, maxlen), needle, wcslen(needle)); + return (wmemcasemem)(haystack, wcsnlen(haystack, maxlen), needle, wcslen(needle)); } @@ -117,9 +117,9 @@ wchar_t* wcsncasestr(const wchar_t* haystack, const wchar_t* needle, size_t maxl * @param needle The sought after substring. * @return Pointer to the first occurrence of the substring. */ -wchar_t* rawwcsstr(const wchar_t* haystack, const wchar_t* needle) +wchar_t* (rawwcsstr)(const wchar_t* haystack, const wchar_t* needle) { - return wmemmem(haystack, SIZE_MAX, needle, wcslen(needle)); + return (wmemmem)(haystack, SIZE_MAX, needle, wcslen(needle)); } @@ -134,9 +134,9 @@ wchar_t* rawwcsstr(const wchar_t* haystack, const wchar_t* needle) * @param needle The sought after substring. * @return Pointer to the first occurrence of the substring. */ -wchar_t* rawwcscasestr(const wchar_t* haystack, const wchar_t* needle) +wchar_t* (rawwcscasestr)(const wchar_t* haystack, const wchar_t* needle) { - return wmemcasemem(haystack, SIZE_MAX, needle, wcslen(needle)); + return (wmemcasemem)(haystack, SIZE_MAX, needle, wcslen(needle)); } @@ -155,8 +155,8 @@ wchar_t* rawwcscasestr(const wchar_t* haystack, const wchar_t* needle) * @return Pointer to the first occurrence of * the substring, `NULL` if not found. */ -wchar_t* wmemmem(const wchar_t* haystack, size_t haystack_length, - const wchar_t* needle, size_t needle_length) +wchar_t* (wmemmem)(const wchar_t* haystack, size_t haystack_length, + const wchar_t* needle, size_t needle_length) { if (haystack_length < needle_length) return NULL; @@ -180,8 +180,8 @@ wchar_t* wmemmem(const wchar_t* haystack, size_t haystack_length, * @return Pointer to the first occurrence of * the substring, `NULL` if not found. */ -wchar_t* wmemcasemem(const wchar_t* haystack, size_t haystack_length, - const wchar_t* needle, size_t needle_length) +wchar_t* (wmemcasemem)(const wchar_t* haystack, size_t haystack_length, + const wchar_t* needle, size_t needle_length) { if (haystack_length < needle_length) return NULL; @@ -204,7 +204,7 @@ wchar_t* wmemcasemem(const wchar_t* haystack, size_t haystack_length, * @return `string` if `string` begins with * `desired`, `NULL` otherwise. */ -wchar_t* wcsstarts(const wchar_t* string, const wchar_t* desired) +wchar_t* (wcsstarts)(const wchar_t* string, const wchar_t* desired) { size_t n = wcslen(string); size_t m = wcslen(desired); @@ -225,7 +225,7 @@ wchar_t* wcsstarts(const wchar_t* string, const wchar_t* desired) * @return The `string`, where `desired` beings if * `string` ends with `desired`, `NULL` otherwise. */ -wchar_t* wcsends(const wchar_t* string, const wchar_t* desired) +wchar_t* (wcsends)(const wchar_t* string, const wchar_t* desired) { size_t n = wcslen(string); size_t m = wcslen(desired); @@ -246,7 +246,7 @@ wchar_t* wcsends(const wchar_t* string, const wchar_t* desired) * @return `string` if `string` begins with * `desired`, `NULL` otherwise. */ -wchar_t* wcscasestarts(const wchar_t* string, const wchar_t* desired) +wchar_t* (wcscasestarts)(const wchar_t* string, const wchar_t* desired) { size_t n = wcslen(string); size_t m = wcslen(desired); @@ -267,7 +267,7 @@ wchar_t* wcscasestarts(const wchar_t* string, const wchar_t* desired) * @return The `string`, where `desired` beings if * `string` ends with `desired`, `NULL` otherwise. */ -wchar_t* wcscaseends(const wchar_t* string, const wchar_t* desired) +wchar_t* (wcscaseends)(const wchar_t* string, const wchar_t* desired) { size_t n = wcslen(string); size_t m = wcslen(desired); diff --git a/src/wchar/wmemccpy.c b/src/wchar/wmemccpy.c index cde1a6a..498e4db 100644 --- a/src/wchar/wmemccpy.c +++ b/src/wchar/wmemccpy.c @@ -37,7 +37,7 @@ */ wchar_t* wmemccpy(wchar_t* restrict whither, const wchar_t* restrict whence, wchar_t c, size_t size) { - wchar_t* stop = wmemchr(whence, c, size); + wchar_t* stop = (wmemchr)(whence, c, size); wchar_t* r = NULL; if (stop != NULL) size = (size_t)(stop - whence), r = whither + size; @@ -64,7 +64,7 @@ wchar_t* wmemccpy(wchar_t* restrict whither, const wchar_t* restrict whence, wch */ wchar_t* wmemcmove(wchar_t* whither, const wchar_t* whence, wchar_t c, size_t size) { - wchar_t* stop = wmemchr(whence, c, size); + wchar_t* stop = (wmemchr)(whence, c, size); wchar_t* r = NULL; if (stop != NULL) size = (size_t)(stop - whence), r = whither + size; -- cgit v1.2.3-70-g09d2