mirror of
https://github.com/adtools/clib2.git
synced 2025-12-08 14:59:05 +00:00
- 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. git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@15153 87f5fb63-7c3d-0410-a384-fd976d0f7a62
This commit is contained in:
@ -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;
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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 <string.h>
|
||||
#include <libgen.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
#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);
|
||||
}
|
||||
|
||||
@ -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 <string.h>
|
||||
#include <libgen.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
#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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user