12
12
You should have received a copy of the GNU General Public License
13
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
18
#include <drizzled/internal/my_sys.h>
19
#include <drizzled/internal/m_string.h>
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
#include "mysys_priv.h"
30
19
/* Functions definied in this file */
32
21
size_t dirname_length(const char *name)
34
register const char *pos, *gpos;
23
register char *pos, *gpos;
24
#ifdef BASKSLASH_MBTAIL
25
CHARSET_INFO *fs= fs_character_set();
36
28
if ((pos=(char*)strrchr(name,FN_DEVCHAR)) == 0)
41
33
for ( ; *pos ; pos++) /* Find last FN_LIBCHAR */
43
if (*pos == FN_LIBCHAR || *pos == '/')
35
#ifdef BASKSLASH_MBTAIL
37
if (use_mb(fs) && (l= my_ismbchar(fs, pos, pos + 3)))
43
if (*pos == FN_LIBCHAR || *pos == '/'
45
|| *pos == FN_C_AFTER_DIR || *pos == FN_C_AFTER_DIR_2
50
return (size_t) (gpos+1-(char*) name);
63
67
size_t dirname_part(char *to, const char *name, size_t *to_res_length)
70
DBUG_ENTER("dirname_part");
71
DBUG_PRINT("enter",("'%s'",name));
67
73
length=dirname_length(name);
68
74
*to_res_length= (size_t) (convert_dirname(to, name, name+length) - to);
87
93
Adds a FN_LIBCHAR to end if the result string if there isn't one
88
94
and the last isn't dev_char.
89
95
Copies data from 'from' until ASCII(0) for until from == from_end
90
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
93
99
If the result string is larger than FN_REFLEN -1, then it's cut.
103
109
char *convert_dirname(char *to, const char *from, const char *from_end)
112
#ifdef BACKSLASH_MBTAIL
113
CHARSET_INFO *fs= fs_character_set();
115
DBUG_ENTER("convert_dirname");
107
117
/* We use -2 here, becasue we need place for the last FN_LIBCHAR */
108
118
if (!from_end || (from_end - from) > FN_REFLEN-2)
109
119
from_end=from+FN_REFLEN -2;
111
#if FN_LIBCHAR != '/'
121
#if FN_LIBCHAR != '/' || defined(FN_C_BEFORE_DIR_2)
113
123
for (; from != from_end && *from ; from++)
115
125
if (*from == '/')
116
126
*to++= FN_LIBCHAR;
127
#ifdef FN_C_BEFORE_DIR_2
128
else if (*from == FN_C_BEFORE_DIR_2)
129
*to++= FN_C_BEFORE_DIR;
130
else if (*from == FN_C_AFTER_DIR_2)
131
*to++= FN_C_AFTER_DIR;
135
#ifdef BACKSLASH_MBTAIL
137
if (use_mb(fs) && (l= my_ismbchar(fs, from, from + 3)))
139
memmove(to, from, l);
142
to_org= to; /* Don't look inside mbchar */
125
154
/* 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);
155
to= strmake(to, from, (size_t) (from_end-from));
133
158
/* Add FN_LIBCHAR to the end of directory path */