~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/mf_dirname.cc

  • Committer: Monty Taylor
  • Date: 2009-10-06 19:37:52 UTC
  • mto: This revision was merged to the branch mainline in revision 1184.
  • Revision ID: mordred@inaugust.com-20091006193752-4dx2c8u35j4em79g
Removed more server_includes.h from headers.

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
 
 
23
 
19
24
        /* Functions definied in this file */
20
25
 
21
26
size_t dirname_length(const char *name)
22
27
{
23
28
  register const char *pos, *gpos;
24
 
#ifdef BASKSLASH_MBTAIL
25
 
  CHARSET_INFO *fs= fs_character_set();
26
 
#endif
27
29
#ifdef FN_DEVCHAR
28
30
  if ((pos=(char*)strrchr(name,FN_DEVCHAR)) == 0)
29
31
#endif
32
34
  gpos= pos++;
33
35
  for ( ; *pos ; pos++)                         /* Find last FN_LIBCHAR */
34
36
  {
35
 
#ifdef BASKSLASH_MBTAIL
36
 
    uint l;
37
 
    if (use_mb(fs) && (l= my_ismbchar(fs, pos, pos + 3)))
38
 
    {
39
 
      pos+= l - 1;
40
 
      continue;
41
 
    }
42
 
#endif
43
 
    if (*pos == FN_LIBCHAR || *pos == '/'
44
 
#ifdef FN_C_AFTER_DIR
45
 
        || *pos == FN_C_AFTER_DIR || *pos == FN_C_AFTER_DIR_2
46
 
#endif
47
 
        )
 
37
    if (*pos == FN_LIBCHAR || *pos == '/')
48
38
      gpos=pos;
49
39
  }
50
40
  return gpos-name+1;
91
81
    Adds a FN_LIBCHAR to end if the result string if there isn't one
92
82
    and the last isn't dev_char.
93
83
    Copies data from 'from' until ASCII(0) for until from == from_end
94
 
    If you want to use the whole 'from' string, just send NullS as the
 
84
    If you want to use the whole 'from' string, just send NULL as the
95
85
    last argument.
96
86
 
97
87
    If the result string is larger than FN_REFLEN -1, then it's cut.
107
97
char *convert_dirname(char *to, const char *from, const char *from_end)
108
98
{
109
99
  char *to_org=to;
110
 
#ifdef BACKSLASH_MBTAIL
111
 
  CHARSET_INFO *fs= fs_character_set();
112
 
#endif
113
100
 
114
101
  /* We use -2 here, becasue we need place for the last FN_LIBCHAR */
115
102
  if (!from_end || (from_end - from) > FN_REFLEN-2)
116
103
    from_end=from+FN_REFLEN -2;
117
104
 
118
 
#if FN_LIBCHAR != '/' || defined(FN_C_BEFORE_DIR_2)
 
105
#if FN_LIBCHAR != '/'
119
106
  {
120
107
    for (; from != from_end && *from ; from++)
121
108
    {
122
109
      if (*from == '/')
123
110
        *to++= FN_LIBCHAR;
124
 
#ifdef FN_C_BEFORE_DIR_2
125
 
      else if (*from == FN_C_BEFORE_DIR_2)
126
 
        *to++= FN_C_BEFORE_DIR;
127
 
      else if (*from == FN_C_AFTER_DIR_2)
128
 
        *to++= FN_C_AFTER_DIR;
129
 
#endif
130
111
      else
131
112
      {
132
 
#ifdef BACKSLASH_MBTAIL
133
 
        uint l;
134
 
        if (use_mb(fs) && (l= my_ismbchar(fs, from, from + 3)))
135
 
        {
136
 
          memmove(to, from, l);
137
 
          to+= l;
138
 
          from+= l - 1;
139
 
          to_org= to; /* Don't look inside mbchar */
140
 
        }
141
 
        else
142
 
#endif
143
 
        {
144
 
          *to++= *from;
145
 
        }
 
113
        *to++= *from;
146
114
      }
147
115
    }
148
116
    *to=0;
149
117
  }
150
118
#else
151
119
  /* This is ok even if to == from, becasue we need to cut the string */
152
 
  to= strmake(to, from, (size_t) (from_end-from));
 
120
  size_t len= min(strlen(from),(size_t)(from_end-from));
 
121
  void *ret= memmove(to, from, len);
 
122
  assert(ret != NULL);
 
123
  to+= len;
 
124
  to[0]= '\0';
153
125
#endif
154
126
 
155
127
  /* Add FN_LIBCHAR to the end of directory path */