diff --git a/include/bits/stdio.h b/include/bits/stdio.h index 351dc1e774ba5cb5a145f522035e9e96a0e85e10..d990dae61b59b1ce111bfe36a2d8f2212150b356 100644 --- a/include/bits/stdio.h +++ b/include/bits/stdio.h @@ -2,21 +2,39 @@ #define _BITS_STDIO_H int fprintf(FILE * stream, const char * fmt, ...) { - int ret; - va_list ap; - va_start(ap, fmt); - ret = vfprintf(stream, fmt, ap); - va_end(ap); - return ret; + int ret; + va_list ap; + va_start(ap, fmt); + ret = vfprintf(stream, fmt, ap); + va_end(ap); + return ret; } int printf(const char * fmt, ...) { - int ret; - va_list ap; - va_start(ap, fmt); - ret = vprintf(fmt, ap); - va_end(ap); - return ret; + int ret; + va_list ap; + va_start(ap, fmt); + ret = vprintf(fmt, ap); + va_end(ap); + return ret; +} + +int snprintf(char *s, size_t n, const char * fmt, ...) { + int ret; + va_list ap; + va_start(ap, fmt); + ret = vsnprintf(s, n, fmt, ap); + va_end(ap); + return ret; +} + +int sprintf(char *s, const char * fmt, ...) { + int ret; + va_list ap; + va_start(ap, fmt); + ret = vsprintf(s, fmt, ap); + va_end(ap); + return ret; } #endif /* _BITS_STDIO_H */ diff --git a/include/sys/types.h b/include/sys/types.h index 7312acfd4bb99cdca80da29228c06e194231d747..0db183a79686cb004db55240b67f0d7a017adcbc 100644 --- a/include/sys/types.h +++ b/include/sys/types.h @@ -32,4 +32,11 @@ typedef int clockid_t; typedef void* timer_t; +#ifdef __linux__ +#define _SC_PAGE_SIZE 30 +#endif +#ifdef __redox__ +#define _SC_PAGE_SIZE 8 +#endif + #endif /* _SYS_TYPES_H */ diff --git a/tests/.gitignore b/tests/.gitignore index 620d8c72440cdb7d870a79e4ce161596092d3106..43fdd536664e672d2368b340b439c7590d3761d9 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -26,6 +26,7 @@ /printf /rmdir /setid +/sprintf /stdlib/strtol /unlink /write diff --git a/tests/Makefile b/tests/Makefile index ae73d603b19f36217f1cd5eeb74f99d01cfbf736..3b732f4ccaafec82acc90c402d64526c798f46d7 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -21,6 +21,7 @@ BINS=\ rmdir \ setid \ sleep \ + sprintf \ stdlib/strtol \ unlink \ write diff --git a/tests/sprintf.c b/tests/sprintf.c new file mode 100644 index 0000000000000000000000000000000000000000..e91f9baee3a3540ba83eb6ccc5fe8e4df9db8fb6 --- /dev/null +++ b/tests/sprintf.c @@ -0,0 +1,30 @@ + +#include <stdio.h> + +int main(int argc, char ** argv) { + char buffer[72]; + int ret = sprintf( + buffer, + "This string fits in the buffer because it is only %d bytes in length", + 68 + ); + + if (ret) { + printf("Failed! %d\n", ret); + return -1; + } + + ret = snprintf( + buffer, + 72, + "This string is way longer and does not fit in the buffer because it %d bytes in length", + 87 + ); + + if (!ret) { + return 0; + } else { + printf("Failed! %d", ret); + return -1; + } +}