~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/mf_dirname.c

  • Committer: Monty Taylor
  • Date: 2008-07-05 16:23:40 UTC
  • mto: This revision was merged to the branch mainline in revision 63.
  • Revision ID: monty@inaugust.com-20080705162340-an09yicpupdtwo2m
Fixed simple signdedness problem.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
#include "mysys_priv.h"
17
 
#include <mystrings/m_string.h>
 
17
#include <m_string.h>
18
18
 
19
19
        /* Functions definied in this file */
20
20
 
21
21
size_t dirname_length(const char *name)
22
22
{
23
 
  register const char *pos, *gpos;
 
23
  register char *pos, *gpos;
24
24
#ifdef BASKSLASH_MBTAIL
25
25
  CHARSET_INFO *fs= fs_character_set();
26
26
#endif
27
27
#ifdef FN_DEVCHAR
28
28
  if ((pos=(char*)strrchr(name,FN_DEVCHAR)) == 0)
29
29
#endif
30
 
    pos=name-1;
 
30
    pos=(char*) name-1;
31
31
 
32
32
  gpos= pos++;
33
33
  for ( ; *pos ; pos++)                         /* Find last FN_LIBCHAR */
34
34
  {
35
35
#ifdef BASKSLASH_MBTAIL
36
 
    uint32_t l;
 
36
    uint l;
37
37
    if (use_mb(fs) && (l= my_ismbchar(fs, pos, pos + 3)))
38
38
    {
39
39
      pos+= l - 1;
47
47
        )
48
48
      gpos=pos;
49
49
  }
50
 
  return gpos-name+1;
 
50
  return (size_t) (gpos+1-(char*) name);
51
51
}
52
52
 
53
53
 
67
67
size_t dirname_part(char *to, const char *name, size_t *to_res_length)
68
68
{
69
69
  size_t length;
 
70
  DBUG_ENTER("dirname_part");
 
71
  DBUG_PRINT("enter",("'%s'",name));
70
72
 
71
73
  length=dirname_length(name);
72
74
  *to_res_length= (size_t) (convert_dirname(to, name, name+length) - to);
73
 
  return(length);
 
75
  DBUG_RETURN(length);
74
76
} /* dirname */
75
77
 
76
78
 
80
82
  SYNPOSIS
81
83
    convert_dirname()
82
84
    to                          Store result here. Must be at least of size
83
 
                                cmin(FN_REFLEN, strlen(from) + 1) to make room
 
85
                                min(FN_REFLEN, strlen(from) + 1) to make room
84
86
                                for adding FN_LIBCHAR at the end.
85
87
    from                        Original filename. May be == to
86
88
    from_end                    Pointer at end of filename (normally end \0)
91
93
    Adds a FN_LIBCHAR to end if the result string if there isn't one
92
94
    and the last isn't dev_char.
93
95
    Copies data from 'from' until ASCII(0) for until from == from_end
94
 
    If you want to use the whole 'from' string, just send NULL as the
 
96
    If you want to use the whole 'from' string, just send NullS as the
95
97
    last argument.
96
98
 
97
99
    If the result string is larger than FN_REFLEN -1, then it's cut.
110
112
#ifdef BACKSLASH_MBTAIL
111
113
  CHARSET_INFO *fs= fs_character_set();
112
114
#endif
 
115
  DBUG_ENTER("convert_dirname");
113
116
 
114
117
  /* We use -2 here, becasue we need place for the last FN_LIBCHAR */
115
118
  if (!from_end || (from_end - from) > FN_REFLEN-2)
130
133
      else
131
134
      {
132
135
#ifdef BACKSLASH_MBTAIL
133
 
        uint32_t l;
 
136
        uint l;
134
137
        if (use_mb(fs) && (l= my_ismbchar(fs, from, from + 3)))
135
138
        {
136
139
          memmove(to, from, l);
158
161
    *to++=FN_LIBCHAR;
159
162
    *to=0;
160
163
  }
161
 
  return(to);                              /* Pointer to end of dir */
 
164
  DBUG_RETURN(to);                              /* Pointer to end of dir */
162
165
} /* convert_dirname */