~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/mf_pack.c

  • Committer: Monty Taylor
  • Date: 2008-07-22 05:48:51 UTC
  • mto: (202.1.3 toru)
  • mto: This revision was merged to the branch mainline in revision 204.
  • Revision ID: monty@inaugust.com-20080722054851-airxt73370725p7x
Re-enabled optimizations for the normal build, and added back the --with-debug option to turn them off. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
#include "mysys_priv.h"
17
 
#include <mystrings/m_string.h>
 
17
#include <m_string.h>
18
18
#include "my_static.h"
19
19
#ifdef HAVE_PWD_H
20
20
#include <pwd.h>
52
52
    buff_length= strlen(buff);
53
53
    d_length= (size_t) (start-to);
54
54
    if ((start == to ||
55
 
         (buff_length == d_length && !memcmp(buff,start,d_length))) &&
 
55
         (buff_length == d_length && !bcmp(buff,start,d_length))) &&
56
56
        *start != FN_LIBCHAR && *start)
57
57
    {                                           /* Put current dir before */
58
 
      bchange((unsigned char*) to, d_length, (unsigned char*) buff, buff_length, strlen(to)+1);
 
58
      bchange((uchar*) to, d_length, (uchar*) buff, buff_length, strlen(to)+1);
59
59
    }
60
60
  }
61
61
 
70
70
    }
71
71
    if (length > 1 && length < d_length)
72
72
    {                                           /* test if /xx/yy -> ~/yy */
73
 
      if (memcmp(to,home_dir,length) == 0 && to[length] == FN_LIBCHAR)
 
73
      if (bcmp(to,home_dir,length) == 0 && to[length] == FN_LIBCHAR)
74
74
      {
75
75
        to[0]=FN_HOMELIB;                       /* Filename begins with ~ */
76
76
        (void) strmov_overlapp(to+1,to+length);
80
80
    {                                           /* Test if cwd is ~/... */
81
81
      if (length > 1 && length < buff_length)
82
82
      {
83
 
        if (memcmp(buff,home_dir,length) == 0 && buff[length] == FN_LIBCHAR)
 
83
        if (bcmp(buff,home_dir,length) == 0 && buff[length] == FN_LIBCHAR)
84
84
        {
85
85
          buff[0]=FN_HOMELIB;
86
86
          (void) strmov_overlapp(buff+1,buff+length);
128
128
{
129
129
  register size_t length;
130
130
  register char * pos;
131
 
  register const char * from_ptr;
 
131
  register char * from_ptr;
132
132
  register char * start;
133
133
  char parent[5],                               /* for "FN_PARENTDIR" */
134
134
       buff[FN_REFLEN+1],*end_parentdir;
137
137
#endif
138
138
 
139
139
  start=buff;
140
 
  from_ptr= from;
 
140
  from_ptr=(char *) from;
141
141
#ifdef FN_DEVCHAR
142
142
  if ((pos=strrchr(from_ptr,FN_DEVCHAR)) != 0)
143
143
  {                                             /* Skip device part */
144
144
    length=(size_t) (pos-from_ptr)+1;
145
 
    start=my_stpncpy(buff,from_ptr,length); from_ptr+=length;
 
145
    start=strnmov(buff,from_ptr,length); from_ptr+=length;
146
146
  }
147
147
#endif
148
148
 
149
149
  parent[0]=FN_LIBCHAR;
150
 
  length=(size_t) (my_stpcpy(parent+1,FN_PARENTDIR)-parent);
 
150
  length=(size_t) (strmov(parent+1,FN_PARENTDIR)-parent);
151
151
  for (pos=start ; (*pos= *from_ptr++) != 0 ; pos++)
152
152
  {
153
153
#ifdef BACKSLASH_MBTAIL
154
 
    uint32_t l;
 
154
    uint l;
155
155
    if (use_mb(fs) && (l= my_ismbchar(fs, from_ptr - 1, from_ptr + 2)))
156
156
    {
157
157
      for (l-- ; l ; *++pos= *from_ptr++, l--);
163
163
      *pos = FN_LIBCHAR;
164
164
    if (*pos == FN_LIBCHAR)
165
165
    {
166
 
      if ((size_t) (pos-start) > length &&
167
 
          memcmp(pos-length,parent,length) == 0)
 
166
      if ((size_t) (pos-start) > length && bcmp(pos-length,parent,length) == 0)
168
167
      {                                         /* If .../../; skip prev */
169
168
        pos-=length;
170
169
        if (pos != start)
177
176
              pos+=length+1;                    /* Don't unpack ~/.. */
178
177
              continue;
179
178
            }
180
 
            pos=my_stpcpy(buff,home_dir)-1;     /* Unpacks ~/.. */
 
179
            pos=strmov(buff,home_dir)-1;        /* Unpacks ~/.. */
181
180
            if (*pos == FN_LIBCHAR)
182
181
              pos--;                            /* home ended with '/' */
183
182
          }
188
187
              pos+=length+1;                    /* Don't unpack ./.. */
189
188
              continue;
190
189
            }
191
 
            pos=my_stpcpy(buff,curr_dir)-1;     /* Unpacks ./.. */
 
190
            pos=strmov(buff,curr_dir)-1;        /* Unpacks ./.. */
192
191
            if (*pos == FN_LIBCHAR)
193
192
              pos--;                            /* home ended with '/' */
194
193
          }
195
194
          end_parentdir=pos;
196
195
          while (pos >= start && *pos != FN_LIBCHAR)    /* remove prev dir */
197
196
            pos--;
198
 
          if (pos[1] == FN_HOMELIB || memcmp(pos,parent,length) == 0)
 
197
          if (pos[1] == FN_HOMELIB || bcmp(pos,parent,length) == 0)
199
198
          {                                     /* Don't remove ~user/ */
200
 
            pos=my_stpcpy(end_parentdir+1,parent);
 
199
            pos=strmov(end_parentdir+1,parent);
201
200
            *pos=FN_LIBCHAR;
202
201
            continue;
203
202
          }
204
203
        }
205
204
      }
206
205
      else if ((size_t) (pos-start) == length-1 &&
207
 
               !memcmp(start,parent+1,length-1))
 
206
               !bcmp(start,parent+1,length-1))
208
207
        start=pos;                              /* Starts with "../" */
209
208
      else if (pos-start > 0 && pos[-1] == FN_LIBCHAR)
210
209
      {
223
222
      }
224
223
    }
225
224
  }
226
 
  (void) my_stpcpy(to,buff);
 
225
  (void) strmov(to,buff);
227
226
  return((size_t) (pos-buff));
228
227
} /* cleanup_dirname */
229
228
 
243
242
void symdirget(char *dir)
244
243
{
245
244
  char buff[FN_REFLEN];
246
 
  char *pos= strchr(dir, '\0');
 
245
  char *pos=strend(dir);
247
246
  if (dir[0] && pos[-1] != FN_DEVCHAR && my_access(dir, F_OK))
248
247
  {
249
248
    File file;
250
249
    size_t length;
251
250
    char temp= *(--pos);            /* May be "/" or "\" */
252
 
    my_stpcpy(pos,".sym");
 
251
    strmov(pos,".sym");
253
252
    file= my_open(dir, O_RDONLY, MYF(0));
254
253
    *pos++=temp; *pos=0;          /* Restore old filename */
255
254
    if (file >= 0)
321
320
        if (tilde_expansion[h_length-1] == FN_LIBCHAR)
322
321
          h_length--;
323
322
        if (buff+h_length < suffix)
324
 
          memcpy(buff+h_length, suffix, length);
 
323
          bmove(buff+h_length,suffix,length);
325
324
        else
326
 
          bmove_upp((unsigned char*) buff+h_length+length, (unsigned char*) suffix+length, length);
327
 
        memcpy(buff, tilde_expansion, h_length);
 
325
          bmove_upp((uchar*) buff+h_length+length, (uchar*) suffix+length, length);
 
326
        bmove(buff,tilde_expansion,h_length);
328
327
      }
329
328
    }
330
329
  }
349
348
    struct passwd *user_entry;
350
349
 
351
350
    if (!(str=strchr(*path,FN_LIBCHAR)))
352
 
      str= strchr(*path, '\0');
 
351
      str=strend(*path);
353
352
    save= *str; *str= '\0';
354
353
    user_entry=getpwnam(*path);
355
354
    *str=save;
361
360
    }
362
361
  }
363
362
#endif
364
 
  return NULL;
 
363
  return (char *) 0;
365
364
}
366
365
 
367
366
 
391
390
  n_length=unpack_dirname(buff,buff);
392
391
  if (n_length+strlen(from+length) < FN_REFLEN)
393
392
  {
394
 
    (void) my_stpcpy(buff+n_length,from+length);
 
393
    (void) strmov(buff+n_length,from+length);
395
394
    length= system_filename(to,buff);           /* Fix to usably filename */
396
395
  }
397
396
  else
423
422
  char buff[FN_REFLEN];
424
423
 
425
424
  libchar_found=0;
426
 
  (void) my_stpcpy(buff,from);                   /* If to == from */
 
425
  (void) strmov(buff,from);                      /* If to == from */
427
426
  from_pos= buff;
428
427
  if ((pos=strrchr(from_pos,FN_DEVCHAR)))       /* Skip device part */
429
428
  {
430
429
    pos++;
431
 
    to_pos=my_stpncpy(to,from_pos,(size_t) (pos-from_pos));
 
430
    to_pos=strnmov(to,from_pos,(size_t) (pos-from_pos));
432
431
    from_pos=pos;
433
432
  }
434
433
  else
444
443
      from_pos+=strlen(FN_ROOTDIR);             /* Actually +1 but... */
445
444
      if (! strchr(from_pos,FN_LIBCHAR))
446
445
      {                                         /* No dir, use [000000] */
447
 
        to_pos=my_stpcpy(to_pos,FN_C_ROOT_DIR);
 
446
        to_pos=strmov(to_pos,FN_C_ROOT_DIR);
448
447
        libchar_found++;
449
448
      }
450
449
    }
457
456
        *(to_pos++)=FN_C_DIR_SEP;               /* Add '.' between dirs */
458
457
      if (strstr(from_pos,FN_PARENTDIR) == from_pos &&
459
458
          from_pos+strlen(FN_PARENTDIR) == pos)
460
 
        to_pos=my_stpcpy(to_pos,FN_C_PARENT_DIR);       /* Found '../' */
 
459
        to_pos=strmov(to_pos,FN_C_PARENT_DIR);  /* Found '../' */
461
460
      else
462
 
        to_pos=my_stpncpy(to_pos,from_pos,(size_t) (pos-from_pos));
 
461
        to_pos=strnmov(to_pos,from_pos,(size_t) (pos-from_pos));
463
462
      from_pos=pos+1;
464
463
    }
465
464
    *(to_pos++)=FN_C_AFTER_DIR;
466
465
  }
467
 
  length= (size_t) (my_stpcpy(to_pos,from_pos)-to);
 
466
  length= (size_t) (strmov(to_pos,from_pos)-to);
468
467
  return(length);
469
468
#endif
470
469
} /* system_filename */
478
477
  char buff[FN_REFLEN];
479
478
  if (from == to)
480
479
  {                                             /* Dirname may destroy from */
481
 
    my_stpcpy(buff,from);
 
480
    strmov(buff,from);
482
481
    from=buff;
483
482
  }
484
483
  length= dirname_part(to, from, &to_length);   /* Copy dirname & fix chars */
485
 
  (void) my_stpcpy(to + to_length,from+length);
 
484
  (void) strmov(to + to_length,from+length);
486
485
  return (to);
487
486
} /* intern_filename */