1
/* Copyright (C) 2000 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
/* my_setwd() and my_getwd() works with intern_filenames !! */
18
#include "mysys_priv.h"
19
#include <mystrings/m_string.h>
20
#include "mysys_err.h"
21
#include "my_static.h"
23
#include <sys/param.h>
26
/* Gets current working directory in buff.
30
buf Buffer to store result. Can be curr_dir[].
35
Directory is allways ended with FN_LIBCHAR
42
int my_getwd(char * buf, size_t size, myf MyFlags)
46
if (curr_dir[0]) /* Current pos is saved here */
47
VOID(strmake(buf,&curr_dir[0],size-1));
50
#if defined(HAVE_GETCWD)
51
if (!getcwd(buf,size-2) && MyFlags & MY_WME)
54
my_error(EE_GETWD,MYF(ME_BELL+ME_WAITTANG),errno);
57
#elif defined(HAVE_GETWD)
59
char pathname[MAXPATHLEN];
61
strmake(buf,pathname,size-1);
64
if (!getcwd(buf,size-2,1) && MyFlags & MY_WME)
67
my_error(EE_GETWD,MYF(ME_BELL+ME_WAITTANG),errno);
70
intern_filename(buf,buf);
72
#error "No way to get current directory"
74
if (*((pos=strend(buf))-1) != FN_LIBCHAR) /* End with FN_LIBCHAR */
79
(void) strmake(&curr_dir[0],buf, (size_t) (FN_REFLEN-1));
85
/* Set new working directory */
87
int my_setwd(const char *dir, myf MyFlags)
97
if (! dir[0] || (dir[0] == FN_LIBCHAR && dir[1] == 0))
101
pos=strmov(buff,dir);
102
if (pos[-1] != FN_LIBCHAR)
104
pos[0]=FN_LIBCHAR; /* Mark as directory */
107
system_filename(buff,buff); /* Change to VMS format */
111
if ((res=chdir((char*) dir)) != 0)
114
if (MyFlags & MY_WME)
115
my_error(EE_SETWD,MYF(ME_BELL+ME_WAITTANG),start,errno);
119
if (test_if_hard_path(start))
120
{ /* Hard pathname */
121
pos= strmake(&curr_dir[0],start,(size_t) FN_REFLEN-1);
122
if (pos[-1] != FN_LIBCHAR)
124
length=(uint) (pos-(char*) curr_dir);
125
curr_dir[length]=FN_LIBCHAR; /* must end with '/' */
126
curr_dir[length+1]='\0';
130
curr_dir[0]='\0'; /* Don't save name */
137
/* Test if hard pathname */
138
/* Returns 1 if dirname is a hard path */
140
int test_if_hard_path(register const char *dir_name)
142
if (dir_name[0] == FN_HOMELIB && dir_name[1] == FN_LIBCHAR)
143
return (home_dir != NullS && test_if_hard_path(home_dir));
144
if (dir_name[0] == FN_LIBCHAR)
147
return (strchr(dir_name,FN_DEVCHAR) != 0);
151
} /* test_if_hard_path */
155
Test if a name contains an (absolute or relative) path.
159
name The name to test.
162
true name contains a path.
163
false name does not contain a path.
166
bool has_path(const char *name)
168
return test(strchr(name, FN_LIBCHAR))
169
#if FN_LIBCHAR != '/'
170
|| test(strchr(name,'/'))
173
|| test(strchr(name, FN_DEVCHAR))