diff --git a/libc/stdio/fputs_unlocked.cpp b/libc/stdio/fputs_unlocked.cpp index aad83945..777353ad 100644 --- a/libc/stdio/fputs_unlocked.cpp +++ b/libc/stdio/fputs_unlocked.cpp @@ -1,6 +1,6 @@ /******************************************************************************* - Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013, 2014. + Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013, 2014, 2015. This file is part of the Sortix C Library. @@ -28,8 +28,7 @@ extern "C" int fputs_unlocked(const char* str, FILE* fp) { size_t stringlen = strlen(str); - size_t result = fwrite_unlocked(str, 1, stringlen, fp); - if ( result < stringlen ) + if ( fwrite_unlocked(str, 1, stringlen, fp) < stringlen ) return EOF; - return result; + return 0; } diff --git a/libc/stdio/puts.cpp b/libc/stdio/puts.cpp index 84f9b6a1..5027e67d 100644 --- a/libc/stdio/puts.cpp +++ b/libc/stdio/puts.cpp @@ -1,6 +1,6 @@ /******************************************************************************* - Copyright(C) Jonas 'Sortie' Termansen 2011, 2014. + Copyright(C) Jonas 'Sortie' Termansen 2011, 2014, 2015. This file is part of the Sortix C Library. @@ -23,8 +23,16 @@ *******************************************************************************/ #include +#include extern "C" int puts(const char* str) { - return printf("%s\n", str) < 0 ? EOF : 1; + int ret = 0; + flockfile(stdout); + size_t stringlen = strlen(str); + if ( fwrite_unlocked(str, 1, stringlen, stdout) < stringlen || + fputc_unlocked('\n', stdout) == EOF ) + ret = EOF; + funlockfile(stdout); + return ret; }