~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/my_fopen.c

  • Committer: Monty Taylor
  • Date: 2008-10-27 23:19:48 UTC
  • mto: (520.4.12 merge-innodb-plugin)
  • mto: This revision was merged to the branch mainline in revision 563.
  • Revision ID: monty@inaugust.com-20081027231948-3kl6ss04plbakqcr
Split some more things out of common_includes.h.

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 <errno.h>
18
19
#include "mysys_err.h"
19
20
 
20
 
#include <stdio.h>
21
 
#include <stdlib.h>
22
 
#include <errno.h>
23
 
#include <string.h>
24
 
 
25
21
static void make_ftype(char * to,int flag);
26
22
 
27
23
/*
42
38
{
43
39
  FILE *fd;
44
40
  char type[5];
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
 
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 
49
45
  */
50
46
  {
51
47
    make_ftype(type,flags);
52
48
    fd = fopen(filename, type);
53
49
  }
54
 
 
 
50
  
55
51
  if (fd != 0)
56
52
  {
57
53
    /*
66
62
    }
67
63
    pthread_mutex_lock(&THR_LOCK_open);
68
64
    if ((my_file_info[fileno(fd)].name = (char*)
69
 
         strdup(filename)))
 
65
         my_strdup(filename,MyFlags)))
70
66
    {
71
67
      my_stream_opened++;
72
68
      my_file_total_opened++;
116
112
 
117
113
 
118
114
 
119
 
/*
 
115
/*   
120
116
  Make a fopen() typestring from a open() type bitmap
121
117
 
122
118
  SYNOPSIS
125
121
    flag        Flag used by open()
126
122
 
127
123
  IMPLEMENTATION
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
 
 
 
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
  
132
128
  NOTE
133
129
    On Unix, O_RDONLY is usually 0
134
130
 
135
131
  MAPPING
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
 
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  
141
137
    a+ == O_RDWR|O_APPEND|O_CREAT
142
138
*/
143
139
 
144
140
static void make_ftype(register char * to, register int flag)
145
141
{
146
 
  /* check some possible invalid combinations */
 
142
  /* check some possible invalid combinations */  
147
143
  assert((flag & (O_TRUNC | O_APPEND)) != (O_TRUNC | O_APPEND));
148
144
  assert((flag & (O_WRONLY | O_RDWR)) != (O_WRONLY | O_RDWR));
149
145
 
150
 
  if ((flag & (O_RDONLY|O_WRONLY)) == O_WRONLY)
151
 
    *to++= (flag & O_APPEND) ? 'a' : 'w';
152
 
  else if (flag & O_RDWR)
 
146
  if ((flag & (O_RDONLY|O_WRONLY)) == O_WRONLY)    
 
147
    *to++= (flag & O_APPEND) ? 'a' : 'w';  
 
148
  else if (flag & O_RDWR)          
153
149
  {
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
 
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      
160
156
      *to++= 'r';
161
 
    *to++= '+';
162
 
  }
163
 
  else
 
157
    *to++= '+';  
 
158
  }  
 
159
  else    
164
160
    *to++= 'r';
165
161
 
166
162
  *to='\0';