uc-sdk
Main Page
Related Pages
Modules
Classes
Files
File List
File Members
All
Classes
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Groups
Pages
yscanf.c
Go to the documentation of this file.
1
#include "
stdio.h
"
2
3
struct
opaque_t
{
4
union
{
5
const
char
*
p
;
6
int
fd
;
7
};
8
uint8_t
bsize
;
9
char
backbuffer
[3];
10
};
11
12
static
int
str_getc(
void
* _opaque) {
13
struct
opaque_t
* opaque = (
struct
opaque_t
*) _opaque;
14
int
r;
15
16
if
(opaque->
bsize
)
17
return
opaque->
backbuffer
[--(opaque->
bsize
)];
18
19
r = *(opaque->
p
++);
20
21
return
r ? r : EOF;
22
}
23
24
static
int
file_getc(
void
* _opaque) {
25
struct
opaque_t
* opaque = (
struct
opaque_t
*) _opaque;
26
uint8_t v;
27
28
if
(opaque->
bsize
)
29
return
opaque->
backbuffer
[--(opaque->
bsize
)];
30
31
if
(
read
(opaque->
fd
, &v, 1) != 1)
32
return
EOF;
33
return
v;
34
}
35
36
static
void
scanf_ungetc(
void
* _opaque,
int
c) {
37
struct
opaque_t
* opaque = (
struct
opaque_t
*) _opaque;
38
39
if
(opaque->
bsize
<
sizeof
(opaque->
backbuffer
))
40
opaque->
backbuffer
[opaque->
bsize
++] = c;
41
}
42
43
int
vsscanf
(
const
char
* str,
const
char
* format, va_list ap) {
44
struct
opaque_t
opaque;
45
opaque.
p
= str;
46
opaque.
bsize
= 0;
47
return
vxscanf
(str_getc, scanf_ungetc, &opaque, format, ap);
48
}
49
50
int
vdscanf
(
int
fd
,
const
char
* format, va_list ap) {
51
struct
opaque_t
opaque;
52
opaque.
fd
=
fd
;
53
opaque.
bsize
= 0;
54
return
vxscanf
(file_getc, scanf_ungetc, &opaque, format, ap);
55
}
libc
src
yscanf.c
Generated on Fri Nov 15 2013 05:00:19 for uc-sdk by
1.8.4