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"
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
#include "mysys_priv.h"
17
#include <mystrings/m_string.h>
18
#include "my_static.h"
22
#include "drizzled/internal/m_string.h"
23
#include "my_static.h"
30
23
static char * expand_tilde(char * *path);
31
static size_t system_filename(char * to, const char *from);
34
27
remove unwanted chars from dirname
165
161
bool my_use_symdir=0; /* Set this if you want to use symdirs */
164
void symdirget(char *dir)
166
char buff[FN_REFLEN];
167
char *pos= strchr(dir, '\0');
168
if (dir[0] && pos[-1] != FN_DEVCHAR && my_access(dir, F_OK))
172
char temp= *(--pos); /* May be "/" or "\" */
174
file= my_open(dir, O_RDONLY, MYF(0));
175
*pos++=temp; *pos=0; /* Restore old filename */
178
if ((length= my_read(file, buff, sizeof(buff), MYF(0))) > 0)
180
for (pos= buff + length ;
181
pos > buff && (iscntrl(pos[-1]) || isspace(pos[-1])) ;
184
/* Ensure that the symlink ends with the directory symbol */
185
if (pos == buff || pos[-1] != FN_LIBCHAR)
188
strncpy(dir,buff, FN_REFLEN-1);
190
my_close(file, MYF(0));
194
#endif /* USE_SYMDIR */
169
198
Fixes a directroy name so that can be used by open()
232
265
if (path[0][0] == FN_LIBCHAR)
233
266
return home_dir; /* ~/ expanded to home */
235
struct passwd *user_entry;
270
struct passwd *user_entry;
237
if (!(str=strchr(*path,FN_LIBCHAR)))
238
str= strchr(*path, '\0');
239
save= *str; *str= '\0';
240
user_entry=getpwnam(*path);
246
return user_entry->pw_dir;
272
if (!(str=strchr(*path,FN_LIBCHAR)))
273
str= strchr(*path, '\0');
274
save= *str; *str= '\0';
275
user_entry=getpwnam(*path);
281
return user_entry->pw_dir;
288
325
/* Used before system command's like open(), create() .. */
289
326
/* Returns used length of to; total length should be FN_REFLEN */
291
static size_t system_filename(char * to, const char *from)
328
size_t system_filename(char * to, const char *from)
330
#ifndef FN_C_BEFORE_DIR
293
331
return strlen(strncpy(to,from,FN_REFLEN-1));
334
/* change 'dev:lib/xxx' to 'dev:[lib]xxx' */
335
/* change 'dev:xxx' to 'dev:xxx' */
336
/* change './xxx' to 'xxx' */
337
/* change './lib/' or lib/ to '[.lib]' */
338
/* change '/x/y/z to '[x.y]x' */
339
/* change 'dev:/x' to 'dev:[000000]x' */
343
char * to_pos,from_pos,pos;
344
char buff[FN_REFLEN];
347
(void) strcpy(buff,from); /* If to == from */
349
if ((pos=strrchr(from_pos,FN_DEVCHAR))) /* Skip device part */
352
to_pos= strncpy(to,from_pos,(size_t) (pos-from_pos));
359
if (from_pos[0] == FN_CURLIB && from_pos[1] == FN_LIBCHAR)
360
from_pos+=2; /* Skip './' */
361
if (strchr(from_pos,FN_LIBCHAR))
363
*(to_pos++) = FN_C_BEFORE_DIR;
364
if (strstr(from_pos,FN_ROOTDIR) == from_pos)
366
from_pos+=strlen(FN_ROOTDIR); /* Actually +1 but... */
367
if (! strchr(from_pos,FN_LIBCHAR))
368
{ /* No dir, use [000000] */
369
to_pos= strcpy(to_pos,FN_C_ROOT_DIR)+strlen(FN_C_ROOT_DIR);
374
*(to_pos++)=FN_C_DIR_SEP; /* '.' gives current dir */
376
while ((pos=strchr(from_pos,FN_LIBCHAR)))
379
*(to_pos++)=FN_C_DIR_SEP; /* Add '.' between dirs */
380
if (strstr(from_pos,FN_PARENTDIR) == from_pos &&
381
from_pos+strlen(FN_PARENTDIR) == pos) {
382
to_pos= strcpy(to_pos,FN_C_PARENT_DIR); /* Found '../' */
383
to_pos+= strlen(FN_C_PARENT_DIR);
387
to_pos= strncpy(to_pos,from_pos,(size_t) (pos-from_pos));
388
to_pos+= strlen(to_pos);
392
*(to_pos++)=FN_C_AFTER_DIR;
395
strcpy(to_pos, from_pos);
294
399
} /* system_filename */