FreeBASIC
0.91.0
Main Page
Data Structures
Files
File List
Globals
file_putback_wstr.c
Go to the documentation of this file.
1
/* ungetwc-like function */
2
3
#include "
fb.h
"
4
5
int
fb_FilePutBackWstrEx
(
FB_FILE
*
handle
,
const
FB_WCHAR
*src,
size_t
chars )
6
{
7
int
res;
8
size_t
bytes;
9
char
*dst;
10
11
if
( !
FB_HANDLE_USED
(handle) )
12
return
fb_ErrorSetNum
(
FB_RTERROR_ILLEGALFUNCTIONCALL
);
13
14
FB_LOCK
();
15
16
res =
fb_ErrorSetNum
(
FB_RTERROR_OK
);
17
18
/* UTF? */
19
if
( handle->
encod
!=
FB_FILE_ENCOD_ASCII
)
20
bytes = chars *
sizeof
(
FB_WCHAR
);
21
else
22
bytes = chars;
23
24
if
( handle->
putback_size
+ bytes >
sizeof
(handle->
putback_buffer
) )
25
{
26
res =
fb_ErrorSetNum
(
FB_RTERROR_FILEIO
);
27
}
28
else
29
{
30
if
( handle->
putback_size
)
31
memmove( handle->
putback_buffer
+ bytes,
32
handle->
putback_buffer
,
33
handle->
putback_size
);
34
35
handle->
putback_size
+= bytes;
36
37
/* note: if encoding != ASCII, putback buffer will be in
38
wchar format, not in UTF */
39
if
( handle->
encod
!=
FB_FILE_ENCOD_ASCII
)
40
memcpy( handle->
putback_buffer
, src, bytes );
41
else
42
{
43
/* wchar to char */
44
dst = handle->
putback_buffer
;
45
while
( chars-- > 0 )
46
*dst++ = *src++;
47
}
48
}
49
50
FB_UNLOCK
();
51
52
return
res;
53
}
54
55
FBCALL
int
fb_FilePutBackWstr
(
int
fnum,
const
FB_WCHAR
*src,
size_t
chars )
56
{
57
return
fb_FilePutBackWstrEx
(
FB_FILE_TO_HANDLE
(fnum), src, chars );
58
}
rtlib
file_putback_wstr.c
Generated on Thu Jan 23 2014 19:40:11 for FreeBASIC by
1.8.4