~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/my_fopen.cc

  • Committer: Brian Aker
  • Date: 2009-05-23 17:13:03 UTC
  • mfrom: (1034.1.8 merge)
  • Revision ID: brian@gaz-20090523171303-d28xhutqic0xe2b4
Merge Brian

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
    fd = fopen(filename, type);
53
53
  }
54
54
 
55
 
  if (fd != 0)
 
55
  if (fd != NULL)
56
56
  {
57
 
    /*
58
 
      The test works if MY_NFILE < 128. The problem is that fileno() is char
59
 
      on some OS (SUNOS). Actually the filename save isn't that important
60
 
      so we can ignore if this doesn't work.
61
 
    */
62
 
    if ((uint32_t) fileno(fd) >= my_file_limit)
63
 
    {
64
 
      thread_safe_increment(my_stream_opened,&THR_LOCK_open);
65
 
      return(fd);                               /* safeguard */
66
 
    }
67
 
    pthread_mutex_lock(&THR_LOCK_open);
68
 
    if ((my_file_info[fileno(fd)].name = (char*)
69
 
         strdup(filename)))
70
 
    {
71
 
      my_stream_opened++;
72
 
      my_file_total_opened++;
73
 
      my_file_info[fileno(fd)].type = STREAM_BY_FOPEN;
74
 
      pthread_mutex_unlock(&THR_LOCK_open);
75
 
      return(fd);
76
 
    }
77
 
    pthread_mutex_unlock(&THR_LOCK_open);
78
 
    (void) my_fclose(fd,MyFlags);
79
 
    my_errno=ENOMEM;
 
57
    my_stream_opened++;
 
58
    return fd;                          /* safeguard */
80
59
  }
81
60
  else
82
61
    my_errno=errno;
84
63
    my_error((flags & O_RDONLY) || (flags == O_RDONLY ) ? EE_FILENOTFOUND :
85
64
             EE_CANTCREATEFILE,
86
65
             MYF(ME_BELL+ME_WAITTANG), filename, my_errno);
87
 
  return((FILE*) 0);
 
66
  return NULL;
88
67
} /* my_fopen */
89
68
 
90
69
 
94
73
{
95
74
  int err,file;
96
75
 
97
 
  pthread_mutex_lock(&THR_LOCK_open);
98
 
  file=fileno(fd);
 
76
  file= fileno(fd);
99
77
  if ((err = fclose(fd)) < 0)
100
78
  {
101
79
    my_errno=errno;
105
83
  }
106
84
  else
107
85
    my_stream_opened--;
108
 
  if ((uint32_t) file < my_file_limit && my_file_info[file].type != UNOPEN)
109
 
  {
110
 
    my_file_info[file].type = UNOPEN;
111
 
    free(my_file_info[file].name);
112
 
  }
113
 
  pthread_mutex_unlock(&THR_LOCK_open);
 
86
 
114
87
  return(err);
115
88
} /* my_fclose */
116
89