~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/my_open.c

  • Committer: Brian Aker
  • Date: 2008-07-18 20:10:26 UTC
  • mfrom: (51.3.29 remove-dbug)
  • Revision ID: brian@tangent.org-20080718201026-tto5golt0xhwqe4a
Merging in Jay's final patch on dbug.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
                                /* Special flags */
38
38
{
39
39
  File fd;
40
 
  DBUG_ENTER("my_open");
41
 
  DBUG_PRINT("my",("Name: '%s'  Flags: %d  MyFlags: %d",
42
 
                   FileName, Flags, MyFlags));
43
40
 
44
41
#if !defined(NO_OPEN_3)
45
42
  fd = open(FileName, Flags, my_umask); /* Normal unix */
47
44
  fd = open((char *) FileName, Flags);
48
45
#endif
49
46
 
50
 
  DBUG_RETURN(my_register_filename(fd, FileName, FILE_BY_OPEN,
 
47
  return(my_register_filename(fd, FileName, FILE_BY_OPEN,
51
48
                                   EE_FILENOTFOUND, MyFlags));
52
49
} /* my_open */
53
50
 
65
62
int my_close(File fd, myf MyFlags)
66
63
{
67
64
  int err;
68
 
  DBUG_ENTER("my_close");
69
 
  DBUG_PRINT("my",("fd: %d  MyFlags: %d",fd, MyFlags));
70
65
 
71
66
  pthread_mutex_lock(&THR_LOCK_open);
72
67
  do
76
71
 
77
72
  if (err)
78
73
  {
79
 
    DBUG_PRINT("error",("Got error %d on close",err));
80
74
    my_errno=errno;
81
75
    if (MyFlags & (MY_FAE | MY_WME))
82
76
      my_error(EE_BADCLOSE, MYF(ME_BELL+ME_WAITTANG),my_filename(fd),errno);
91
85
  }
92
86
  my_file_opened--;
93
87
  pthread_mutex_unlock(&THR_LOCK_open);
94
 
  DBUG_RETURN(err);
 
88
  return(err);
95
89
} /* my_close */
96
90
 
97
91
 
115
109
File my_register_filename(File fd, const char *FileName, enum file_type
116
110
                          type_of_file, uint error_message_number, myf MyFlags)
117
111
{
118
 
  DBUG_ENTER("my_register_filename");
119
112
  if ((int) fd >= 0)
120
113
  {
121
114
    if ((uint) fd >= my_file_limit)
124
117
      my_errno= EMFILE;
125
118
#else
126
119
      thread_safe_increment(my_file_opened,&THR_LOCK_open);
127
 
      DBUG_RETURN(fd);                          /* safeguard */
 
120
      return(fd);                               /* safeguard */
128
121
#endif
129
122
    }
130
123
    else
139
132
        pthread_mutex_init(&my_file_info[fd].mutex,MY_MUTEX_INIT_FAST);
140
133
#endif
141
134
        pthread_mutex_unlock(&THR_LOCK_open);
142
 
        DBUG_PRINT("exit",("fd: %d",fd));
143
 
        DBUG_RETURN(fd);
 
135
        return(fd);
144
136
      }
145
137
      pthread_mutex_unlock(&THR_LOCK_open);
146
138
      my_errno= ENOMEM;
150
142
  else
151
143
    my_errno= errno;
152
144
 
153
 
  DBUG_PRINT("error",("Got error %d on open", my_errno));
154
145
  if (MyFlags & (MY_FFNF | MY_FAE | MY_WME))
155
146
  {
156
147
    if (my_errno == EMFILE)
157
148
      error_message_number= EE_OUT_OF_FILERESOURCES;
158
 
    DBUG_PRINT("error",("print err: %d",error_message_number));
159
149
    my_error(error_message_number, MYF(ME_BELL+ME_WAITTANG),
160
150
             FileName, my_errno);
161
151
  }
162
 
  DBUG_RETURN(-1);
 
152
  return(-1);
163
153
}
164
154
 
165
155