~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/internal/mf_dirname.cc

  • Committer: Brian Aker
  • Date: 2010-02-11 22:43:58 UTC
  • Revision ID: brian@gaz-20100211224358-y0gdvnat2ahg4c1e
Disabling support for memcached plugins until we can test for version of
memcached.

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"
17
 
#include <mystrings/m_string.h>
 
16
#include "config.h"
 
17
 
 
18
#include "drizzled/internal/my_sys.h"
 
19
#include "drizzled/internal/m_string.h"
 
20
 
 
21
#include <algorithm>
 
22
 
 
23
using namespace std;
 
24
 
 
25
namespace drizzled
 
26
{
 
27
namespace internal
 
28
{
18
29
 
19
30
        /* Functions definied in this file */
20
31
 
21
32
size_t dirname_length(const char *name)
22
33
{
23
34
  register const char *pos, *gpos;
24
 
#ifdef BASKSLASH_MBTAIL
25
 
  CHARSET_INFO *fs= fs_character_set();
26
 
#endif
27
35
#ifdef FN_DEVCHAR
28
36
  if ((pos=(char*)strrchr(name,FN_DEVCHAR)) == 0)
29
37
#endif
32
40
  gpos= pos++;
33
41
  for ( ; *pos ; pos++)                         /* Find last FN_LIBCHAR */
34
42
  {
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
 
        )
 
43
    if (*pos == FN_LIBCHAR || *pos == '/')
48
44
      gpos=pos;
49
45
  }
50
46
  return gpos-name+1;
91
87
    Adds a FN_LIBCHAR to end if the result string if there isn't one
92
88
    and the last isn't dev_char.
93
89
    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
 
90
    If you want to use the whole 'from' string, just send NULL as the
95
91
    last argument.
96
92
 
97
93
    If the result string is larger than FN_REFLEN -1, then it's cut.
107
103
char *convert_dirname(char *to, const char *from, const char *from_end)
108
104
{
109
105
  char *to_org=to;
110
 
#ifdef BACKSLASH_MBTAIL
111
 
  CHARSET_INFO *fs= fs_character_set();
112
 
#endif
113
106
 
114
107
  /* We use -2 here, becasue we need place for the last FN_LIBCHAR */
115
108
  if (!from_end || (from_end - from) > FN_REFLEN-2)
116
109
    from_end=from+FN_REFLEN -2;
117
110
 
118
 
#if FN_LIBCHAR != '/' || defined(FN_C_BEFORE_DIR_2)
 
111
#if FN_LIBCHAR != '/'
119
112
  {
120
113
    for (; from != from_end && *from ; from++)
121
114
    {
122
115
      if (*from == '/')
123
116
        *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
117
      else
131
118
      {
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
 
        }
 
119
        *to++= *from;
146
120
      }
147
121
    }
148
122
    *to=0;
149
123
  }
150
124
#else
151
125
  /* This is ok even if to == from, becasue we need to cut the string */
152
 
  to= strmake(to, from, (size_t) (from_end-from));
 
126
  size_t len= min(strlen(from),(size_t)(from_end-from));
 
127
  void *ret= memmove(to, from, len);
 
128
  assert(ret != NULL);
 
129
  to+= len;
 
130
  to[0]= '\0';
153
131
#endif
154
132
 
155
133
  /* Add FN_LIBCHAR to the end of directory path */
160
138
  }
161
139
  return(to);                              /* Pointer to end of dir */
162
140
} /* convert_dirname */
 
141
 
 
142
} /* namespace internal */
 
143
} /* namespace drizzled */