~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/my_lib.c

Removed dead variable, sorted authors file.

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)
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
*/
51
53
#define NAMES_START_SIZE   32768
52
54
 
53
55
 
54
 
static int comp_names(const struct fileinfo *a, const struct fileinfo *b);
 
56
static int      comp_names(struct fileinfo *a,struct fileinfo *b);
55
57
 
56
58
 
57
59
        /* We need this because program don't know with malloc we used */
58
60
 
59
61
void my_dirend(MY_DIR *buffer)
60
62
{
 
63
  DBUG_ENTER("my_dirend");
61
64
  if (buffer)
62
65
  {
63
 
    delete_dynamic((DYNAMIC_ARRAY*)((char*)buffer +
 
66
    delete_dynamic((DYNAMIC_ARRAY*)((char*)buffer + 
64
67
                                    ALIGN_SIZE(sizeof(MY_DIR))));
65
 
    free_root((MEM_ROOT*)((char*)buffer + ALIGN_SIZE(sizeof(MY_DIR)) +
 
68
    free_root((MEM_ROOT*)((char*)buffer + ALIGN_SIZE(sizeof(MY_DIR)) + 
66
69
                          ALIGN_SIZE(sizeof(DYNAMIC_ARRAY))), MYF(0));
67
 
    free((unsigned char*) buffer);
 
70
    my_free((uchar*) buffer,MYF(0));
68
71
  }
69
 
  return;
 
72
  DBUG_VOID_RETURN;
70
73
} /* my_dirend */
71
74
 
72
75
 
73
76
        /* Compare in sort of filenames */
74
77
 
75
 
static int comp_names(const struct fileinfo *a, const struct fileinfo *b)
 
78
static int comp_names(struct fileinfo *a, struct fileinfo *b)
76
79
{
77
80
  return (strcmp(a->name,b->name));
78
81
} /* comp_names */
89
92
  struct dirent *dp;
90
93
  char          tmp_path[FN_REFLEN+1],*tmp_file;
91
94
  char  dirent_tmp[sizeof(struct dirent)+_POSIX_PATH_MAX+1];
 
95
  DBUG_ENTER("my_dir");
 
96
  DBUG_PRINT("my",("path: '%s' MyFlags: %d",path,MyFlags));
92
97
 
93
98
#if !defined(HAVE_READDIR_R)
94
99
  pthread_mutex_lock(&THR_LOCK_open);
95
100
#endif
96
101
 
97
102
  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))))
 
103
  if (dirp == NULL || 
 
104
      ! (buffer= my_malloc(ALIGN_SIZE(sizeof(MY_DIR)) + 
 
105
                           ALIGN_SIZE(sizeof(DYNAMIC_ARRAY)) +
 
106
                           sizeof(MEM_ROOT), MyFlags)))
102
107
    goto error;
103
108
 
104
 
  dir_entries_storage= (DYNAMIC_ARRAY*)(buffer + ALIGN_SIZE(sizeof(MY_DIR)));
 
109
  dir_entries_storage= (DYNAMIC_ARRAY*)(buffer + ALIGN_SIZE(sizeof(MY_DIR))); 
105
110
  names_storage= (MEM_ROOT*)(buffer + ALIGN_SIZE(sizeof(MY_DIR)) +
106
111
                             ALIGN_SIZE(sizeof(DYNAMIC_ARRAY)));
107
 
 
 
112
  
108
113
  if (my_init_dynamic_array(dir_entries_storage, sizeof(FILEINFO),
109
114
                            ENTRIES_START_SIZE, ENTRIES_INCREMENT))
110
115
  {
111
 
    free((unsigned char*) buffer);
 
116
    my_free((uchar*) buffer,MYF(0));
112
117
    goto error;
113
118
  }
114
119
  init_alloc_root(names_storage, NAMES_START_SIZE, NAMES_START_SIZE);
115
 
 
 
120
  
116
121
  /* MY_DIR structure is allocated and completly initialized at this point */
117
122
  result= (MY_DIR*)buffer;
118
123
 
119
 
  tmp_file= strchr(tmp_path, '\0');
 
124
  tmp_file=strend(tmp_path);
120
125
 
121
126
  dp= (struct dirent*) dirent_tmp;
122
 
 
 
127
  
123
128
  while (!(READDIR(dirp,(struct dirent*) dirent_tmp,dp)))
124
129
  {
125
130
    if (!(finfo.name= strdup_root(names_storage, dp->d_name)))
126
131
      goto error;
127
 
 
 
132
    
128
133
    if (MyFlags & MY_WANT_STAT)
129
134
    {
130
 
      if (!(finfo.mystat= (struct stat*)alloc_root(names_storage,
 
135
      if (!(finfo.mystat= (struct stat*)alloc_root(names_storage, 
131
136
                                               sizeof(struct stat))))
132
137
        goto error;
133
 
 
134
 
      memset(finfo.mystat, 0, sizeof(struct stat));
135
 
      strcpy(tmp_file,dp->d_name);
136
 
      stat(tmp_path, finfo.mystat);
137
 
      if (!(finfo.mystat->st_mode & S_IREAD))
 
138
      
 
139
      bzero(finfo.mystat, sizeof(struct stat));
 
140
      VOID(strmov(tmp_file,dp->d_name));
 
141
      VOID(stat(tmp_path, finfo.mystat));
 
142
      if (!(finfo.mystat->st_mode & MY_S_IREAD))
138
143
        continue;
139
144
    }
140
145
    else
141
146
      finfo.mystat= NULL;
142
147
 
143
 
    if (push_dynamic(dir_entries_storage, (unsigned char*)&finfo))
 
148
    if (push_dynamic(dir_entries_storage, (uchar*)&finfo))
144
149
      goto error;
145
150
  }
146
151
 
150
155
#endif
151
156
  result->dir_entry= (FILEINFO *)dir_entries_storage->buffer;
152
157
  result->number_off_files= dir_entries_storage->elements;
153
 
 
 
158
  
154
159
  if (!(MyFlags & MY_DONT_SORT))
155
160
    my_qsort((void *) result->dir_entry, result->number_off_files,
156
161
          sizeof(FILEINFO), (qsort_cmp) comp_names);
157
 
  return(result);
 
162
  DBUG_RETURN(result);
158
163
 
159
164
 error:
160
165
#if !defined(HAVE_READDIR_R)
166
171
  my_dirend(result);
167
172
  if (MyFlags & (MY_FAE | MY_WME))
168
173
    my_error(EE_DIR,MYF(ME_BELL+ME_WAITTANG),path,my_errno);
169
 
  return((MY_DIR *) NULL);
 
174
  DBUG_RETURN((MY_DIR *) NULL);
170
175
} /* my_dir */
171
176
 
172
177
 
188
193
 
189
194
  if (src[0] == 0)
190
195
    src= (char*) ".";                           /* Use empty as current */
191
 
  end= strcpy(dst, src)+strlen(src);
 
196
  end=strmov(dst, src);
192
197
  if (end[-1] != FN_LIBCHAR)
193
198
  {
194
199
    end[0]=FN_LIBCHAR;                          /* Add last '/' */