FreeBASIC
0.91.0
Main Page
Data Structures
Files
File List
Globals
dev_file_encod_write.c
Go to the documentation of this file.
1
/* UTF-encoded file writing */
2
3
#include "
fb.h
"
4
5
int
fb_DevFileWriteEncod
(
FB_FILE
*
handle
,
const
void
*
buffer
,
size_t
chars )
6
{
7
FILE *fp;
8
char
*encod_buffer;
9
ssize_t bytes;
10
11
FB_LOCK
();
12
13
fp = (FILE*) handle->
opaque
;
14
if
( fp ==
NULL
) {
15
FB_UNLOCK
();
16
return
fb_ErrorSetNum
(
FB_RTERROR_ILLEGALFUNCTIONCALL
);
17
}
18
19
/* convert (note: encoded file can only be opened in text-mode, so no
20
PUT# is allowed, no binary data should be emitted ever) */
21
encod_buffer =
fb_CharToUTF
( handle->
encod
,
22
(
const
char
*)buffer,
23
chars,
24
NULL
,
25
&bytes );
26
27
if
( encod_buffer !=
NULL
)
28
{
29
/* do write */
30
if
( fwrite( encod_buffer, 1, bytes, fp ) != bytes )
31
{
32
FB_UNLOCK
();
33
return
fb_ErrorSetNum
(
FB_RTERROR_FILEIO
);
34
}
35
36
if
( encod_buffer != buffer )
37
free( encod_buffer );
38
}
39
40
FB_UNLOCK
();
41
42
return
fb_ErrorSetNum
(
FB_RTERROR_OK
);
43
}
rtlib
dev_file_encod_write.c
Generated on Thu Jan 23 2014 19:40:08 for FreeBASIC by
1.8.4