42
if we are not creating, then we need to use my_access to make sure
43
the file exists since Windows doesn't handle files like "com1.sym"
46
if we are not creating, then we need to use my_access to make sure
47
the file exists since Windows doesn't handle files like "com1.sym"
47
51
make_ftype(type,flags);
48
52
fd = fopen(filename, type);
55
59
on some OS (SUNOS). Actually the filename save isn't that important
56
60
so we can ignore if this doesn't work.
58
if ((uint) fileno(fd) >= my_file_limit)
62
if ((uint32_t) fileno(fd) >= my_file_limit)
60
64
thread_safe_increment(my_stream_opened,&THR_LOCK_open);
61
65
return(fd); /* safeguard */
63
67
pthread_mutex_lock(&THR_LOCK_open);
64
68
if ((my_file_info[fileno(fd)].name = (char*)
65
my_strdup(filename,MyFlags)))
67
71
my_stream_opened++;
68
72
my_file_total_opened++;
103
107
my_stream_opened--;
104
if ((uint) file < my_file_limit && my_file_info[file].type != UNOPEN)
108
if ((uint32_t) file < my_file_limit && my_file_info[file].type != UNOPEN)
106
110
my_file_info[file].type = UNOPEN;
107
111
free(my_file_info[file].name);
121
125
flag Flag used by open()
124
This routine attempts to find the best possible match
125
between a numeric option and a string option that could be
126
fed to fopen. There is not a 1 to 1 mapping between the two.
128
This routine attempts to find the best possible match
129
between a numeric option and a string option that could be
130
fed to fopen. There is not a 1 to 1 mapping between the two.
129
133
On Unix, O_RDONLY is usually 0
133
w == O_WRONLY|O_TRUNC|O_CREAT
134
a == O_WRONLY|O_APPEND|O_CREAT
136
w+ == O_RDWR|O_TRUNC|O_CREAT
137
w == O_WRONLY|O_TRUNC|O_CREAT
138
a == O_WRONLY|O_APPEND|O_CREAT
140
w+ == O_RDWR|O_TRUNC|O_CREAT
137
141
a+ == O_RDWR|O_APPEND|O_CREAT
140
144
static void make_ftype(register char * to, register int flag)
142
/* check some possible invalid combinations */
146
/* check some possible invalid combinations */
143
147
assert((flag & (O_TRUNC | O_APPEND)) != (O_TRUNC | O_APPEND));
144
148
assert((flag & (O_WRONLY | O_RDWR)) != (O_WRONLY | O_RDWR));
146
if ((flag & (O_RDONLY|O_WRONLY)) == O_WRONLY)
147
*to++= (flag & O_APPEND) ? 'a' : 'w';
148
else if (flag & O_RDWR)
150
if ((flag & (O_RDONLY|O_WRONLY)) == O_WRONLY)
151
*to++= (flag & O_APPEND) ? 'a' : 'w';
152
else if (flag & O_RDWR)
150
/* Add '+' after theese */
151
if (flag & (O_TRUNC | O_CREAT))
153
else if (flag & O_APPEND)
154
/* Add '+' after theese */
155
if (flag & (O_TRUNC | O_CREAT))
157
else if (flag & O_APPEND)
162
#if FILE_BINARY /* If we have binary-files */
163
if (flag & FILE_BINARY)
167
167
} /* make_ftype */