~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/mf_dirname.c

  • Committer: Monty Taylor
  • Date: 2008-10-10 23:04:21 UTC
  • mto: (509.1.1 codestyle)
  • mto: This revision was merged to the branch mainline in revision 511.
  • Revision ID: monty@inaugust.com-20081010230421-zohe1eppxievpw8d
RemovedĀ O_NOFOLLOW

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 "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
 
{
 
16
#include "mysys_priv.h"
 
17
#include <mystrings/m_string.h>
29
18
 
30
19
        /* Functions definied in this file */
31
20
 
32
21
size_t dirname_length(const char *name)
33
22
{
34
23
  register const char *pos, *gpos;
 
24
#ifdef BASKSLASH_MBTAIL
 
25
  CHARSET_INFO *fs= fs_character_set();
 
26
#endif
35
27
#ifdef FN_DEVCHAR
36
28
  if ((pos=(char*)strrchr(name,FN_DEVCHAR)) == 0)
37
29
#endif
40
32
  gpos= pos++;
41
33
  for ( ; *pos ; pos++)                         /* Find last FN_LIBCHAR */
42
34
  {
43
 
    if (*pos == FN_LIBCHAR || *pos == '/')
 
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
    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
        )
44
48
      gpos=pos;
45
49
  }
46
50
  return gpos-name+1;
76
80
  SYNPOSIS
77
81
    convert_dirname()
78
82
    to                          Store result here. Must be at least of size
79
 
                                min(FN_REFLEN, strlen(from) + 1) to make room
 
83
                                cmin(FN_REFLEN, strlen(from) + 1) to make room
80
84
                                for adding FN_LIBCHAR at the end.
81
85
    from                        Original filename. May be == to
82
86
    from_end                    Pointer at end of filename (normally end \0)
103
107
char *convert_dirname(char *to, const char *from, const char *from_end)
104
108
{
105
109
  char *to_org=to;
 
110
#ifdef BACKSLASH_MBTAIL
 
111
  CHARSET_INFO *fs= fs_character_set();
 
112
#endif
106
113
 
107
114
  /* We use -2 here, becasue we need place for the last FN_LIBCHAR */
108
115
  if (!from_end || (from_end - from) > FN_REFLEN-2)
109
116
    from_end=from+FN_REFLEN -2;
110
117
 
111
 
#if FN_LIBCHAR != '/'
 
118
#if FN_LIBCHAR != '/' || defined(FN_C_BEFORE_DIR_2)
112
119
  {
113
120
    for (; from != from_end && *from ; from++)
114
121
    {
115
122
      if (*from == '/')
116
123
        *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
117
130
      else
118
131
      {
119
 
        *to++= *from;
 
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
        }
120
146
      }
121
147
    }
122
148
    *to=0;
123
149
  }
124
150
#else
125
151
  /* This is ok even if to == from, becasue we need to cut the string */
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';
 
152
  to= strmake(to, from, (size_t) (from_end-from));
131
153
#endif
132
154
 
133
155
  /* Add FN_LIBCHAR to the end of directory path */
138
160
  }
139
161
  return(to);                              /* Pointer to end of dir */
140
162
} /* convert_dirname */
141
 
 
142
 
} /* namespace internal */
143
 
} /* namespace drizzled */