~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/mf_format.c

  • Committer: Monty Taylor
  • Date: 2008-10-23 00:05:28 UTC
  • Revision ID: monty@inaugust.com-20081023000528-grdvrd8c4058nutm
Moved my_handler to myisam, which is where it actually belongs.

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 "config.h"
17
 
 
18
 
#include "drizzled/internal/my_sys.h"
19
 
 
20
 
#include <fcntl.h>
21
 
 
22
 
#ifdef HAVE_SYS_STAT_H
23
 
# include <sys/stat.h>
24
 
#endif
25
 
 
26
 
#include <algorithm>
27
 
 
28
 
#include "drizzled/internal/m_string.h"
29
 
 
30
 
using namespace std;
31
 
 
32
 
namespace drizzled
33
 
{
34
 
namespace internal
35
 
{
 
16
#include "mysys_priv.h"
 
17
#include <mystrings/m_string.h>
36
18
 
37
19
/*
38
20
  Formats a filename with possible replace of directory of extension
60
42
  else if ((flag & MY_RELATIVE_PATH) && !test_if_hard_path(dev))
61
43
  {
62
44
    /* Put 'dir' before the given path */
63
 
    strncpy(buff,dev,sizeof(buff)-1);
 
45
    strmake(buff,dev,sizeof(buff)-1);
64
46
    pos=convert_dirname(dev,dir,NULL);
65
 
    strncpy(pos,buff,sizeof(buff)-1- (int) (pos-dev));
 
47
    strmake(pos,buff,sizeof(buff)-1- (int) (pos-dev));
66
48
  }
67
49
 
 
50
  if (flag & MY_PACK_FILENAME)
 
51
    pack_dirname(dev,dev);                      /* Put in ./.. and ~/.. */
68
52
  if (flag & MY_UNPACK_FILENAME)
69
53
    (void) unpack_dirname(dev,dev);             /* Replace ~/.. with dir */
70
54
 
94
78
    size_t tmp_length;
95
79
    if (flag & MY_SAFE_PATH)
96
80
      return NULL;
97
 
    tmp_length= min(strlength(startpos), (size_t)(FN_REFLEN-1));
98
 
    strncpy(to,startpos,tmp_length);
99
 
    to[tmp_length]= '\0';
 
81
    tmp_length= strlength(startpos);
 
82
    (void) strmake(to,startpos,cmin(tmp_length,FN_REFLEN-1));
100
83
  }
101
84
  else
102
85
  {
103
86
    if (to == startpos)
104
87
    {
105
 
      memmove(buff, name, length); /* Save name for last copy */
 
88
      memcpy(buff, name, length); /* Save name for last copy */
106
89
      name=buff;
107
90
    }
108
 
    char *tmp= strcpy(to, dev) + strlen(dev);
109
 
    pos= strncpy(tmp,name,length) + length;
110
 
    (void) strcpy(pos,ext);                     /* Don't convert extension */
 
91
    pos=strmake(my_stpcpy(to,dev),name,length);
 
92
    (void) my_stpcpy(pos,ext);                  /* Don't convert extension */
111
93
  }
112
94
  /*
113
95
    If MY_RETURN_REAL_PATH and MY_RESOLVE_SYMLINK is given, only do
114
96
    realpath if the file is a symbolic link
115
97
  */
116
98
  if (flag & MY_RETURN_REAL_PATH)
117
 
  {
118
 
    struct stat stat_buff;
119
 
    char rp_buff[PATH_MAX];
120
 
    if ((!flag & MY_RESOLVE_SYMLINKS) || 
121
 
       (!lstat(to,&stat_buff) && S_ISLNK(stat_buff.st_mode)))
122
 
    {
123
 
      if (!realpath(to,rp_buff))
124
 
        my_load_path(rp_buff, to, NULL);
125
 
      rp_buff[FN_REFLEN-1]= '\0';
126
 
      strcpy(to,rp_buff);
127
 
    }
128
 
  }
 
99
    (void) my_realpath(to, to, MYF(flag & MY_RESOLVE_SYMLINKS ?
 
100
                                   MY_RESOLVE_LINK: 0));
129
101
  else if (flag & MY_RESOLVE_SYMLINKS)
130
102
  {
131
 
    strcpy(buff,to);
132
 
    ssize_t sym_link_size= readlink(buff,to,FN_REFLEN-1);
133
 
    if (sym_link_size >= 0)
134
 
      to[sym_link_size]= '\0';
 
103
    my_stpcpy(buff,to);
 
104
    (void) my_readlink(to, buff, MYF(0));
135
105
  }
136
106
  return(to);
137
107
} /* fn_format */
165
135
  }
166
136
  return((size_t) (found - str));
167
137
} /* strlength */
168
 
 
169
 
} /* namespace internal */
170
 
} /* namespace drizzled */