FreeBASIC  0.91.0
qb_file_open.c
Go to the documentation of this file.
1 /* QB compatible OPEN */
2 
3 #include "fb.h"
4 
6  (
7  FBSTRING *str,
8  unsigned int mode,
9  unsigned int access,
10  unsigned int lock,
11  int fnum,
12  int len
13  )
14 {
15  if( !FB_FILE_INDEX_VALID( fnum ) )
17 
18  ssize_t str_len = FB_STRSIZE( str );
19 
20  if( !str_len || (str->data == NULL) )
22 
23  /* serial? */
24  if( (str_len > 3) && (strncasecmp( str->data, "COM", 3 ) == 0) )
25  {
26  ssize_t i = 3;
27  while( (i < str_len) && (str->data[i] >= '0') && (str->data[i] <= '9' ) )
28  ++i;
29 
30  if( str->data[i] == ':' )
31  {
32  return fb_FileOpenVfsEx( FB_FILE_TO_HANDLE(fnum),
33  str,
34  mode,
35  access,
36  lock,
37  len,
39  fb_DevComOpen );
40  }
41  }
42  /* parallel? */
43  else if( (str_len > 3) && (strncasecmp( str->data, "LPT", 3 ) == 0) )
44  {
45  ssize_t i = 3;
46  while( (i < str_len) && (str->data[i] >= '0') && (str->data[i] <= '9' ) )
47  ++i;
48 
49  if( str->data[i] == ':' )
50  {
51  return fb_FileOpenVfsEx( FB_FILE_TO_HANDLE(fnum),
52  str,
53  mode,
54  access,
55  lock,
56  len,
58  fb_DevLptOpen );
59  }
60  }
61  /* default printer? */
62  else if( (str_len == 4) && (strcasecmp( str->data, "PRN:" ) == 0) )
63  {
64  return fb_FileOpenVfsEx( FB_FILE_TO_HANDLE(fnum),
65  str,
66  mode,
67  access,
68  lock,
69  len,
71  fb_DevLptOpen );
72  }
73  /* console? */
74  else if( (str_len == 5) && (strcasecmp( str->data, "CONS:" ) == 0) )
75  {
76  return fb_FileOpenVfsEx( FB_FILE_TO_HANDLE(fnum),
77  str,
78  mode,
79  access,
80  lock,
81  len,
84 
85  }
86  /* screen? */
87  else if( (str_len == 5) && (strcasecmp( str->data, "SCRN:" ) == 0) )
88  {
89  fb_DevScrnInit( );
90 
91  return fb_FileOpenVfsEx( FB_FILE_TO_HANDLE(fnum),
92  str,
93  mode,
94  access,
95  lock,
96  len,
99  }
100  /* pipe? */
101  else if( (str_len == 5) && (strcasecmp( str->data, "PIPE:" ) == 0) )
102  {
103  return fb_FileOpenVfsEx( FB_FILE_TO_HANDLE(fnum),
104  str,
105  mode,
106  access,
107  lock,
108  len,
110  fb_DevPipeOpen );
111  }
112 
113  /* ordinary file */
114  return fb_FileOpenEx( FB_FILE_TO_HANDLE(fnum), str, mode, access, lock, len );
115 }