diff options
Diffstat (limited to 'mysys/my_getwd.c')
-rw-r--r-- | mysys/my_getwd.c | 87 |
1 files changed, 27 insertions, 60 deletions
diff --git a/mysys/my_getwd.c b/mysys/my_getwd.c index 3870a5d61b0..e0c5b94b53e 100644 --- a/mysys/my_getwd.c +++ b/mysys/my_getwd.c @@ -21,39 +21,41 @@ #ifdef HAVE_GETWD #include <sys/param.h> #endif -#if defined(MSDOS) || defined(__WIN__) +#if defined(__WIN__) #include <m_ctype.h> #include <dos.h> #include <direct.h> #endif -#if defined(OS2) -#include <direct.h> -#endif -#ifdef __EMX__ -/* chdir2 support also drive change */ -#define chdir _chdir2 -#endif +/* Gets current working directory in buff. - /* Gets current working directory in buff. Directory is allways ended - with FN_LIBCHAR */ - /* One must pass a buffer to my_getwd. One can allways use - curr_dir[] */ + SYNPOSIS + my_getwd() + buf Buffer to store result. Can be curr_dir[]. + size Size of buffer + MyFlags Flags + + NOTES + Directory is allways ended with FN_LIBCHAR + + RESULT + 0 ok + # error +*/ -int my_getwd(my_string buf, uint size, myf MyFlags) +int my_getwd(char * buf, size_t size, myf MyFlags) { - my_string pos; + char * pos; DBUG_ENTER("my_getwd"); - DBUG_PRINT("my",("buf: 0x%lx size: %d MyFlags %d", (long) buf,size,MyFlags)); + DBUG_PRINT("my",("buf: 0x%lx size: %u MyFlags %d", + (long) buf, (uint) size, MyFlags)); -#if ! defined(MSDOS) if (curr_dir[0]) /* Current pos is saved here */ VOID(strmake(buf,&curr_dir[0],size-1)); else -#endif { #if defined(HAVE_GETCWD) - if (!getcwd(buf,size-2) && MyFlags & MY_WME) + if (!getcwd(buf,(uint) (size-2)) && MyFlags & MY_WME) { my_errno=errno; my_error(EE_GETWD,MYF(ME_BELL+ME_WAITTANG),errno); @@ -81,61 +83,26 @@ int my_getwd(my_string buf, uint size, myf MyFlags) pos[0]= FN_LIBCHAR; pos[1]=0; } - (void) strmake(&curr_dir[0],buf,(size_s) (FN_REFLEN-1)); + (void) strmake(&curr_dir[0],buf, (size_t) (FN_REFLEN-1)); } DBUG_RETURN(0); } /* my_getwd */ - /* Set new working directory */ +/* Set new working directory */ int my_setwd(const char *dir, myf MyFlags) { int res; - size_s length; - my_string start,pos; -#if defined(VMS) || defined(MSDOS) || defined(OS2) + size_t length; + char *start, *pos; +#if defined(VMS) char buff[FN_REFLEN]; #endif DBUG_ENTER("my_setwd"); DBUG_PRINT("my",("dir: '%s' MyFlags %d", dir, MyFlags)); - start=(my_string) dir; -#if defined(MSDOS) || defined(OS2) /* OS2/MSDOS chdir can't change drive */ -#if !defined(_DDL) && !defined(WIN32) - if ((pos=(char*) strchr(dir,FN_DEVCHAR)) != 0) - { - uint drive,drives; - - pos++; /* Skip FN_DEVCHAR */ - drive=(uint) (my_toupper(&my_charset_latin1,dir[0])-'A'+1); - drives= (uint) -1; - if ((pos-(byte*) dir) == 2 && drive > 0 && drive < 32) - { -#ifdef OS2 - _chdrive(drive); - drives = _getdrive(); -#else - _dos_setdrive(drive,&drives); - _dos_getdrive(&drives); -#endif - } - if (drive != drives) - { - *pos='\0'; /* Dir is now only drive */ - my_errno=errno; - my_error(EE_SETWD,MYF(ME_BELL+ME_WAITTANG),dir,ENOENT); - DBUG_RETURN(-1); - } - dir=pos; /* drive changed, change now path */ - } -#endif - if (*((pos=strend(dir)-1)) == FN_LIBCHAR && pos != dir) - { - strmov(buff,dir)[-1]=0; /* Remove last '/' */ - dir=buff; - } -#endif /* MSDOS*/ + start=(char *) dir; if (! dir[0] || (dir[0] == FN_LIBCHAR && dir[1] == 0)) dir=FN_ROOTDIR; #ifdef VMS @@ -160,7 +127,7 @@ int my_setwd(const char *dir, myf MyFlags) { if (test_if_hard_path(start)) { /* Hard pathname */ - pos=strmake(&curr_dir[0],start,(size_s) FN_REFLEN-1); + pos= strmake(&curr_dir[0],start,(size_t) FN_REFLEN-1); if (pos[-1] != FN_LIBCHAR) { length=(uint) (pos-(char*) curr_dir); |