| 27 | /* to may be == from */ |
| 28 | |
| 29 | void pack_dirname(char * to, const char *from) |
| 30 | { |
| 31 | int cwd_err; |
| 32 | size_t d_length,length,UNINIT_VAR(buff_length); |
| 33 | char * start; |
| 34 | char buff[FN_REFLEN]; |
| 35 | DBUG_ENTER("pack_dirname"); |
| 36 | |
| 37 | (void) intern_filename(to,from); /* Change to intern name */ |
| 38 | |
| 39 | #ifdef FN_DEVCHAR |
| 40 | if ((start=strrchr(to,FN_DEVCHAR)) != 0) /* Skip device part */ |
| 41 | start++; |
| 42 | else |
| 43 | #endif |
| 44 | start=to; |
| 45 | |
| 46 | if (!(cwd_err= my_getwd(buff,FN_REFLEN,MYF(0)))) |
| 47 | { |
| 48 | buff_length= strlen(buff); |
| 49 | d_length= (size_t) (start-to); |
| 50 | if ((start == to || |
| 51 | (buff_length == d_length && !memcmp(buff,start,d_length))) && |
| 52 | *start != FN_LIBCHAR && *start) |
| 53 | { /* Put current dir before */ |
| 54 | bchange((uchar*) to, d_length, (uchar*) buff, buff_length, strlen(to)+1); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | if ((d_length= cleanup_dirname(to,to)) != 0) |
| 59 | { |
| 60 | length=0; |
| 61 | if (home_dir) |
| 62 | { |
| 63 | length= strlen(home_dir); |
| 64 | if (home_dir[length-1] == FN_LIBCHAR) |
| 65 | length--; /* Don't test last '/' */ |
| 66 | } |
| 67 | if (length > 1 && length < d_length) |
| 68 | { /* test if /xx/yy -> ~/yy */ |
| 69 | if (memcmp(to,home_dir,length) == 0 && to[length] == FN_LIBCHAR) |
| 70 | { |
| 71 | to[0]=FN_HOMELIB; /* Filename begins with ~ */ |
| 72 | (void) strmov_overlapp(to+1,to+length); |
| 73 | } |
| 74 | } |
| 75 | if (! cwd_err) |
| 76 | { /* Test if cwd is ~/... */ |
| 77 | if (length > 1 && length < buff_length) |
| 78 | { |
| 79 | if (memcmp(buff,home_dir,length) == 0 && buff[length] == FN_LIBCHAR) |
| 80 | { |
| 81 | buff[0]=FN_HOMELIB; |
| 82 | (void) strmov_overlapp(buff+1,buff+length); |
| 83 | } |
| 84 | } |
| 85 | if (is_prefix(to,buff)) |
| 86 | { |
no test coverage detected