forked from ImortisInglorian/fbrtLib
-
Notifications
You must be signed in to change notification settings - Fork 1
/
dev_file_encod_write.bas
39 lines (30 loc) · 993 Bytes
/
dev_file_encod_write.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/' UTF-encoded file writing '/
#include "fb.bi"
extern "C"
function fb_DevFileWriteEncod( handle as FB_FILE ptr, buffer as any const ptr, chars as size_t ) as long
dim as FILE ptr fp
dim as ubyte ptr encod_buffer
dim as ssize_t bytes
FB_LOCK()
fp = cast(FILE ptr, handle->opaque)
if ( fp = NULL ) then
FB_UNLOCK()
return fb_ErrorSetNum( FB_RTERROR_ILLEGALFUNCTIONCALL )
end if
/' convert (note: encoded file can only be opened in text-mode, so no
PUT# is allowed, no binary data should be emitted ever) '/
encod_buffer = fb_CharToUTF( handle->encod, cast(ubyte const ptr, buffer), chars, NULL, @bytes )
if ( encod_buffer <> NULL ) then
/' do write '/
if ( fwrite( encod_buffer, 1, bytes, fp ) <> cast(size_t, bytes) ) then
FB_UNLOCK()
return fb_ErrorSetNum( FB_RTERROR_FILEIO )
end if
if ( encod_buffer <> buffer ) then
free( encod_buffer )
end if
end if
FB_UNLOCK()
return fb_ErrorSetNum( FB_RTERROR_OK )
end function
end extern