~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/my_lib.c

  • Committer: Monty Taylor
  • Date: 2008-10-16 06:32:30 UTC
  • mto: (511.1.5 codestyle)
  • mto: This revision was merged to the branch mainline in revision 521.
  • Revision ID: monty@inaugust.com-20081016063230-4brxsra0qsmsg84q
Added -Wunused-macros.

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        <m_string.h>
 
20
#include        <mystrings/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)
53
53
#define NAMES_START_SIZE   32768
54
54
 
55
55
 
56
 
static int      comp_names(struct fileinfo *a,struct fileinfo *b);
 
56
static int comp_names(const struct fileinfo *a, const 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");
64
63
  if (buffer)
65
64
  {
66
65
    delete_dynamic((DYNAMIC_ARRAY*)((char*)buffer + 
67
66
                                    ALIGN_SIZE(sizeof(MY_DIR))));
68
67
    free_root((MEM_ROOT*)((char*)buffer + ALIGN_SIZE(sizeof(MY_DIR)) + 
69
68
                          ALIGN_SIZE(sizeof(DYNAMIC_ARRAY))), MYF(0));
70
 
    my_free((uchar*) buffer,MYF(0));
 
69
    free((unsigned char*) buffer);
71
70
  }
72
 
  DBUG_VOID_RETURN;
 
71
  return;
73
72
} /* my_dirend */
74
73
 
75
74
 
76
75
        /* Compare in sort of filenames */
77
76
 
78
 
static int comp_names(struct fileinfo *a, struct fileinfo *b)
 
77
static int comp_names(const struct fileinfo *a, const struct fileinfo *b)
79
78
{
80
79
  return (strcmp(a->name,b->name));
81
80
} /* comp_names */
92
91
  struct dirent *dp;
93
92
  char          tmp_path[FN_REFLEN+1],*tmp_file;
94
93
  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));
97
94
 
98
95
#if !defined(HAVE_READDIR_R)
99
96
  pthread_mutex_lock(&THR_LOCK_open);
113
110
  if (my_init_dynamic_array(dir_entries_storage, sizeof(FILEINFO),
114
111
                            ENTRIES_START_SIZE, ENTRIES_INCREMENT))
115
112
  {
116
 
    my_free((uchar*) buffer,MYF(0));
 
113
    free((unsigned char*) buffer);
117
114
    goto error;
118
115
  }
119
116
  init_alloc_root(names_storage, NAMES_START_SIZE, NAMES_START_SIZE);
121
118
  /* MY_DIR structure is allocated and completly initialized at this point */
122
119
  result= (MY_DIR*)buffer;
123
120
 
124
 
  tmp_file=strend(tmp_path);
 
121
  tmp_file= strchr(tmp_path, '\0');
125
122
 
126
123
  dp= (struct dirent*) dirent_tmp;
127
124
  
136
133
                                               sizeof(struct stat))))
137
134
        goto error;
138
135
      
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))
 
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))
143
140
        continue;
144
141
    }
145
142
    else
146
143
      finfo.mystat= NULL;
147
144
 
148
 
    if (push_dynamic(dir_entries_storage, (uchar*)&finfo))
 
145
    if (push_dynamic(dir_entries_storage, (unsigned char*)&finfo))
149
146
      goto error;
150
147
  }
151
148
 
159
156
  if (!(MyFlags & MY_DONT_SORT))
160
157
    my_qsort((void *) result->dir_entry, result->number_off_files,
161
158
          sizeof(FILEINFO), (qsort_cmp) comp_names);
162
 
  DBUG_RETURN(result);
 
159
  return(result);
163
160
 
164
161
 error:
165
162
#if !defined(HAVE_READDIR_R)
171
168
  my_dirend(result);
172
169
  if (MyFlags & (MY_FAE | MY_WME))
173
170
    my_error(EE_DIR,MYF(ME_BELL+ME_WAITTANG),path,my_errno);
174
 
  DBUG_RETURN((MY_DIR *) NULL);
 
171
  return((MY_DIR *) NULL);
175
172
} /* my_dir */
176
173
 
177
174
 
193
190
 
194
191
  if (src[0] == 0)
195
192
    src= (char*) ".";                           /* Use empty as current */
196
 
  end=strmov(dst, src);
 
193
  end=my_stpcpy(dst, src);
197
194
  if (end[-1] != FN_LIBCHAR)
198
195
  {
199
196
    end[0]=FN_LIBCHAR;                          /* Add last '/' */