FreeBASIC
0.91.0
Main Page
Data Structures
Files
File List
Globals
file_inputstr.c
Go to the documentation of this file.
1
/* input$ function */
2
3
#include "
fb.h
"
4
5
FBCALL
FBSTRING
*
fb_FileStrInput
( ssize_t bytes,
int
fnum )
6
{
7
FB_FILE
*
handle
;
8
FBSTRING
*dst;
9
size_t
len;
10
int
res =
FB_RTERROR_OK
;
11
12
fb_DevScrnInit_Read
( );
13
14
FB_LOCK
();
15
16
handle =
FB_FILE_TO_HANDLE
(fnum);
17
if
( !
FB_HANDLE_USED
(handle) )
18
{
19
FB_UNLOCK
();
20
return
&
__fb_ctx
.
null_desc
;
21
}
22
23
dst =
fb_hStrAllocTemp
(
NULL
, bytes );
24
if
( dst!=
NULL
)
25
{
26
size_t
read_count = 0;
27
if
(
FB_HANDLE_IS_SCREEN
(handle) )
28
{
29
dst->
data
[0] = 0;
30
while
( read_count!=bytes ) {
31
res =
fb_FileGetDataEx
( handle,
32
0,
33
dst->
data
+ read_count,
34
bytes - read_count,
35
&len,
36
TRUE
,
37
FALSE
);
38
if
( res!=
FB_RTERROR_OK
) {
39
break
;
40
}
41
read_count += len;
42
43
/* add the null-term */
44
dst->
data
[read_count] =
'\0'
;
45
}
46
}
47
else
48
{
49
res =
fb_FileGetDataEx
( handle,
50
0,
51
dst->
data
,
52
bytes,
53
&len,
54
TRUE
,
55
FALSE
);
56
if
( res==
FB_RTERROR_OK
) {
57
read_count += len;
58
}
59
}
60
61
/* add the null-term */
62
dst->
data
[read_count] =
'\0'
;
63
64
if
( read_count != bytes )
65
{
66
fb_hStrSetLength
( dst, read_count );
67
}
68
}
69
else
70
{
71
res =
FB_RTERROR_OUTOFMEM
;
72
}
73
74
if
( res !=
FB_RTERROR_OK
)
75
{
76
if
( dst !=
NULL
)
77
fb_hStrDelTemp
( dst );
78
79
dst = &
__fb_ctx
.
null_desc
;
80
}
81
82
FB_UNLOCK
();
83
84
return
dst;
85
}
86
rtlib
file_inputstr.c
Generated on Thu Jan 23 2014 19:40:11 for FreeBASIC by
1.8.4