- add implementation of ksprintf and ksnprintf
- remove some typos git-svn-id: http://svn.lfbs.rwth-aachen.de/svn/scc/trunk/MetalSVM@201 315a16e6-25f9-4109-90ae-ca3045a26c18
This commit is contained in:
parent
6baf5119fb
commit
9cbe8781b2
4 changed files with 96 additions and 6 deletions
|
@ -22,11 +22,17 @@
|
|||
|
||||
#include <metalsvm/config.h>
|
||||
#include <metalsvm/stddef.h>
|
||||
#include <metalsvm/stdarg.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Forces all write operations
|
||||
*/
|
||||
int kflush(void);
|
||||
|
||||
/*
|
||||
* Works like the ANSI C function puts
|
||||
*/
|
||||
|
@ -38,20 +44,30 @@ int kputs(const char *);
|
|||
int kputchar(int);
|
||||
|
||||
/*
|
||||
* Work like the ANSI C function printf
|
||||
* Works like the ANSI C function printf
|
||||
*/
|
||||
int kprintf(const char*, ...);
|
||||
|
||||
/*
|
||||
* Forces all write operations
|
||||
/*
|
||||
* Works like the ANSI c function sprintf
|
||||
*/
|
||||
int kflush(void);
|
||||
int ksprintf(char *str, const char *format, ...);
|
||||
|
||||
/*
|
||||
* Works like the ANSI c function sprintf
|
||||
*/
|
||||
int ksnprintf(char *str, size_t size, const char *format, ...);
|
||||
|
||||
/*
|
||||
* Initialize the I/O functions
|
||||
*/
|
||||
int koutput_init(void);
|
||||
|
||||
/*
|
||||
* Scaled down version of printf(3)
|
||||
*/
|
||||
int kvprintf(char const *fmt, void (*func) (int, void *), void *arg, int radix, va_list ap);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
C_source = string.c stdio.c printf.c qdivrem.c udivdi3.c umoddi3.c
|
||||
C_source = string.c stdio.c printf.c sprintf.c qdivrem.c udivdi3.c umoddi3.c
|
||||
|
||||
OBJS += $(patsubst %.c, %.o, $(filter %.c, $(C_source)))
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
* all typedefs required have been added.
|
||||
*/
|
||||
|
||||
#include <eduos/string.h>
|
||||
#include <metalsvm/string.h>
|
||||
|
||||
#define __64BIT__
|
||||
|
||||
|
|
74
libkern/sprintf.c
Normal file
74
libkern/sprintf.c
Normal file
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* Copyright 2010 Stefan Lankes, Chair for Operating Systems,
|
||||
* RWTH Aachen University
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is part of MetalSVM.
|
||||
*/
|
||||
|
||||
#include <metalsvm/stdio.h>
|
||||
|
||||
typedef struct {
|
||||
char *str;
|
||||
size_t pos;
|
||||
size_t max;
|
||||
} sputchar_arg_t;
|
||||
|
||||
static void sputchar(int c, void *arg)
|
||||
{
|
||||
sputchar_arg_t *dest = (sputchar_arg_t *) arg;
|
||||
|
||||
if (dest->pos < dest->max) {
|
||||
dest->str[dest->pos] = (char)c;
|
||||
dest->pos++;
|
||||
}
|
||||
}
|
||||
|
||||
int ksnprintf(char *str, size_t size, const char *format, ...)
|
||||
{
|
||||
int ret;
|
||||
va_list ap;
|
||||
sputchar_arg_t dest;
|
||||
|
||||
dest.str = str;
|
||||
dest.pos = 0;
|
||||
dest.max = size;
|
||||
|
||||
va_start(ap, format);
|
||||
ret = kvprintf(format, sputchar, &dest, 10, ap);
|
||||
va_end(ap);
|
||||
|
||||
str[ret] = 0;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ksprintf(char *str, const char *format, ...)
|
||||
{
|
||||
int ret;
|
||||
va_list ap;
|
||||
sputchar_arg_t dest;
|
||||
|
||||
dest.str = str;
|
||||
dest.pos = 0;
|
||||
dest.max = (size_t) -1;
|
||||
|
||||
va_start(ap, format);
|
||||
ret = kvprintf(format, sputchar, &dest, 10, ap);
|
||||
va_end(ap);
|
||||
|
||||
str[ret] = 0;
|
||||
|
||||
return ret;
|
||||
}
|
Loading…
Add table
Reference in a new issue