~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/mf_pack.c

  • Committer: Monty Taylor
  • Date: 2008-07-01 14:33:36 UTC
  • mto: (28.1.12 backport_patch)
  • mto: This revision was merged to the branch mainline in revision 34.
  • Revision ID: monty@inaugust.com-20080701143336-8uihm7dhpu92rt0q
Somehow missed moving password.c. Duh.

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