aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2015-09-02 20:49:08 +0200
committerMattias Andrée <maandree@operamail.com>2015-09-02 20:49:08 +0200
commitf9e52c4acbd8f53da1b083770c6aab9c67cb0368 (patch)
tree755cb04726fbf6f44b42d94844fd78be6940dd7c
parentadd memcasecmp and wmemcasecmp (diff)
downloadslibc-f9e52c4acbd8f53da1b083770c6aab9c67cb0368.tar.gz
slibc-f9e52c4acbd8f53da1b083770c6aab9c67cb0368.tar.bz2
slibc-f9e52c4acbd8f53da1b083770c6aab9c67cb0368.tar.xz
misc
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rw-r--r--include/bits/types.h10
-rw-r--r--include/err.h3
-rw-r--r--include/errno.h1
-rw-r--r--include/error.h3
-rw-r--r--include/slibc-error.h4
-rw-r--r--include/stdarg.h12
-rw-r--r--include/stdio.h63
-rw-r--r--include/stdlib.h11
-rw-r--r--include/string.h4
-rw-r--r--include/unistd.h9
-rw-r--r--src/assert.c2
-rw-r--r--src/err.c1
-rw-r--r--src/error.c9
-rw-r--r--src/slibc-error.c1
-rw-r--r--src/string/strerror.c5
-rw-r--r--src/wchar/wcsspn.c12
16 files changed, 132 insertions, 18 deletions
diff --git a/include/bits/types.h b/include/bits/types.h
index 83087b5..3d178b8 100644
--- a/include/bits/types.h
+++ b/include/bits/types.h
@@ -368,9 +368,17 @@ typedef struct {
*/
#if defined(__NEED_locale_t) && !defined(__DEFINED_locale_t)
# define __DEFINED_locale_t
-typedef struct __locale locale_t; /* TODO not implemented */
+typedef int locale_t; /* TODO not implemented */
#endif
#ifndef __INTMAX_MAX
# define __INTMAX_MAX INT64_MAX
#endif
+
+/**
+ * State of variadic argument-reading.
+ */
+#define __ONLY_va_list
+# include <stdarg.h>
+#undef __ONLY_va_list
+
diff --git a/include/err.h b/include/err.h
index c4b241a..3f52afc 100644
--- a/include/err.h
+++ b/include/err.h
@@ -26,7 +26,8 @@
#endif
-#include <stdarg.h>
+#define __NEED_va_list
+#include <bits/types.h>
diff --git a/include/errno.h b/include/errno.h
index 9344a8a..fc36695 100644
--- a/include/errno.h
+++ b/include/errno.h
@@ -23,6 +23,7 @@
/* TODO include error definitions */
+#define ERANGE 34
diff --git a/include/error.h b/include/error.h
index 37d8328..0716530 100644
--- a/include/error.h
+++ b/include/error.h
@@ -26,7 +26,8 @@
#endif
-#include <stdarg.h>
+#define __NEED_va_list
+#include <bits/types.h>
diff --git a/include/slibc-error.h b/include/slibc-error.h
index 086ad31..c474745 100644
--- a/include/slibc-error.h
+++ b/include/slibc-error.h
@@ -22,7 +22,9 @@
#ifndef __PORTABLE
-#include <stdarg.h>
+#define __NEED_va_list
+#include <bits/types.h>
+
#include <errno.h>
diff --git a/include/stdarg.h b/include/stdarg.h
index 84bc840..801e5e8 100644
--- a/include/stdarg.h
+++ b/include/stdarg.h
@@ -16,7 +16,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _STDARG_H
-#define _STDARG_H
+# ifndef __ONLY_va_list
+# define _STDARG_H
+# endif
#include <slibc/version.h>
#include <slibc/features.h>
@@ -37,6 +39,12 @@
typedef __builtin_va_list va_list;
#endif
+
+
+#ifndef __ONLY_va_list
+
+
+
/**
* Prologue to using a variadic arguments.
*
@@ -84,3 +92,5 @@ typedef __builtin_va_list va_list;
#endif
+#endif
+
diff --git a/include/stdio.h b/include/stdio.h
new file mode 100644
index 0000000..d23339d
--- /dev/null
+++ b/include/stdio.h
@@ -0,0 +1,63 @@
+/**
+ * slibc — Yet another C library
+ * Copyright © 2015 Mattias Andrée (maandree@member.fsf.org)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef _STDIO_H
+#define _STDIO_H
+#include <slibc/version.h>
+#include <slibc/features.h>
+
+
+
+#define __NEED_fpos_t /* TODO not implemented */
+#define __NEED_off_t
+#define __NEED_size_t
+#define __NEED_ssize_t
+#define __NEED_va_list
+#if __STDC_VERSION__ >= 201112L
+# define __NEED_max_align_t
+#endif
+
+#include <bits/types.h>
+
+
+
+/* TODO implement I/O */
+int fflush(void*);
+#define stdin NULL
+#define stdout NULL
+#define stderr NULL
+int printf(const char*, ...);
+int fprintf(void*, const char*, ...);
+int dprintf(int, const char*, ...);
+int sprintf(char*, const char*, ...);
+int snprintf(char*, size_t, const char*, ...);
+#if (defined(_GNU_SOURCE) || defined(_SLIBC_SOURCE)) && !defined(__PORTABLE)
+int asprintf(char**, const char*, ...);
+#endif
+int vprintf(const char*, va_list);
+int vfprintf(void*, const char*, va_list);
+int vdprintf(int, const char*, va_list);
+int vsprintf(char*, const char*, va_list);
+int vsnprintf(char*, size_t, const char*, va_list);
+#if (defined(_GNU_SOURCE) || defined(_SLIBC_SOURCE)) && !defined(__PORTABLE)
+int vasprintf(char**, const char*, va_list);
+#endif
+
+
+
+#endif
+
diff --git a/include/stdlib.h b/include/stdlib.h
index 9340201..89712f9 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -102,5 +102,16 @@ void srand(unsigned int seed);
+/* TODO implement exit-functions */
+void abort(void) __noreturn;
+void _Exit(int) __noreturn;
+int atexit(void (*)(void));
+int on_exit(void (*)(int, void*), void*);
+void exit(int) __noreturn;
+int at_quick_exit (void (*) (void));
+void quick_exit(int) __noreturn;
+
+
+
#endif
diff --git a/include/string.h b/include/string.h
index d1eedd0..03c6acd 100644
--- a/include/string.h
+++ b/include/string.h
@@ -73,10 +73,8 @@ char* strerror(int)
* `LC_GLOBAL_LOCALE`, lest the behaviour is undefined.
* @return A description of the error.
*/
-/* TODO strerror_l
char* strerror_l(int, locale_t)
- __GCC_ONLY(__attribute__((warn_unused_result)));
-*/
+ __GCC_ONLY(__attribute__((warn_unused_result))); /* TODO attributes */
#if !defined(__PORTABLE)
diff --git a/include/unistd.h b/include/unistd.h
index f651867..45ec712 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -134,5 +134,14 @@ void* sbrk(ptrdiff_t) /* TODO implement sbrk */
+/* TODO implement exit-functions */
+void _exit(int) __noreturn;
+
+
+/* TODO implement I/O */
+int isatty(int);
+
+
+
#endif
diff --git a/src/assert.c b/src/assert.c
index 8e7561a..ffd61a3 100644
--- a/src/assert.c
+++ b/src/assert.c
@@ -50,7 +50,7 @@ void __assert_fail(const char* expression, int errnum, const char* file, int lin
tty, line, tty,
tty, file, tty,
tty, func, tty,
- tty, expression != NULL, (expression ? expression : stderror(errnum)), tty);
+ tty, expression != NULL, (expression ? expression : strerror(errnum)), tty);
fflush(NULL); /* Flush all streams. */
abort();
diff --git a/src/err.c b/src/err.c
index caa8d3f..b873a93 100644
--- a/src/err.c
+++ b/src/err.c
@@ -19,6 +19,7 @@
#include <error.h>
#include <errno.h>
#include <stdlib.h>
+#include <stdarg.h>
diff --git a/src/error.c b/src/error.c
index eb73276..c560d2a 100644
--- a/src/error.c
+++ b/src/error.c
@@ -20,6 +20,9 @@
#include <stdio.h>
#include <errno.h>
#include <stddef.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdarg.h>
@@ -85,7 +88,7 @@ void error_at_line(int status, int errnum, const char* filename,
{
va_list args;
va_start(args, format);
- verror_at_line(status, errnu, filename, linenum, format, args);
+ verror_at_line(status, errnum, filename, linenum, format, args);
va_end(args);
}
@@ -130,7 +133,7 @@ void verror_at_line(int status, int errnum, const char* filename,
}
fprintf(stderr, "%(: %(\033[35m%)%s%(\033[0m%): %(\033[32m%)%u%(\033[0m%)%)%(: %s%)%(: %)",
- filename != NULL, tty, filename, tty, tty, filenum, tty,
+ filename != NULL, tty, filename, tty, tty, linenum, tty,
errnum != 0, strerror(errnum) /* TODO strerror is not MT-Safe */, format != NULL);
if (filename != NULL)
@@ -185,5 +188,5 @@ volatile int error_one_per_line = 1;
*
* This is a GNU extension.
*/
-volatile void (*error_print_progname)(void) = NULL;
+void (*volatile error_print_progname)(void) = NULL;
diff --git a/src/slibc-error.c b/src/slibc-error.c
index 0680751..fd103d1 100644
--- a/src/slibc-error.c
+++ b/src/slibc-error.c
@@ -21,6 +21,7 @@
#include <unistd.h>
#include <string.h>
#include <stddef.h>
+#include <stdarg.h>
diff --git a/src/string/strerror.c b/src/string/strerror.c
index 87f3261..ccce049 100644
--- a/src/string/strerror.c
+++ b/src/string/strerror.c
@@ -40,7 +40,7 @@
*/
char* strerror(int errnum)
{
- return strerror_l(errnum, CURRENT_LOCALE /* TODO not defined */);
+ return strerror_l(errnum, 0 /* TODO CURRENT_LOCALE, not defined */);
}
@@ -63,7 +63,8 @@ char* strerror(int errnum)
char* strerror_l(int errnum, locale_t locale)
{
/* TODO implement strerror_l */
- return (void) errnum, (void) locale, NULL:
+ return strerror(errnum);
+ (void) locale;
}
diff --git a/src/wchar/wcsspn.c b/src/wchar/wcsspn.c
index 239b863..63dc60b 100644
--- a/src/wchar/wcsspn.c
+++ b/src/wchar/wcsspn.c
@@ -53,12 +53,16 @@ size_t wcsspn(const wchar_t* string, const wchar_t* skipset)
*/
size_t wcscspn(const wchar_t* string, const wchar_t* stopset)
{
- size_t end = wcslen(string);
- wchar_t* p;
+ size_t i, end = wcslen(string);
+ wchar_t* s;
wchar_t c;
while ((c = *stopset++))
- if (p = wcsnchr(string, c, end), p != NULL)
- end = (size_t)(p - string);
+ for (i = 0, s = string; *s && (i < end); i++, s++)
+ if (*s == c)
+ {
+ end = (size_t)(s - string);
+ break;
+ }
return end;
}