diff --git a/library/amiga_rexxvars.c b/library/amiga_rexxvars.c index a24b62d..f033cef 100644 --- a/library/amiga_rexxvars.c +++ b/library/amiga_rexxvars.c @@ -1,5 +1,5 @@ /* - * $Id: amiga_rexxvars.c,v 1.9 2006-09-25 15:12:47 obarthel Exp $ + * $Id: amiga_rexxvars.c,v 1.10 2006-09-25 18:19:44 obarthel Exp $ * * :ts=4 * @@ -142,7 +142,7 @@ CheckRexxMsg(struct RexxMsg *message) if(message->rm_TaskBlock == NULL) goto out; - if(NOT IsRexxMsg(message)) + if(NOT IsRexxMsg((struct Message *)message)) goto out; result = TRUE; @@ -165,7 +165,7 @@ GetRexxVar(struct RexxMsg *message,STRPTR variable_name,STRPTR *buffer_pointer) /* The following uses a function which was added to rexxsyslib.library V45. We therefore have a minimum library version requirement. */ - if(RexxSysBase == NULL || RexxSysBase->lib_Version < 45 || NOT IsRexxMsg(message)) + if(RexxSysBase == NULL || RexxSysBase->lib_Version < 45 || NOT IsRexxMsg((struct Message *)message)) { result = ERR10_010; /* invalid message packet */ goto out; @@ -195,7 +195,7 @@ SetRexxVar(struct RexxMsg *message,STRPTR variable_name,STRPTR value,ULONG lengt /* The following uses a function which was added to rexxsyslib.library V45. We therefore have a minimum library version requirement. */ - if(RexxSysBase == NULL || RexxSysBase->lib_Version < 45 || NOT IsRexxMsg(message)) + if(RexxSysBase == NULL || RexxSysBase->lib_Version < 45 || NOT IsRexxMsg((struct Message *)message)) { result = ERR10_010; /* invalid message packet */ goto out; diff --git a/library/changes b/library/changes index c819d34..872e6ea 100644 --- a/library/changes +++ b/library/changes @@ -1,3 +1,8 @@ +- basename() and dirname() can no longer return NULL. They truncate the + resulting path name instead. This is done so because some code that + calls basename() or dirname() does not check if the function's return + value is NULL. + - The SetOwner() fall-back code for Kickstart 2.04 was passing the wrong parameters to the file system. The first (dp_Arg1) should have been zero. Ouch. diff --git a/library/libgen_basename.c b/library/libgen_basename.c index 438f22b..023c2dc 100644 --- a/library/libgen_basename.c +++ b/library/libgen_basename.c @@ -1,5 +1,5 @@ /* - * $Id: libgen_basename.c,v 1.6 2006-09-25 13:29:47 obarthel Exp $ + * $Id: libgen_basename.c,v 1.7 2006-09-25 18:19:44 obarthel Exp $ * * :ts=4 * @@ -34,13 +34,6 @@ #include #include #include -#include - -/****************************************************************************/ - -#ifndef _STDLIB_PROTOS_H -#include "stdlib_protos.h" -#endif /* _STDLIB_PROTOS_H */ /****************************************************************************/ @@ -56,8 +49,8 @@ char * basename(const char *path) { static char new_path[MAXPATHLEN]; - char * result = NULL; const char * str; + char * result; size_t len; ENTER(); @@ -89,7 +82,7 @@ basename(const char *path) { if(path[i] == '/') { - len -= i; + len -= i+1; str = &path[i+1]; break; @@ -99,28 +92,22 @@ basename(const char *path) break; } } - else + + if(len == 0) { str = "/"; len = 1; } } - if(len + 1 > sizeof(MAXPATHLEN)) - { - __set_errno(ENAMETOOLONG); - goto out; - } + if(len >= sizeof(new_path)) + len = sizeof(new_path)-1; memcpy(new_path,str,len); new_path[len] = '\0'; result = new_path; - SHOWSTRING(result); - - out: - RETURN(result); return(result); } diff --git a/library/libgen_dirname.c b/library/libgen_dirname.c index 7f74723..4578ece 100644 --- a/library/libgen_dirname.c +++ b/library/libgen_dirname.c @@ -1,5 +1,5 @@ /* - * $Id: libgen_dirname.c,v 1.6 2006-09-25 13:29:47 obarthel Exp $ + * $Id: libgen_dirname.c,v 1.7 2006-09-25 18:19:44 obarthel Exp $ * * :ts=4 * @@ -34,13 +34,6 @@ #include #include #include -#include - -/****************************************************************************/ - -#ifndef _STDLIB_PROTOS_H -#include "stdlib_protos.h" -#endif /* _STDLIB_PROTOS_H */ /****************************************************************************/ @@ -56,8 +49,8 @@ char * dirname(const char *path) { static char new_path[MAXPATHLEN]; - char * result = NULL; const char * str; + char * result; size_t len; ENTER(); @@ -67,23 +60,19 @@ dirname(const char *path) else SHOWSTRING(path); - if(path == NULL || path[0] == '\0') - { - str = "."; - len = 1; - } - else - { - size_t i; + str = "."; + len = 1; + if(path != NULL && path[0] != '\0') + { len = strlen(path); - while(len > 0 && path[len-1] == '/') + while(len > 1 && path[len-1] == '/') len--; if(len > 0) { - str = "."; + size_t i; for(i = len-1 ; ; i--) { @@ -92,6 +81,9 @@ dirname(const char *path) str = path; len = i; + if(i == 0) + len++; + break; } @@ -99,28 +91,16 @@ dirname(const char *path) break; } } - else - { - str = "/"; - len = 1; - } } - if(len + 1 > sizeof(MAXPATHLEN)) - { - __set_errno(ENAMETOOLONG); - goto out; - } + if(len >= sizeof(new_path)) + len = sizeof(new_path)-1; memcpy(new_path,str,len); new_path[len] = '\0'; result = new_path; - SHOWSTRING(result); - - out: - RETURN(result); return(result); }