~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/my_fopen.cc

enable remaining subselect tests, merge with latest from the trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
#include "mysys_priv.h"
17
17
#include "my_static.h"
 
18
#include "mysys_err.h"
 
19
 
 
20
#include <stdio.h>
 
21
#include <stdlib.h>
18
22
#include <errno.h>
19
 
#include "mysys_err.h"
 
23
#include <string.h>
20
24
 
21
25
static void make_ftype(char * to,int flag);
22
26
 
38
42
{
39
43
  FILE *fd;
40
44
  char type[5];
41
 
  /* 
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" 
44
 
    very  well 
 
45
  /*
 
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"
 
48
    very  well
45
49
  */
46
50
  {
47
51
    make_ftype(type,flags);
48
52
    fd = fopen(filename, type);
49
53
  }
50
 
  
 
54
 
51
55
  if (fd != 0)
52
56
  {
53
57
    /*
62
66
    }
63
67
    pthread_mutex_lock(&THR_LOCK_open);
64
68
    if ((my_file_info[fileno(fd)].name = (char*)
65
 
         my_strdup(filename,MyFlags)))
 
69
         strdup(filename)))
66
70
    {
67
71
      my_stream_opened++;
68
72
      my_file_total_opened++;
104
108
  if ((uint) file < my_file_limit && my_file_info[file].type != UNOPEN)
105
109
  {
106
110
    my_file_info[file].type = UNOPEN;
107
 
    my_free(my_file_info[file].name, MYF(MY_ALLOW_ZERO_PTR));
 
111
    free(my_file_info[file].name);
108
112
  }
109
113
  pthread_mutex_unlock(&THR_LOCK_open);
110
114
  return(err);
112
116
 
113
117
 
114
118
 
115
 
/*   
 
119
/*
116
120
  Make a fopen() typestring from a open() type bitmap
117
121
 
118
122
  SYNOPSIS
121
125
    flag        Flag used by open()
122
126
 
123
127
  IMPLEMENTATION
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.  
127
 
  
 
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.
 
131
 
128
132
  NOTE
129
133
    On Unix, O_RDONLY is usually 0
130
134
 
131
135
  MAPPING
132
 
    r  == O_RDONLY   
133
 
    w  == O_WRONLY|O_TRUNC|O_CREAT  
134
 
    a  == O_WRONLY|O_APPEND|O_CREAT  
135
 
    r+ == O_RDWR  
136
 
    w+ == O_RDWR|O_TRUNC|O_CREAT  
 
136
    r  == O_RDONLY
 
137
    w  == O_WRONLY|O_TRUNC|O_CREAT
 
138
    a  == O_WRONLY|O_APPEND|O_CREAT
 
139
    r+ == O_RDWR
 
140
    w+ == O_RDWR|O_TRUNC|O_CREAT
137
141
    a+ == O_RDWR|O_APPEND|O_CREAT
138
142
*/
139
143
 
140
144
static void make_ftype(register char * to, register int flag)
141
145
{
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));
145
149
 
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)
149
153
  {
150
 
    /* Add '+' after theese */    
151
 
    if (flag & (O_TRUNC | O_CREAT))      
152
 
      *to++= 'w';    
153
 
    else if (flag & O_APPEND)      
154
 
      *to++= 'a';    
155
 
    else      
 
154
    /* Add '+' after theese */
 
155
    if (flag & (O_TRUNC | O_CREAT))
 
156
      *to++= 'w';
 
157
    else if (flag & O_APPEND)
 
158
      *to++= 'a';
 
159
    else
156
160
      *to++= 'r';
157
 
    *to++= '+';  
158
 
  }  
159
 
  else    
 
161
    *to++= '+';
 
162
  }
 
163
  else
160
164
    *to++= 'r';
161
165
 
162
 
#if FILE_BINARY            /* If we have binary-files */  
163
 
  if (flag & FILE_BINARY)    
164
 
    *to++='b';
165
 
#endif  
166
166
  *to='\0';
167
167
} /* make_ftype */