FreeBASIC
0.91.0
Main Page
Data Structures
Files
File List
Globals
dev_pipe_open.c
Go to the documentation of this file.
1
/* file device */
2
3
#include "
fb.h
"
4
5
#ifdef HOST_XBOX
6
7
int
fb_DevPipeOpen
(
FB_FILE
*
handle
,
const
char
*
filename
,
size_t
filename_len )
8
{
9
return
fb_ErrorSetNum
(
FB_RTERROR_ILLEGALFUNCTIONCALL
);
10
}
11
12
#else
13
14
static
FB_FILE_HOOKS
hooks_dev_pipe
= {
15
fb_DevFileEof
,
16
fb_DevPipeClose
,
17
NULL
,
18
NULL
,
19
fb_DevFileRead
,
20
fb_DevFileReadWstr
,
21
fb_DevFileWrite
,
22
fb_DevFileWriteWstr
,
23
NULL
,
24
NULL
,
25
fb_DevFileReadLine
,
26
fb_DevFileReadLineWstr
27
};
28
29
int
fb_DevPipeOpen
(
FB_FILE
*
handle
,
const
char
*
filename
,
size_t
filename_len )
30
{
31
int
res =
fb_ErrorSetNum
(
FB_RTERROR_OK
);
32
FILE *fp =
NULL
;
33
char
openmask[16];
34
const
char
*fname;
35
36
FB_LOCK
();
37
38
fname =
filename
;
39
40
handle->
hooks
= &
hooks_dev_pipe
;
41
42
openmask[0] = 0;
43
44
switch
( handle->
mode
)
45
{
46
case
FB_FILE_MODE_INPUT
:
47
if
( handle->
access
==
FB_FILE_ACCESS_ANY
)
48
handle->
access
=
FB_FILE_ACCESS_READ
;
49
50
if
( handle->
access
!=
FB_FILE_ACCESS_READ
)
51
res =
fb_ErrorSetNum
(
FB_RTERROR_ILLEGALFUNCTIONCALL
);
52
53
strcpy( openmask,
"r"
);
54
break
;
55
56
case
FB_FILE_MODE_OUTPUT
:
57
if
( handle->
access
==
FB_FILE_ACCESS_ANY
)
58
handle->
access
=
FB_FILE_ACCESS_WRITE
;
59
60
if
( handle->
access
!=
FB_FILE_ACCESS_WRITE
)
61
res =
fb_ErrorSetNum
(
FB_RTERROR_ILLEGALFUNCTIONCALL
);
62
63
strcpy( openmask,
"w"
);
64
break
;
65
66
case
FB_FILE_MODE_BINARY
:
67
if
( handle->
access
==
FB_FILE_ACCESS_ANY
)
68
handle->
access
=
FB_FILE_ACCESS_WRITE
;
69
70
strcpy( openmask, (handle->
access
==
FB_FILE_ACCESS_WRITE
?
"wb"
:
"rb"
) );
71
72
break
;
73
74
default
:
75
res =
fb_ErrorSetNum
(
FB_RTERROR_ILLEGALFUNCTIONCALL
);
76
}
77
78
if
( res ==
FB_RTERROR_OK
)
79
{
80
/* try to open/create pipe */
81
#ifdef HOST_MINGW
82
if
( (fp = _popen( fname, openmask )) ==
NULL
)
83
#else
84
if
( (fp = popen( fname, openmask )) ==
NULL
)
85
#endif
86
{
87
res =
fb_ErrorSetNum
(
FB_RTERROR_FILENOTFOUND
);
88
}
89
handle->
opaque
= fp;
90
handle->
type
=
FB_FILE_TYPE_PIPE
;
91
}
92
93
FB_UNLOCK
();
94
95
return
res;
96
}
97
98
#endif
rtlib
dev_pipe_open.c
Generated on Thu Jan 23 2014 19:40:08 for FreeBASIC by
1.8.4