~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/my_lib.cc

enable remaining subselect tests, merge with latest from the trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
#include        "mysys_priv.h"
20
20
#include        <mystrings/m_string.h>
21
 
#include        <my_dir.h>      /* Structs used by my_dir,includes sys/types */
22
21
#include        "mysys_err.h"
 
22
#include        "my_dir.h"      /* Structs used by my_dir,includes sys/types */
23
23
#if defined(HAVE_DIRENT_H)
24
24
# include <dirent.h>
25
 
# define NAMLEN(dirent) strlen((dirent)->d_name)
26
25
#else
27
26
# define dirent direct
28
 
# define NAMLEN(dirent) (dirent)->d_namlen
29
27
# if defined(HAVE_SYS_NDIR_H)
30
28
#  include <sys/ndir.h>
31
29
# endif
44
42
#endif
45
43
 
46
44
/*
47
 
  We are assuming that directory we are reading is either has less than 
 
45
  We are assuming that directory we are reading is either has less than
48
46
  100 files and so can be read in one initial chunk or has more than 1000
49
47
  files and so big increment are suitable.
50
48
*/
62
60
{
63
61
  if (buffer)
64
62
  {
65
 
    delete_dynamic((DYNAMIC_ARRAY*)((char*)buffer + 
 
63
    delete_dynamic((DYNAMIC_ARRAY*)((char*)buffer +
66
64
                                    ALIGN_SIZE(sizeof(MY_DIR))));
67
 
    free_root((MEM_ROOT*)((char*)buffer + ALIGN_SIZE(sizeof(MY_DIR)) + 
 
65
    free_root((MEM_ROOT*)((char*)buffer + ALIGN_SIZE(sizeof(MY_DIR)) +
68
66
                          ALIGN_SIZE(sizeof(DYNAMIC_ARRAY))), MYF(0));
69
 
    my_free((uchar*) buffer,MYF(0));
 
67
    free((unsigned char*) buffer);
70
68
  }
71
69
  return;
72
70
} /* my_dirend */
97
95
#endif
98
96
 
99
97
  dirp = opendir(directory_file_name(tmp_path,(char *) path));
100
 
  if (dirp == NULL || 
101
 
      ! (buffer= my_malloc(ALIGN_SIZE(sizeof(MY_DIR)) + 
102
 
                           ALIGN_SIZE(sizeof(DYNAMIC_ARRAY)) +
103
 
                           sizeof(MEM_ROOT), MyFlags)))
 
98
  if (dirp == NULL ||
 
99
      ! (buffer= (char *) malloc(ALIGN_SIZE(sizeof(MY_DIR)) + 
 
100
                                 ALIGN_SIZE(sizeof(DYNAMIC_ARRAY)) +
 
101
                                 sizeof(MEM_ROOT))))
104
102
    goto error;
105
103
 
106
 
  dir_entries_storage= (DYNAMIC_ARRAY*)(buffer + ALIGN_SIZE(sizeof(MY_DIR))); 
 
104
  dir_entries_storage= (DYNAMIC_ARRAY*)(buffer + ALIGN_SIZE(sizeof(MY_DIR)));
107
105
  names_storage= (MEM_ROOT*)(buffer + ALIGN_SIZE(sizeof(MY_DIR)) +
108
106
                             ALIGN_SIZE(sizeof(DYNAMIC_ARRAY)));
109
 
  
 
107
 
110
108
  if (my_init_dynamic_array(dir_entries_storage, sizeof(FILEINFO),
111
109
                            ENTRIES_START_SIZE, ENTRIES_INCREMENT))
112
110
  {
113
 
    my_free((uchar*) buffer,MYF(0));
 
111
    free((unsigned char*) buffer);
114
112
    goto error;
115
113
  }
116
114
  init_alloc_root(names_storage, NAMES_START_SIZE, NAMES_START_SIZE);
117
 
  
 
115
 
118
116
  /* MY_DIR structure is allocated and completly initialized at this point */
119
117
  result= (MY_DIR*)buffer;
120
118
 
121
 
  tmp_file=strend(tmp_path);
 
119
  tmp_file= strchr(tmp_path, '\0');
122
120
 
123
121
  dp= (struct dirent*) dirent_tmp;
124
 
  
 
122
 
125
123
  while (!(READDIR(dirp,(struct dirent*) dirent_tmp,dp)))
126
124
  {
127
125
    if (!(finfo.name= strdup_root(names_storage, dp->d_name)))
128
126
      goto error;
129
 
    
 
127
 
130
128
    if (MyFlags & MY_WANT_STAT)
131
129
    {
132
 
      if (!(finfo.mystat= (struct stat*)alloc_root(names_storage, 
 
130
      if (!(finfo.mystat= (struct stat*)alloc_root(names_storage,
133
131
                                               sizeof(struct stat))))
134
132
        goto error;
135
 
      
 
133
 
136
134
      memset(finfo.mystat, 0, sizeof(struct stat));
137
 
      VOID(stpcpy(tmp_file,dp->d_name));
138
 
      VOID(stat(tmp_path, finfo.mystat));
 
135
      strcpy(tmp_file,dp->d_name);
 
136
      stat(tmp_path, finfo.mystat);
139
137
      if (!(finfo.mystat->st_mode & S_IREAD))
140
138
        continue;
141
139
    }
142
140
    else
143
141
      finfo.mystat= NULL;
144
142
 
145
 
    if (push_dynamic(dir_entries_storage, (uchar*)&finfo))
 
143
    if (push_dynamic(dir_entries_storage, (unsigned char*)&finfo))
146
144
      goto error;
147
145
  }
148
146
 
152
150
#endif
153
151
  result->dir_entry= (FILEINFO *)dir_entries_storage->buffer;
154
152
  result->number_off_files= dir_entries_storage->elements;
155
 
  
 
153
 
156
154
  if (!(MyFlags & MY_DONT_SORT))
157
155
    my_qsort((void *) result->dir_entry, result->number_off_files,
158
156
          sizeof(FILEINFO), (qsort_cmp) comp_names);
190
188
 
191
189
  if (src[0] == 0)
192
190
    src= (char*) ".";                           /* Use empty as current */
193
 
  end=stpcpy(dst, src);
 
191
  end= strcpy(dst, src)+strlen(src);
194
192
  if (end[-1] != FN_LIBCHAR)
195
193
  {
196
194
    end[0]=FN_LIBCHAR;                          /* Add last '/' */