00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include <config.h>
00017
00018 #include <drizzled/internal/my_sys.h>
00019 #include <drizzled/internal/m_string.h>
00020
00021 #include <algorithm>
00022
00023 using namespace std;
00024
00025 namespace drizzled
00026 {
00027 namespace internal
00028 {
00029
00030
00031
00032 size_t dirname_length(const char *name)
00033 {
00034 const char *pos, *gpos;
00035 #ifdef FN_DEVCHAR
00036 if ((pos=(char*)strrchr(name,FN_DEVCHAR)) == 0)
00037 #endif
00038 pos=name-1;
00039
00040 gpos= pos++;
00041 for ( ; *pos ; pos++)
00042 {
00043 if (*pos == FN_LIBCHAR || *pos == '/')
00044 gpos=pos;
00045 }
00046 return gpos-name+1;
00047 }
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063 size_t dirname_part(char *to, const char *name, size_t *to_res_length)
00064 {
00065 size_t length;
00066
00067 length=dirname_length(name);
00068 *to_res_length= (size_t) (convert_dirname(to, name, name+length) - to);
00069 return(length);
00070 }
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099 #ifndef FN_DEVCHAR
00100 #define FN_DEVCHAR '\0'
00101 #endif
00102
00103 char *convert_dirname(char *to, const char *from, const char *from_end)
00104 {
00105 char *to_org=to;
00106
00107
00108 if (!from_end || (from_end - from) > FN_REFLEN-2)
00109 from_end=from+FN_REFLEN -2;
00110
00111 #if FN_LIBCHAR != '/'
00112 {
00113 for (; from != from_end && *from ; from++)
00114 {
00115 if (*from == '/')
00116 *to++= FN_LIBCHAR;
00117 else
00118 {
00119 *to++= *from;
00120 }
00121 }
00122 *to=0;
00123 }
00124 #else
00125
00126 size_t len= min(strlen(from),(size_t)(from_end-from));
00127 void *ret= memmove(to, from, len);
00128 assert(ret != NULL);
00129 to+= len;
00130 to[0]= '\0';
00131 #endif
00132
00133
00134 if (to != to_org && (to[-1] != FN_LIBCHAR && to[-1] != FN_DEVCHAR))
00135 {
00136 *to++=FN_LIBCHAR;
00137 *to=0;
00138 }
00139 return(to);
00140 }
00141
00142 }
00143 }