-
Notifications
You must be signed in to change notification settings - Fork 10
/
dev_file_read_wstr.bas
58 lines (44 loc) · 1.16 KB
/
dev_file_read_wstr.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/' file device '/
#include "fb.bi"
extern "C"
function fb_DevFileReadWstr( handle as FB_FILE ptr, dst as FB_WCHAR ptr, pchars as size_t ptr ) as long
dim as FILE ptr fp
dim as size_t chars
dim as ubyte ptr buffer
dim as long errorRet = FB_RTERROR_OK
FB_LOCK()
if ( handle = NULL ) then
fp = stdin
else
fp = cast(FILE ptr, handle->opaque)
if ( fp = stdout orelse fp = stderr ) then
fp = stdin
end if
if ( fp = NULL ) then
errorRet = FB_RTERROR_ILLEGALFUNCTIONCALL
goto functionExit
end if
end if
chars = *pchars
buffer = allocate( chars + 1 )
if ( buffer = Null ) then
errorRet = FB_RTERROR_ILLEGALFUNCTIONCALL
goto functionExit
end if
/' do read '/
chars = fread( buffer, 1, chars, fp )
buffer[chars] = 0
/' convert to wchar, file should be opened with the ENCODING option
to allow UTF characters to be read '/
fb_wstr_ConvFromA( dst, chars, buffer )
deallocate( buffer )
/' fill with nulls if at eof '/
if ( chars <> *pchars ) then
memset( @dst[chars], 0, (*pchars - chars) * sizeof( FB_WCHAR ) )
end if
*pchars = chars
functionExit:
FB_UNLOCK()
return fb_ErrorSetNum( errorRet )
end function
end extern