1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00

Optimize puts and fputs.

This commit is contained in:
Jonas 'Sortie' Termansen 2015-05-21 21:36:01 +02:00
parent 0fc3d70716
commit fb29ff42e0
2 changed files with 13 additions and 6 deletions

View file

@ -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;
}

View file

@ -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 <stdio.h>
#include <string.h>
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;
}