From 44bd67431cf04d80ac5eb12f0b1e95c9c2bf26ce Mon Sep 17 00:00:00 2001 From: Yatis Date: Wed, 14 Oct 2020 15:18:10 +0200 Subject: [PATCH] Fix norme + move arch-specific header --- include/{ => arch}/fx9860g/unistd_32.h | 0 include/{ => arch}/fxcg50/unistd_32.h | 0 include/{ => arch}/vhex/unistd_32.h | 0 include/asm/unistd_32.h | 6 +++--- make/Makefile.default | 4 ++-- src/stdio/dprintf.c | 4 ++++ src/stdio/internal/printf_actions.c | 18 ++++++------------ src/stdio/printf.c | 6 ++++++ src/stdio/puts.c | 5 +++++ src/stdio/snprintf.c | 6 ++++++ src/stdio/sprintf.c | 6 ++++++ src/stdio/vdprintf.c | 6 ++++++ src/stdio/vsnprintf.c | 7 ++++++- src/stdio/vsprintf.c | 8 +++++++- src/stdlib/reallocarray.c | 2 +- src/threads/mutex.c | 6 ++---- 16 files changed, 60 insertions(+), 24 deletions(-) rename include/{ => arch}/fx9860g/unistd_32.h (100%) rename include/{ => arch}/fxcg50/unistd_32.h (100%) rename include/{ => arch}/vhex/unistd_32.h (100%) diff --git a/include/fx9860g/unistd_32.h b/include/arch/fx9860g/unistd_32.h similarity index 100% rename from include/fx9860g/unistd_32.h rename to include/arch/fx9860g/unistd_32.h diff --git a/include/fxcg50/unistd_32.h b/include/arch/fxcg50/unistd_32.h similarity index 100% rename from include/fxcg50/unistd_32.h rename to include/arch/fxcg50/unistd_32.h diff --git a/include/vhex/unistd_32.h b/include/arch/vhex/unistd_32.h similarity index 100% rename from include/vhex/unistd_32.h rename to include/arch/vhex/unistd_32.h diff --git a/include/asm/unistd_32.h b/include/asm/unistd_32.h index 54cf52e..29c86c7 100644 --- a/include/asm/unistd_32.h +++ b/include/asm/unistd_32.h @@ -3,11 +3,11 @@ // ABI redirection #if defined(__SUPPORT_VHEX_KERNEL) -# include +# include #elif defined(__SUPPORT_CASIO_ABI_FX9860G) -# include +# include #elif defined(__SUPPORT_CASIO_ABI_FXCG50) -# include +# include #endif #endif /*__ASM_UNISTD_32_H__*/ diff --git a/make/Makefile.default b/make/Makefile.default index 2fb0efe..9ee57f6 100644 --- a/make/Makefile.default +++ b/make/Makefile.default @@ -34,8 +34,8 @@ #--- MAJOR := 0 MINOR := 2 -PATCH := 3 -EXTRAVERSION := -alpha +PATCH := 4 +EXTRAVERSION := -beta #--- diff --git a/src/stdio/dprintf.c b/src/stdio/dprintf.c index f001ff3..f7f5bbc 100644 --- a/src/stdio/dprintf.c +++ b/src/stdio/dprintf.c @@ -1,5 +1,9 @@ #include +/* +** The function dprintf() is the same as fprintf() except that it outputs to a +** file descriptor, fd, instead of to a stdio stream. +*/ int dprintf(int fd, const char *restrict format, ...) { va_list ap; diff --git a/src/stdio/internal/printf_actions.c b/src/stdio/internal/printf_actions.c index 14f6e1b..df52f2c 100644 --- a/src/stdio/internal/printf_actions.c +++ b/src/stdio/internal/printf_actions.c @@ -31,8 +31,7 @@ static void base_to_str(struct printf_opt *opt, uint32_t num, int base, int digi char *hexa = (opt->uppercase == 1) ? "0123456789ABCDEF" : "0123456789abcdef"; opt->digits = 0; - while (num != 0 || opt->digits < digits) - { + while (num != 0 || opt->digits < digits) { opt->format[opt->digits++] = hexa[num % base]; num = num / base; } @@ -49,8 +48,7 @@ static void disp_format(struct printf_opt *opt) (*opt->disp_char)(opt, opt->base[1]); // padding - if (opt->flags.minus == 1 && opt->width > opt->digits) - { + if (opt->flags.minus == 1 && opt->width > opt->digits) { int total = opt->digits + (opt->sign != '\0') + (opt->base[0] != '\0') + (opt->base[1] != '\0'); total = opt->width - total; @@ -65,8 +63,7 @@ static void disp_format(struct printf_opt *opt) (*opt->disp_char)(opt, opt->format[opt->digits]); // padding - if (opt->flags.minus == 0 && opt->width > saved_digits) - { + if (opt->flags.minus == 0 && opt->width > saved_digits) { int total = saved_digits + (opt->sign != '\0') + (opt->base[0] != '\0') + (opt->base[1] != '\0'); total = opt->width - total; @@ -81,8 +78,7 @@ static void disp_format(struct printf_opt *opt) //--- static uint32_t get_arg_i(struct printf_opt *opt) { - switch (opt->lenght) - { + switch (opt->lenght) { case 0: return ((signed char)va_arg(opt->ap, int)); case 1: return ((short int)va_arg(opt->ap, int)); case 2: return (va_arg(opt->ap, long int)); @@ -96,8 +92,7 @@ static uint32_t get_arg_i(struct printf_opt *opt) static uint32_t get_arg_u(struct printf_opt *opt) { - switch (opt->lenght) - { + switch (opt->lenght) { case 0: return ((unsigned char)va_arg(opt->ap, int)); case 1: return ((unsigned short int)va_arg(opt->ap, int)); case 2: return (va_arg(opt->ap, unsigned long int)); @@ -165,8 +160,7 @@ static void action_uint(struct printf_opt *opt, char n) int base; // Get appropriate base - switch (n) - { + switch (n) { case 'o': base = 8; break; case 'x': base = 16; break; default: base = 10; break; diff --git a/src/stdio/printf.c b/src/stdio/printf.c index a67b524..88feb6e 100644 --- a/src/stdio/printf.c +++ b/src/stdio/printf.c @@ -1,6 +1,12 @@ #include #include +/* +** printf() write the output under the control of a format string that specifies +** how subsequent arguments (or arguments accessed via the variable-length +** argument facilities of stdarg(3)) are converted for output then write to +** the STDOUT. +*/ int printf(const char *restrict format, ...) { va_list ap; diff --git a/src/stdio/puts.c b/src/stdio/puts.c index d11bec8..418dcc8 100644 --- a/src/stdio/puts.c +++ b/src/stdio/puts.c @@ -2,6 +2,10 @@ #include #include +/* +** puts() writes the string s and a trailing newline to stdout. +** FIXME: check last write error ! +*/ int puts(const char *s) { size_t size; @@ -9,5 +13,6 @@ int puts(const char *s) size = strlen(s); n = write(STDOUT_FILENO, s, size); + write(STDOUT_FILENO, "\n", 1); return (-(n == size)); } diff --git a/src/stdio/snprintf.c b/src/stdio/snprintf.c index e983f49..08cf2c5 100644 --- a/src/stdio/snprintf.c +++ b/src/stdio/snprintf.c @@ -1,5 +1,11 @@ #include +/* +** sprintf(), snprintf(), vsprintf() and vsnprintf() write the output under the +** control of a format string that specifies how subsequent arguments (or +** arguments accessed via the variable-length argument facilities of stdarg(3)) +** are converted for output then write to the character string str. +*/ int snprintf(char *restrict str, size_t size, const char *restrict format, ...) { va_list ap; diff --git a/src/stdio/sprintf.c b/src/stdio/sprintf.c index 22ba62e..e6aa357 100644 --- a/src/stdio/sprintf.c +++ b/src/stdio/sprintf.c @@ -1,5 +1,11 @@ #include +/* +** sprintf(), snprintf(), vsprintf() and vsnprintf() write the output under the +** control of a format string that specifies how subsequent arguments (or +** arguments accessed via the variable-length argument facilities of stdarg(3)) +** are converted for output then write to the character string str. +*/ int sprintf(char *restrict str, const char *restrict format, ...) { va_list ap; diff --git a/src/stdio/vdprintf.c b/src/stdio/vdprintf.c index 1a8f445..9527df7 100644 --- a/src/stdio/vdprintf.c +++ b/src/stdio/vdprintf.c @@ -26,6 +26,12 @@ static void disp_char(struct printf_opt *opt, char n) opt->buffer[opt->buffer_cursor++] = n; } +/* +** The functions vdprintf() are equivalent to the dprintf() except that they +** are called with a va_list instead of a variable number of arguments. These +** functions do not call the va_end macro. Because they invoke the va_arg macro, +** the value of ap is undefined after the call. +*/ int vdprintf(int fd, const char *restrict format, va_list ap) { extern int printf_common(struct printf_opt *opt, const char *restrict format); diff --git a/src/stdio/vsnprintf.c b/src/stdio/vsnprintf.c index 6d83871..2a79711 100644 --- a/src/stdio/vsnprintf.c +++ b/src/stdio/vsnprintf.c @@ -18,6 +18,12 @@ static void disp_fflush(struct printf_opt *opt) opt->str[opt->buffer_cursor] = '\0'; } +/* +** The functions vsnprintf() are equivalent to the snprintf() except that they +** are called with a va_list instead of a variable number of arguments. These +** functions do not call the va_end macro. Because they invoke the va_arg macro, +** the value of ap is undefined after the call. +*/ int vsnprintf(char *restrict str, size_t size, const char *restrict format, va_list ap) { extern int printf_common(struct printf_opt *opt, const char *restrict format); @@ -30,4 +36,3 @@ int vsnprintf(char *restrict str, size_t size, const char *restrict format, va_l va_copy(opt.ap, ap); return (printf_common(&opt, format) + 1); } - diff --git a/src/stdio/vsprintf.c b/src/stdio/vsprintf.c index 7c45220..a9cdd9d 100644 --- a/src/stdio/vsprintf.c +++ b/src/stdio/vsprintf.c @@ -1,6 +1,12 @@ #include +/* +** The functions vsprintf() are equivalent to the sprintf() except that they +** are called with a va_list instead of a variable number of arguments. These +** functions do not call the va_end macro. Because they invoke the va_arg macro, +** the value of ap is undefined after the call. +*/ int vsprintf(char *restrict str, const char *restrict format, va_list ap) { - return (vsnprintf(str, 65535, format, ap)); + return (vsnprintf(str, 65535, format, ap)); } diff --git a/src/stdlib/reallocarray.c b/src/stdlib/reallocarray.c index 5ac0da3..493e996 100644 --- a/src/stdlib/reallocarray.c +++ b/src/stdlib/reallocarray.c @@ -15,5 +15,5 @@ */ void *reallocarray(void *ptr, size_t nmemb, size_t size) { - return (realloc(ptr, nmemb * size)); + return (realloc(ptr, nmemb * size)); } diff --git a/src/threads/mutex.c b/src/threads/mutex.c index a8efdce..e1b71ff 100644 --- a/src/threads/mutex.c +++ b/src/threads/mutex.c @@ -25,8 +25,7 @@ int mtx_lock(mtx_t *__mutex) return (-1); // Wait util the mutex is unlocked - while (1) - { + while (1) { // Check if the mutex is unlock __thread_atomic_start(); if (__mutex->lock == 0) @@ -62,8 +61,7 @@ int mtx_trylock(mtx_t *__mutex) // Check if the mutex is already free int ret = -1; - if (__mutex->lock == 0) - { + if (__mutex->lock == 0) { //TODO: handle mutex type !! (void)__mutex->type;