~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/mf_format.c

  • Committer: Mats Kindahl
  • Date: 2008-08-26 07:32:59 UTC
  • mto: (489.1.2 codestyle)
  • mto: This revision was merged to the branch mainline in revision 491.
  • Revision ID: mats@mysql.com-20080826073259-9k4evtajgldgolli
Replaced use of thd_proc_info() macro with calls to
set_proc_info() and get_proc_info() internally.  Introduced
functions set_thd_proc_info() and get_thd_proc_info() for
external users, i.e., plug-ins.

The set_thd_proc_info() accepted callers info that can be used to
print debug output, but the information was not used. The return
value was changed to void and the old value is not fetched any
more. To be able to get the value of proc_info for external
users, the function get_thd_proc_info() was introduced.

The thd_proc_info() macro called set_thd_proc_info() but almost
never used the return value of set_thd_proc_info() so the macro
was replaced with a call of THD::set_proc_info().

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
13
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
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
 
{
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
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
42
24
*/
43
25
 
44
26
char * fn_format(char * to, const char *name, const char *dir,
45
 
                    const char *extension, uint32_t flag)
 
27
                    const char *extension, uint flag)
46
28
{
47
29
  char dev[FN_REFLEN], buff[FN_REFLEN], *pos;
48
30
  const char *startpos = name;
55
37
  if (length == 0 || (flag & MY_REPLACE_DIR))
56
38
  {
57
39
    /* Use given directory */
58
 
    convert_dirname(dev,dir,NULL);              /* Fix to this OS */
 
40
    convert_dirname(dev,dir,NullS);             /* Fix to this OS */
59
41
  }
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);
64
 
    pos=convert_dirname(dev,dir,NULL);
65
 
    strncpy(pos,buff,sizeof(buff)-1- (int) (pos-dev));
 
45
    strmake(buff,dev,sizeof(buff)-1);
 
46
    pos=convert_dirname(dev,dir,NullS);
 
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
 
71
55
  if (!(flag & MY_APPEND_EXT) &&
72
 
      (pos= (char*) strchr(name,FN_EXTCHAR)) != NULL)
 
56
      (pos= (char*) strchr(name,FN_EXTCHAR)) != NullS)
73
57
  {
74
58
    if ((flag & MY_REPLACE_EXT) == 0)           /* If we should keep old ext */
75
59
    {
93
77
    /* To long path, return original or NULL */
94
78
    size_t tmp_length;
95
79
    if (flag & MY_SAFE_PATH)
96
 
      return NULL;
97
 
    tmp_length= min(strlength(startpos), (size_t)(FN_REFLEN-1));
98
 
    strncpy(to,startpos,tmp_length);
99
 
    to[tmp_length]= '\0';
 
80
      return NullS;
 
81
    tmp_length= strlength(startpos);
 
82
    (void) strmake(to,startpos,min(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(stpcpy(to,dev),name,length);
 
92
    (void) 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
    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 */