-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathdev_pipe_open.bas
89 lines (68 loc) · 2.09 KB
/
dev_pipe_open.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/' file device '/
#include "fb.bi"
extern "C"
#if defined(HOST_XBOX) or defined(HOST_JS)
function fb_DevPipeOpen( handle as FB_FILE ptr, filename as const ubyte ptr, filename_len ) as long
return fb_ErrorSetNum( FB_RTERROR_ILLEGALFUNCTIONCALL )
end function
#else
dim shared as FB_FILE_HOOKS hooks_dev_pipe = ( _
@fb_DevFileEof _
, @fb_DevPipeClose _
, NULL _
, NULL _
, @fb_DevFileRead _
, @fb_DevFileReadWstr _
, @fb_DevFileWrite _
, @fb_DevFileWriteWstr _
, NULL _
, NULL _
, @fb_DevFileReadLine _
, @fb_DevFileReadLineWstr _
, NULL _
, @fb_DevFileFlush )
function fb_DevPipeOpen( handle as FB_FILE ptr, filename as const ubyte ptr, filename_len as size_t ) as long
dim as long res = fb_ErrorSetNum( FB_RTERROR_OK )
dim as FILE ptr fp = NULL
dim as ubyte ptr openmask = NULL
FB_LOCK()
handle->hooks = @hooks_dev_pipe
select case ( handle->mode )
case FB_FILE_MODE_INPUT:
if ( handle->access = FB_FILE_ACCESS_ANY) then
handle->access = FB_FILE_ACCESS_READ
end if
if( handle->access <> FB_FILE_ACCESS_READ ) then
res = fb_ErrorSetNum( FB_RTERROR_ILLEGALFUNCTIONCALL )
end if
openmask = sadd( "r" )
case FB_FILE_MODE_OUTPUT:
if ( handle->access = FB_FILE_ACCESS_ANY) then
handle->access = FB_FILE_ACCESS_WRITE
end if
if( handle->access <> FB_FILE_ACCESS_WRITE ) then
res = fb_ErrorSetNum( FB_RTERROR_ILLEGALFUNCTIONCALL )
end if
openmask = sadd( "w" )
case FB_FILE_MODE_BINARY:
if ( handle->access = FB_FILE_ACCESS_ANY) then
handle->access = FB_FILE_ACCESS_WRITE
end if
openmask = iif(handle->access = FB_FILE_ACCESS_WRITE, sadd( "wb" ), sadd( "rb" ) )
case else:
res = fb_ErrorSetNum( FB_RTERROR_ILLEGALFUNCTIONCALL )
end select
if ( res = FB_RTERROR_OK ) then
/' try to open/create pipe '/
fp = popen( cast( ZString ptr, filename ), openmask )
if( fp = NULL ) then
res = fb_ErrorSetNum( FB_RTERROR_FILENOTFOUND )
end if
handle->opaque = fp
handle->type = FB_FILE_TYPE_PIPE
end if
FB_UNLOCK()
return res
end function
#endif
end extern