FreeBASIC
0.91.0
Main Page
Data Structures
Files
File List
Globals
dev_file_write_wstr.c
Go to the documentation of this file.
1
/* wstring to ascii file writing function */
2
3
#include "
fb.h
"
4
5
int
fb_DevFileWriteWstr
(
FB_FILE
*
handle
,
const
FB_WCHAR
* src,
size_t
chars )
6
{
7
FILE *fp;
8
char
*
buffer
;
9
int
res;
10
11
FB_LOCK
();
12
13
fp = (FILE*) handle->
opaque
;
14
15
if
( fp ==
NULL
) {
16
FB_UNLOCK
();
17
return
fb_ErrorSetNum
(
FB_RTERROR_ILLEGALFUNCTIONCALL
);
18
}
19
20
if
( chars <
FB_LOCALBUFF_MAXLEN
)
21
buffer = alloca( chars + 1 );
22
else
23
buffer = malloc( chars + 1 );
24
25
/* convert to ascii, file should be opened with the ENCODING option
26
to allow UTF characters to be written */
27
fb_wstr_ConvToA
( buffer, src, chars );
28
29
/* do write */
30
res = fwrite( (
void
*)buffer, 1, chars, fp ) == chars;
31
32
if
( chars >=
FB_LOCALBUFF_MAXLEN
)
33
free( buffer );
34
35
FB_UNLOCK
();
36
37
return
fb_ErrorSetNum
( (res?
FB_RTERROR_OK
:
FB_RTERROR_FILEIO
) );
38
}
rtlib
dev_file_write_wstr.c
Generated on Thu Jan 23 2014 19:40:08 for FreeBASIC by
1.8.4