~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/mf_format.cc

  • Committer: Brian Aker
  • Date: 2009-08-21 18:46:31 UTC
  • mto: This revision was merged to the branch mainline in revision 1123.
  • Revision ID: brian@gaz-20090821184631-e11gja79070fvhk4
Cleanup around page checksum removal

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
   along with this program; if not, write to the Free Software
14
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
 
#include "mysys_priv.h"
 
16
#include "mysys/mysys_priv.h"
17
17
#include <mystrings/m_string.h>
18
18
 
 
19
#include <algorithm>
 
20
 
 
21
using namespace std;
 
22
 
19
23
/*
20
24
  Formats a filename with possible replace of directory of extension
21
25
  Function can handle the case where 'to' == 'name'
42
46
  else if ((flag & MY_RELATIVE_PATH) && !test_if_hard_path(dev))
43
47
  {
44
48
    /* Put 'dir' before the given path */
45
 
    strmake(buff,dev,sizeof(buff)-1);
 
49
    strncpy(buff,dev,sizeof(buff)-1);
46
50
    pos=convert_dirname(dev,dir,NULL);
47
 
    strmake(pos,buff,sizeof(buff)-1- (int) (pos-dev));
 
51
    strncpy(pos,buff,sizeof(buff)-1- (int) (pos-dev));
48
52
  }
49
53
 
50
 
  if (flag & MY_PACK_FILENAME)
51
 
    pack_dirname(dev,dev);                      /* Put in ./.. and ~/.. */
52
54
  if (flag & MY_UNPACK_FILENAME)
53
55
    (void) unpack_dirname(dev,dev);             /* Replace ~/.. with dir */
54
56
 
78
80
    size_t tmp_length;
79
81
    if (flag & MY_SAFE_PATH)
80
82
      return NULL;
81
 
    tmp_length= strlength(startpos);
82
 
    (void) strmake(to,startpos,cmin(tmp_length,FN_REFLEN-1));
 
83
    tmp_length= min(strlength(startpos), (size_t)(FN_REFLEN-1));
 
84
    strncpy(to,startpos,tmp_length);
 
85
    to[tmp_length]= '\0';
83
86
  }
84
87
  else
85
88
  {
86
89
    if (to == startpos)
87
90
    {
88
 
      memcpy(buff, name, length); /* Save name for last copy */
 
91
      memmove(buff, name, length); /* Save name for last copy */
89
92
      name=buff;
90
93
    }
91
 
    pos=strmake(my_stpcpy(to,dev),name,length);
92
 
    (void) my_stpcpy(pos,ext);                  /* Don't convert extension */
 
94
    char *tmp= strcpy(to, dev) + strlen(dev);
 
95
    pos= strncpy(tmp,name,length) + length;
 
96
    (void) strcpy(pos,ext);                     /* Don't convert extension */
93
97
  }
94
98
  /*
95
99
    If MY_RETURN_REAL_PATH and MY_RESOLVE_SYMLINK is given, only do
96
100
    realpath if the file is a symbolic link
97
101
  */
98
102
  if (flag & MY_RETURN_REAL_PATH)
99
 
    (void) my_realpath(to, to, MYF(flag & MY_RESOLVE_SYMLINKS ?
100
 
                                   MY_RESOLVE_LINK: 0));
 
103
  {
 
104
    struct stat stat_buff;
 
105
    char rp_buff[PATH_MAX];
 
106
    if ((!flag & MY_RESOLVE_SYMLINKS) || 
 
107
       (!lstat(to,&stat_buff) && S_ISLNK(stat_buff.st_mode)))
 
108
    {
 
109
      if (!realpath(to,rp_buff))
 
110
        my_load_path(rp_buff, to, NULL);
 
111
      rp_buff[FN_REFLEN-1]= '\0';
 
112
      strcpy(to,rp_buff);
 
113
    }
 
114
  }
101
115
  else if (flag & MY_RESOLVE_SYMLINKS)
102
116
  {
103
 
    my_stpcpy(buff,to);
104
 
    (void) my_readlink(to, buff, MYF(0));
 
117
    strcpy(buff,to);
 
118
    ssize_t sym_link_size= readlink(buff,to,FN_REFLEN-1);
 
119
    if (sym_link_size >= 0)
 
120
      to[sym_link_size]= '\0';
105
121
  }
106
122
  return(to);
107
123
} /* fn_format */