forked from KolibriOS/kolibrios
kolibri-libc:
Move to folder with tcc. Part 1 git-svn-id: svn://kolibrios.org@8793 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
46
programs/develop/ktcc/trunk/libc.obj/source/stdio/sscanf.c
Normal file
46
programs/develop/ktcc/trunk/libc.obj/source/stdio/sscanf.c
Normal file
@@ -0,0 +1,46 @@
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
int virtual_getc_str(void *sp, const void *obj)
|
||||
// get next chat from string obj, save point is ptr to string char ptr
|
||||
{
|
||||
int ch;
|
||||
const char *s = (const char *)obj;
|
||||
const char**spc= (const char**)sp;
|
||||
if (!s || !spc) return EOF; // error
|
||||
|
||||
if (!*spc) *spc = s; // first call, init savepoint
|
||||
|
||||
if (!**spc) return EOF; // EOS
|
||||
|
||||
ch = **spc; (*spc)++ ;
|
||||
|
||||
return ch;
|
||||
}
|
||||
|
||||
void virtual_ungetc_str(void *sp, int c, const void *obj)
|
||||
// if can, one step back savepoint in s
|
||||
{
|
||||
const char *s = (const char *)obj;
|
||||
const char**spc= (const char**)sp;
|
||||
|
||||
if (s && spc && *spc > s) (*spc)--;
|
||||
}
|
||||
|
||||
int vsscanf ( const char * s, const char * format, va_list arg )
|
||||
{
|
||||
return format_scan(s, format, arg, &virtual_getc_str, &virtual_ungetc_str);
|
||||
};
|
||||
|
||||
int sscanf ( const char * s, const char * format, ...)
|
||||
{
|
||||
va_list arg;
|
||||
int n;
|
||||
va_start(arg, format);
|
||||
|
||||
n = vsscanf(s, format, arg);
|
||||
|
||||
va_end(arg);
|
||||
return n;
|
||||
}
|
||||
|
Reference in New Issue
Block a user