~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/mf_pack.c

  • Committer: Brian Aker
  • Date: 2008-07-07 14:25:25 UTC
  • mto: (77.1.25 codestyle)
  • mto: This revision was merged to the branch mainline in revision 82.
  • Revision ID: brian@tangent.org-20080707142525-xzy2nl3ie2ebwfln
LL() cleanup

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>
37
37
  size_t d_length,length,buff_length= 0;
38
38
  char * start;
39
39
  char buff[FN_REFLEN];
 
40
  DBUG_ENTER("pack_dirname");
40
41
 
41
42
  (void) intern_filename(to,from);              /* Change to intern name */
42
43
 
52
53
    buff_length= strlen(buff);
53
54
    d_length= (size_t) (start-to);
54
55
    if ((start == to ||
55
 
         (buff_length == d_length && !memcmp(buff,start,d_length))) &&
 
56
         (buff_length == d_length && !bcmp(buff,start,d_length))) &&
56
57
        *start != FN_LIBCHAR && *start)
57
58
    {                                           /* Put current dir before */
58
 
      bchange((unsigned char*) to, d_length, (unsigned char*) buff, buff_length, strlen(to)+1);
 
59
      bchange((uchar*) to, d_length, (uchar*) buff, buff_length, strlen(to)+1);
59
60
    }
60
61
  }
61
62
 
70
71
    }
71
72
    if (length > 1 && length < d_length)
72
73
    {                                           /* test if /xx/yy -> ~/yy */
73
 
      if (memcmp(to,home_dir,length) == 0 && to[length] == FN_LIBCHAR)
 
74
      if (bcmp(to,home_dir,length) == 0 && to[length] == FN_LIBCHAR)
74
75
      {
75
76
        to[0]=FN_HOMELIB;                       /* Filename begins with ~ */
76
77
        (void) strmov_overlapp(to+1,to+length);
80
81
    {                                           /* Test if cwd is ~/... */
81
82
      if (length > 1 && length < buff_length)
82
83
      {
83
 
        if (memcmp(buff,home_dir,length) == 0 && buff[length] == FN_LIBCHAR)
 
84
        if (bcmp(buff,home_dir,length) == 0 && buff[length] == FN_LIBCHAR)
84
85
        {
85
86
          buff[0]=FN_HOMELIB;
86
87
          (void) strmov_overlapp(buff+1,buff+length);
100
101
      }
101
102
    }
102
103
  }
103
 
  return;
 
104
  DBUG_PRINT("exit",("to: '%s'",to));
 
105
  DBUG_VOID_RETURN;
104
106
} /* pack_dirname */
105
107
 
106
108
 
128
130
{
129
131
  register size_t length;
130
132
  register char * pos;
131
 
  register const char * from_ptr;
 
133
  register char * from_ptr;
132
134
  register char * start;
133
135
  char parent[5],                               /* for "FN_PARENTDIR" */
134
136
       buff[FN_REFLEN+1],*end_parentdir;
135
137
#ifdef BACKSLASH_MBTAIL
136
138
  CHARSET_INFO *fs= fs_character_set();
137
139
#endif
 
140
  DBUG_ENTER("cleanup_dirname");
 
141
  DBUG_PRINT("enter",("from: '%s'",from));
138
142
 
139
143
  start=buff;
140
 
  from_ptr= from;
 
144
  from_ptr=(char *) from;
141
145
#ifdef FN_DEVCHAR
142
146
  if ((pos=strrchr(from_ptr,FN_DEVCHAR)) != 0)
143
147
  {                                             /* Skip device part */
144
148
    length=(size_t) (pos-from_ptr)+1;
145
 
    start=my_stpncpy(buff,from_ptr,length); from_ptr+=length;
 
149
    start=strnmov(buff,from_ptr,length); from_ptr+=length;
146
150
  }
147
151
#endif
148
152
 
149
153
  parent[0]=FN_LIBCHAR;
150
 
  length=(size_t) (my_stpcpy(parent+1,FN_PARENTDIR)-parent);
 
154
  length=(size_t) (strmov(parent+1,FN_PARENTDIR)-parent);
151
155
  for (pos=start ; (*pos= *from_ptr++) != 0 ; pos++)
152
156
  {
153
157
#ifdef BACKSLASH_MBTAIL
154
 
    uint32_t l;
 
158
    uint l;
155
159
    if (use_mb(fs) && (l= my_ismbchar(fs, from_ptr - 1, from_ptr + 2)))
156
160
    {
157
161
      for (l-- ; l ; *++pos= *from_ptr++, l--);
163
167
      *pos = FN_LIBCHAR;
164
168
    if (*pos == FN_LIBCHAR)
165
169
    {
166
 
      if ((size_t) (pos-start) > length &&
167
 
          memcmp(pos-length,parent,length) == 0)
 
170
      if ((size_t) (pos-start) > length && bcmp(pos-length,parent,length) == 0)
168
171
      {                                         /* If .../../; skip prev */
169
172
        pos-=length;
170
173
        if (pos != start)
177
180
              pos+=length+1;                    /* Don't unpack ~/.. */
178
181
              continue;
179
182
            }
180
 
            pos=my_stpcpy(buff,home_dir)-1;     /* Unpacks ~/.. */
 
183
            pos=strmov(buff,home_dir)-1;        /* Unpacks ~/.. */
181
184
            if (*pos == FN_LIBCHAR)
182
185
              pos--;                            /* home ended with '/' */
183
186
          }
188
191
              pos+=length+1;                    /* Don't unpack ./.. */
189
192
              continue;
190
193
            }
191
 
            pos=my_stpcpy(buff,curr_dir)-1;     /* Unpacks ./.. */
 
194
            pos=strmov(buff,curr_dir)-1;        /* Unpacks ./.. */
192
195
            if (*pos == FN_LIBCHAR)
193
196
              pos--;                            /* home ended with '/' */
194
197
          }
195
198
          end_parentdir=pos;
196
199
          while (pos >= start && *pos != FN_LIBCHAR)    /* remove prev dir */
197
200
            pos--;
198
 
          if (pos[1] == FN_HOMELIB || memcmp(pos,parent,length) == 0)
 
201
          if (pos[1] == FN_HOMELIB || bcmp(pos,parent,length) == 0)
199
202
          {                                     /* Don't remove ~user/ */
200
 
            pos=my_stpcpy(end_parentdir+1,parent);
 
203
            pos=strmov(end_parentdir+1,parent);
201
204
            *pos=FN_LIBCHAR;
202
205
            continue;
203
206
          }
204
207
        }
205
208
      }
206
209
      else if ((size_t) (pos-start) == length-1 &&
207
 
               !memcmp(start,parent+1,length-1))
 
210
               !bcmp(start,parent+1,length-1))
208
211
        start=pos;                              /* Starts with "../" */
209
212
      else if (pos-start > 0 && pos[-1] == FN_LIBCHAR)
210
213
      {
223
226
      }
224
227
    }
225
228
  }
226
 
  (void) my_stpcpy(to,buff);
227
 
  return((size_t) (pos-buff));
 
229
  (void) strmov(to,buff);
 
230
  DBUG_PRINT("exit",("to: '%s'",to));
 
231
  DBUG_RETURN((size_t) (pos-buff));
228
232
} /* cleanup_dirname */
229
233
 
230
234
 
237
241
*/
238
242
 
239
243
 
240
 
bool my_use_symdir=0;   /* Set this if you want to use symdirs */
 
244
my_bool my_use_symdir=0;        /* Set this if you want to use symdirs */
241
245
 
242
246
#ifdef USE_SYMDIR
243
247
void symdirget(char *dir)
244
248
{
245
249
  char buff[FN_REFLEN];
246
 
  char *pos= strchr(dir, '\0');
 
250
  char *pos=strend(dir);
247
251
  if (dir[0] && pos[-1] != FN_DEVCHAR && my_access(dir, F_OK))
248
252
  {
249
253
    File file;
250
254
    size_t length;
251
255
    char temp= *(--pos);            /* May be "/" or "\" */
252
 
    my_stpcpy(pos,".sym");
 
256
    strmov(pos,".sym");
253
257
    file= my_open(dir, O_RDONLY, MYF(0));
254
258
    *pos++=temp; *pos=0;          /* Restore old filename */
255
259
    if (file >= 0)
296
300
{
297
301
  size_t length, h_length;
298
302
  char buff[FN_REFLEN+1+4],*suffix,*tilde_expansion;
 
303
  DBUG_ENTER("unpack_dirname");
299
304
 
300
305
  (void) intern_filename(buff,from);        /* Change to intern name */
301
306
  length= strlen(buff);                     /* Fix that '/' is last */
321
326
        if (tilde_expansion[h_length-1] == FN_LIBCHAR)
322
327
          h_length--;
323
328
        if (buff+h_length < suffix)
324
 
          memcpy(buff+h_length, suffix, length);
 
329
          bmove(buff+h_length,suffix,length);
325
330
        else
326
 
          bmove_upp((unsigned char*) buff+h_length+length, (unsigned char*) suffix+length, length);
327
 
        memcpy(buff, tilde_expansion, h_length);
 
331
          bmove_upp((uchar*) buff+h_length+length, (uchar*) suffix+length, length);
 
332
        bmove(buff,tilde_expansion,h_length);
328
333
      }
329
334
    }
330
335
  }
332
337
  if (my_use_symdir)
333
338
    symdirget(buff);
334
339
#endif
335
 
  return(system_filename(to,buff));     /* Fix for open */
 
340
  DBUG_RETURN(system_filename(to,buff));        /* Fix for open */
336
341
} /* unpack_dirname */
337
342
 
338
343
 
349
354
    struct passwd *user_entry;
350
355
 
351
356
    if (!(str=strchr(*path,FN_LIBCHAR)))
352
 
      str= strchr(*path, '\0');
 
357
      str=strend(*path);
353
358
    save= *str; *str= '\0';
354
359
    user_entry=getpwnam(*path);
355
360
    *str=save;
361
366
    }
362
367
  }
363
368
#endif
364
 
  return NULL;
 
369
  return (char *) 0;
365
370
}
366
371
 
367
372
 
386
391
{
387
392
  size_t length, n_length, buff_length;
388
393
  char buff[FN_REFLEN];
 
394
  DBUG_ENTER("unpack_filename");
389
395
 
390
396
  length=dirname_part(buff, from, &buff_length);/* copy & convert dirname */
391
397
  n_length=unpack_dirname(buff,buff);
392
398
  if (n_length+strlen(from+length) < FN_REFLEN)
393
399
  {
394
 
    (void) my_stpcpy(buff+n_length,from+length);
 
400
    (void) strmov(buff+n_length,from+length);
395
401
    length= system_filename(to,buff);           /* Fix to usably filename */
396
402
  }
397
403
  else
398
404
    length= system_filename(to,from);           /* Fix to usably filename */
399
 
  return(length);
 
405
  DBUG_RETURN(length);
400
406
} /* unpack_filename */
401
407
 
402
408
 
421
427
  size_t length;
422
428
  char * to_pos,from_pos,pos;
423
429
  char buff[FN_REFLEN];
 
430
  DBUG_ENTER("system_filename");
424
431
 
425
432
  libchar_found=0;
426
 
  (void) my_stpcpy(buff,from);                   /* If to == from */
 
433
  (void) strmov(buff,from);                      /* If to == from */
427
434
  from_pos= buff;
428
435
  if ((pos=strrchr(from_pos,FN_DEVCHAR)))       /* Skip device part */
429
436
  {
430
437
    pos++;
431
 
    to_pos=my_stpncpy(to,from_pos,(size_t) (pos-from_pos));
 
438
    to_pos=strnmov(to,from_pos,(size_t) (pos-from_pos));
432
439
    from_pos=pos;
433
440
  }
434
441
  else
439
446
  if (strchr(from_pos,FN_LIBCHAR))
440
447
  {
441
448
    *(to_pos++) = FN_C_BEFORE_DIR;
442
 
    if (strstr(from_pos,FN_ROOTDIR) == from_pos)
 
449
    if (strinstr(from_pos,FN_ROOTDIR) == 1)
443
450
    {
444
451
      from_pos+=strlen(FN_ROOTDIR);             /* Actually +1 but... */
445
452
      if (! strchr(from_pos,FN_LIBCHAR))
446
453
      {                                         /* No dir, use [000000] */
447
 
        to_pos=my_stpcpy(to_pos,FN_C_ROOT_DIR);
 
454
        to_pos=strmov(to_pos,FN_C_ROOT_DIR);
448
455
        libchar_found++;
449
456
      }
450
457
    }
455
462
    {
456
463
      if (libchar_found++)
457
464
        *(to_pos++)=FN_C_DIR_SEP;               /* Add '.' between dirs */
458
 
      if (strstr(from_pos,FN_PARENTDIR) == from_pos &&
 
465
      if (strinstr(from_pos,FN_PARENTDIR) == 1 &&
459
466
          from_pos+strlen(FN_PARENTDIR) == pos)
460
 
        to_pos=my_stpcpy(to_pos,FN_C_PARENT_DIR);       /* Found '../' */
 
467
        to_pos=strmov(to_pos,FN_C_PARENT_DIR);  /* Found '../' */
461
468
      else
462
 
        to_pos=my_stpncpy(to_pos,from_pos,(size_t) (pos-from_pos));
 
469
        to_pos=strnmov(to_pos,from_pos,(size_t) (pos-from_pos));
463
470
      from_pos=pos+1;
464
471
    }
465
472
    *(to_pos++)=FN_C_AFTER_DIR;
466
473
  }
467
 
  length= (size_t) (my_stpcpy(to_pos,from_pos)-to);
468
 
  return(length);
 
474
  length= (size_t) (strmov(to_pos,from_pos)-to);
 
475
  DBUG_PRINT("exit",("name: '%s'",to));
 
476
  DBUG_RETURN(length);
469
477
#endif
470
478
} /* system_filename */
471
479
 
478
486
  char buff[FN_REFLEN];
479
487
  if (from == to)
480
488
  {                                             /* Dirname may destroy from */
481
 
    my_stpcpy(buff,from);
 
489
    strmov(buff,from);
482
490
    from=buff;
483
491
  }
484
492
  length= dirname_part(to, from, &to_length);   /* Copy dirname & fix chars */
485
 
  (void) my_stpcpy(to + to_length,from+length);
 
493
  (void) strmov(to + to_length,from+length);
486
494
  return (to);
487
495
} /* intern_filename */