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:
parent
0fc3d70716
commit
fb29ff42e0
2 changed files with 13 additions and 6 deletions
|
@ -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.
|
This file is part of the Sortix C Library.
|
||||||
|
|
||||||
|
@ -28,8 +28,7 @@
|
||||||
extern "C" int fputs_unlocked(const char* str, FILE* fp)
|
extern "C" int fputs_unlocked(const char* str, FILE* fp)
|
||||||
{
|
{
|
||||||
size_t stringlen = strlen(str);
|
size_t stringlen = strlen(str);
|
||||||
size_t result = fwrite_unlocked(str, 1, stringlen, fp);
|
if ( fwrite_unlocked(str, 1, stringlen, fp) < stringlen )
|
||||||
if ( result < stringlen )
|
|
||||||
return EOF;
|
return EOF;
|
||||||
return result;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.
|
This file is part of the Sortix C Library.
|
||||||
|
|
||||||
|
@ -23,8 +23,16 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
extern "C" int puts(const char* str)
|
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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue