FreeBASIC  0.91.0
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 {
10 }
11 
12 #else
13 
17  NULL,
18  NULL,
23  NULL,
24  NULL,
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 )
52 
53  strcpy( openmask, "r" );
54  break;
55 
57  if ( handle->access == FB_FILE_ACCESS_ANY)
58  handle->access = FB_FILE_ACCESS_WRITE;
59 
60  if( handle->access != FB_FILE_ACCESS_WRITE )
62 
63  strcpy( openmask, "w" );
64  break;
65 
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:
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  {
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