~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/my_lib.c

Put errmsg.c in sql-common since it can be built only once and used twice.
Put client.c and net_serv.c in libmysql so that we can only have one
link_sources section. 
Got rid of just about all copying and other weirdness, other than some stuff
in client and client.c/net_serv.c, which need to be reworked.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
/*       Convert MSDOS-TIME to standar time_t (still needed?) */
18
18
 
19
19
#include        "mysys_priv.h"
20
 
#include        <mystrings/m_string.h>
 
20
#include        <m_string.h>
21
21
#include        <my_dir.h>      /* Structs used by my_dir,includes sys/types */
22
22
#include        "mysys_err.h"
23
23
#if defined(HAVE_DIRENT_H)
37
37
# endif
38
38
#endif
39
39
 
40
 
#if defined(HAVE_READDIR_R)
 
40
#if defined(THREAD) && defined(HAVE_READDIR_R)
41
41
#define READDIR(A,B,C) ((errno=readdir_r(A,B,&C)) != 0 || !C)
42
42
#else
43
43
#define READDIR(A,B,C) (!(C=readdir(A)))
53
53
#define NAMES_START_SIZE   32768
54
54
 
55
55
 
56
 
static int comp_names(const struct fileinfo *a, const struct fileinfo *b);
 
56
static int      comp_names(struct fileinfo *a,struct fileinfo *b);
57
57
 
58
58
 
59
59
        /* We need this because program don't know with malloc we used */
60
60
 
61
61
void my_dirend(MY_DIR *buffer)
62
62
{
 
63
  DBUG_ENTER("my_dirend");
63
64
  if (buffer)
64
65
  {
65
66
    delete_dynamic((DYNAMIC_ARRAY*)((char*)buffer + 
66
67
                                    ALIGN_SIZE(sizeof(MY_DIR))));
67
68
    free_root((MEM_ROOT*)((char*)buffer + ALIGN_SIZE(sizeof(MY_DIR)) + 
68
69
                          ALIGN_SIZE(sizeof(DYNAMIC_ARRAY))), MYF(0));
69
 
    free((unsigned char*) buffer);
 
70
    my_free((uchar*) buffer,MYF(0));
70
71
  }
71
 
  return;
 
72
  DBUG_VOID_RETURN;
72
73
} /* my_dirend */
73
74
 
74
75
 
75
76
        /* Compare in sort of filenames */
76
77
 
77
 
static int comp_names(const struct fileinfo *a, const struct fileinfo *b)
 
78
static int comp_names(struct fileinfo *a, struct fileinfo *b)
78
79
{
79
80
  return (strcmp(a->name,b->name));
80
81
} /* comp_names */
90
91
  DIR           *dirp;
91
92
  struct dirent *dp;
92
93
  char          tmp_path[FN_REFLEN+1],*tmp_file;
 
94
#ifdef THREAD
93
95
  char  dirent_tmp[sizeof(struct dirent)+_POSIX_PATH_MAX+1];
 
96
#endif
 
97
  DBUG_ENTER("my_dir");
 
98
  DBUG_PRINT("my",("path: '%s' MyFlags: %d",path,MyFlags));
94
99
 
95
 
#if !defined(HAVE_READDIR_R)
 
100
#if defined(THREAD) && !defined(HAVE_READDIR_R)
96
101
  pthread_mutex_lock(&THR_LOCK_open);
97
102
#endif
98
103
 
110
115
  if (my_init_dynamic_array(dir_entries_storage, sizeof(FILEINFO),
111
116
                            ENTRIES_START_SIZE, ENTRIES_INCREMENT))
112
117
  {
113
 
    free((unsigned char*) buffer);
 
118
    my_free((uchar*) buffer,MYF(0));
114
119
    goto error;
115
120
  }
116
121
  init_alloc_root(names_storage, NAMES_START_SIZE, NAMES_START_SIZE);
118
123
  /* MY_DIR structure is allocated and completly initialized at this point */
119
124
  result= (MY_DIR*)buffer;
120
125
 
121
 
  tmp_file= strchr(tmp_path, '\0');
 
126
  tmp_file=strend(tmp_path);
122
127
 
 
128
#ifdef THREAD
123
129
  dp= (struct dirent*) dirent_tmp;
 
130
#else
 
131
  dp=0;
 
132
#endif
124
133
  
125
134
  while (!(READDIR(dirp,(struct dirent*) dirent_tmp,dp)))
126
135
  {
133
142
                                               sizeof(struct stat))))
134
143
        goto error;
135
144
      
136
 
      memset(finfo.mystat, 0, sizeof(struct stat));
137
 
      my_stpcpy(tmp_file,dp->d_name);
138
 
      stat(tmp_path, finfo.mystat);
139
 
      if (!(finfo.mystat->st_mode & S_IREAD))
 
145
      bzero(finfo.mystat, sizeof(struct stat));
 
146
      VOID(strmov(tmp_file,dp->d_name));
 
147
      VOID(stat(tmp_path, finfo.mystat));
 
148
      if (!(finfo.mystat->st_mode & MY_S_IREAD))
140
149
        continue;
141
150
    }
142
151
    else
143
152
      finfo.mystat= NULL;
144
153
 
145
 
    if (push_dynamic(dir_entries_storage, (unsigned char*)&finfo))
 
154
    if (push_dynamic(dir_entries_storage, (uchar*)&finfo))
146
155
      goto error;
147
156
  }
148
157
 
149
158
  (void) closedir(dirp);
150
 
#if !defined(HAVE_READDIR_R)
 
159
#if defined(THREAD) && !defined(HAVE_READDIR_R)
151
160
  pthread_mutex_unlock(&THR_LOCK_open);
152
161
#endif
153
162
  result->dir_entry= (FILEINFO *)dir_entries_storage->buffer;
156
165
  if (!(MyFlags & MY_DONT_SORT))
157
166
    my_qsort((void *) result->dir_entry, result->number_off_files,
158
167
          sizeof(FILEINFO), (qsort_cmp) comp_names);
159
 
  return(result);
 
168
  DBUG_RETURN(result);
160
169
 
161
170
 error:
162
 
#if !defined(HAVE_READDIR_R)
 
171
#if defined(THREAD) && !defined(HAVE_READDIR_R)
163
172
  pthread_mutex_unlock(&THR_LOCK_open);
164
173
#endif
165
174
  my_errno=errno;
168
177
  my_dirend(result);
169
178
  if (MyFlags & (MY_FAE | MY_WME))
170
179
    my_error(EE_DIR,MYF(ME_BELL+ME_WAITTANG),path,my_errno);
171
 
  return((MY_DIR *) NULL);
 
180
  DBUG_RETURN((MY_DIR *) NULL);
172
181
} /* my_dir */
173
182
 
174
183
 
190
199
 
191
200
  if (src[0] == 0)
192
201
    src= (char*) ".";                           /* Use empty as current */
193
 
  end=my_stpcpy(dst, src);
 
202
  end=strmov(dst, src);
194
203
  if (end[-1] != FN_LIBCHAR)
195
204
  {
196
205
    end[0]=FN_LIBCHAR;                          /* Add last '/' */