~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/my_lib.c

  • Committer: Brian Aker
  • Date: 2008-10-06 06:47:29 UTC
  • Revision ID: brian@tangent.org-20081006064729-2i9mhjkzyvow9xsm
RemoveĀ uint.

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