~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/mf_format.c

  • Committer: Monty Taylor
  • Date: 2008-08-01 22:33:44 UTC
  • mto: (236.1.42 codestyle)
  • mto: This revision was merged to the branch mainline in revision 261.
  • Revision ID: monty@inaugust.com-20080801223344-vzhlflfmtijp1imv
First pass at gettexizing the error messages.

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