Split libc/stdio/sprint.cpp into multiple files.

This commit is contained in:
Jonas 'Sortie' Termansen 2013-07-20 13:47:42 +02:00
parent edce6b9c2b
commit 91eb5f3af9
5 changed files with 119 additions and 33 deletions

View File

@ -80,10 +80,13 @@ stdio/getline.o \
stdio/rewind.o \
stdio/setbuf.o \
stdio/setvbuf.o \
stdio/sprint.o \
stdio/snprintf.o \
stdio/sprintf.o \
stdio/sscanf.o \
stdio/ungetc.o \
stdio/vfscanf.o \
stdio/vsnprintf.o \
stdio/vsprintf.o \
stdio/vsscanf.o \
stdlib/abort.o \
stdlib/abs.o \

36
libc/stdio/snprintf.cpp Normal file
View File

@ -0,0 +1,36 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013.
This file is part of the Sortix C Library.
The Sortix C Library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
The Sortix C Library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see <http://www.gnu.org/licenses/>.
stdio/snprintf.cpp
Prints a formatted string to a limited string.
*******************************************************************************/
#include <stdarg.h>
#include <stdio.h>
extern "C"
int snprintf(char* restrict str, size_t size, const char* restrict format, ...)
{
va_list list;
va_start(list, format);
int result = vsnprintf(str, size, format, list);
va_end(list);
return result;
}

35
libc/stdio/sprintf.cpp Normal file
View File

@ -0,0 +1,35 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013.
This file is part of the Sortix C Library.
The Sortix C Library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
The Sortix C Library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see <http://www.gnu.org/licenses/>.
stdio/sprintf.cpp
Prints a formatted string to a string.
*******************************************************************************/
#include <stdarg.h>
#include <stdio.h>
extern "C" int sprintf(char* restrict str, const char* restrict format, ...)
{
va_list list;
va_start(list, format);
int result = vsprintf(str, format, list);
va_end(list);
return result;
}

View File

@ -1,6 +1,6 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013.
This file is part of the Sortix C Library.
@ -17,15 +17,13 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see <http://www.gnu.org/licenses/>.
stdio/sprint.cpp
Provides the stubs for the sprintf family of functions.
stdio/vsnprintf.cpp
Prints a formatted string to a limited string.
*******************************************************************************/
#include <stddef.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
typedef struct vsnprintf_struct
@ -36,7 +34,8 @@ typedef struct vsnprintf_struct
size_t written;
} vsnprintf_t;
static size_t StringPrintCallback(void* user, const char* string, size_t stringlen)
static size_t StringPrintCallback(void* user, const char* string,
size_t stringlen)
{
vsnprintf_t* info = (vsnprintf_t*) user;
if ( info->produced < info->size )
@ -50,37 +49,17 @@ static size_t StringPrintCallback(void* user, const char* string, size_t stringl
return stringlen;
}
extern "C" int vsnprintf(char* restrict str, size_t size, const char* restrict format, va_list list)
extern "C"
int vsnprintf(char* restrict str, size_t size, const char* restrict format,
va_list list)
{
vsnprintf_t info;
info.str = str;
info.size = (size) ? size-1 : 0;
info.size = size ? size-1 : 0;
info.produced = 0;
info.written = 0;
vprintf_callback(StringPrintCallback, &info, format, list);
if ( size ) { info.str[info.written] = '\0'; }
if ( size )
info.str[info.written] = '\0';
return (int) info.produced;
}
extern "C" int snprintf(char* restrict str, size_t size, const char* restrict format, ...)
{
va_list list;
va_start(list, format);
int result = vsnprintf(str, size, format, list);
va_end(list);
return result;
}
extern "C" int vsprintf(char* restrict str, const char* restrict format, va_list list)
{
return vsnprintf(str, SIZE_MAX, format, list);
}
extern "C" int sprintf(char* restrict str, const char* restrict format, ...)
{
va_list list;
va_start(list, format);
int result = vsprintf(str, format, list);
va_end(list);
return result;
}

33
libc/stdio/vsprintf.cpp Normal file
View File

@ -0,0 +1,33 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013.
This file is part of the Sortix C Library.
The Sortix C Library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
The Sortix C Library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see <http://www.gnu.org/licenses/>.
stdio/vsprintf.cpp
Prints a formatted string to a string.
*******************************************************************************/
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
extern "C"
int vsprintf(char* restrict str, const char* restrict format, va_list list)
{
return vsnprintf(str, SIZE_MAX, format, list);
}