~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/mf_dirname.cc

Merged in latest plugin-slot-reorg.

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
 
    uint32_t l;
37
 
    if (use_mb(fs) && (l= my_ismbchar(fs, pos, pos + 3)))
38
 
    {
39
 
      pos+= l - 1;
40
 
      continue;
41
 
    }
42
 
#endif
43
37
    if (*pos == FN_LIBCHAR || *pos == '/'
44
38
#ifdef FN_C_AFTER_DIR
45
39
        || *pos == FN_C_AFTER_DIR || *pos == FN_C_AFTER_DIR_2
80
74
  SYNPOSIS
81
75
    convert_dirname()
82
76
    to                          Store result here. Must be at least of size
83
 
                                cmin(FN_REFLEN, strlen(from) + 1) to make room
 
77
                                min(FN_REFLEN, strlen(from) + 1) to make room
84
78
                                for adding FN_LIBCHAR at the end.
85
79
    from                        Original filename. May be == to
86
80
    from_end                    Pointer at end of filename (normally end \0)
107
101
char *convert_dirname(char *to, const char *from, const char *from_end)
108
102
{
109
103
  char *to_org=to;
110
 
#ifdef BACKSLASH_MBTAIL
111
 
  CHARSET_INFO *fs= fs_character_set();
112
 
#endif
113
104
 
114
105
  /* We use -2 here, becasue we need place for the last FN_LIBCHAR */
115
106
  if (!from_end || (from_end - from) > FN_REFLEN-2)
129
120
#endif
130
121
      else
131
122
      {
132
 
#ifdef BACKSLASH_MBTAIL
133
 
        uint32_t 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
 
        }
 
123
        *to++= *from;
146
124
      }
147
125
    }
148
126
    *to=0;
149
127
  }
150
128
#else
151
129
  /* This is ok even if to == from, becasue we need to cut the string */
152
 
  to= strmake(to, from, (size_t) (from_end-from));
 
130
  size_t len= min(strlen(from),(size_t)(from_end-from));
 
131
  void *ret= memmove(to, from, len);
 
132
  assert(ret != NULL);
 
133
  to+= len;
 
134
  to[0]= '\0';
153
135
#endif
154
136
 
155
137
  /* Add FN_LIBCHAR to the end of directory path */