mirror of
https://github.com/adtools/clib2.git
synced 2025-12-08 14:59:05 +00:00
- basename() is not supposed to modify the string it is passed and should
return a pointer to a string which can be modified. Now it does. Same thing for dirname(). git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@15145 87f5fb63-7c3d-0410-a384-fd976d0f7a62
This commit is contained in:
@ -1,3 +1,8 @@
|
||||
- basename() is not supposed to modify the string it is passed and should
|
||||
return a pointer to a string which can be modified. Now it does. Same
|
||||
thing for dirname().
|
||||
|
||||
|
||||
c.lib 1.201 (21.9.2006)
|
||||
|
||||
- If defined, the local environment variable "DISABLE_COMMANDLINE_WILDCARD_EXPANSION"
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: libgen.h,v 1.6 2006-01-08 12:06:14 obarthel Exp $
|
||||
* $Id: libgen.h,v 1.7 2006-09-25 13:29:47 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@ -53,8 +53,8 @@ extern "C" {
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
char * basename(char *path);
|
||||
char * dirname(char *path);
|
||||
char * basename(const char *path);
|
||||
char * dirname(const char *path);
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: libgen_basename.c,v 1.5 2006-09-22 09:02:51 obarthel Exp $
|
||||
* $Id: libgen_basename.c,v 1.6 2006-09-25 13:29:47 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@ -33,6 +33,14 @@
|
||||
|
||||
#include <string.h>
|
||||
#include <libgen.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
#ifndef _STDLIB_PROTOS_H
|
||||
#include "stdlib_protos.h"
|
||||
#endif /* _STDLIB_PROTOS_H */
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
@ -45,9 +53,12 @@
|
||||
/****************************************************************************/
|
||||
|
||||
char *
|
||||
basename(char *path)
|
||||
basename(const char *path)
|
||||
{
|
||||
char * result;
|
||||
static char new_path[MAXPATHLEN];
|
||||
char * result = NULL;
|
||||
const char * str;
|
||||
size_t len;
|
||||
|
||||
ENTER();
|
||||
|
||||
@ -58,12 +69,11 @@ basename(char *path)
|
||||
|
||||
if(path == NULL || path[0] == '\0')
|
||||
{
|
||||
result = (char *)".";
|
||||
str = ".";
|
||||
len = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
int len,i;
|
||||
|
||||
len = strlen(path);
|
||||
|
||||
while(len > 0 && path[len-1] == '/')
|
||||
@ -71,27 +81,46 @@ basename(char *path)
|
||||
|
||||
if(len > 0)
|
||||
{
|
||||
result = path;
|
||||
size_t i;
|
||||
|
||||
path[len] = '\0';
|
||||
str = path;
|
||||
|
||||
for(i = len-1 ; i >= 0 ; i--)
|
||||
for(i = len - 1 ; ; i--)
|
||||
{
|
||||
if(path[i] == '/')
|
||||
{
|
||||
result = &path[i+1];
|
||||
len -= i;
|
||||
|
||||
str = &path[i+1];
|
||||
break;
|
||||
}
|
||||
|
||||
if(i == 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result = (char *)"/";
|
||||
str = "/";
|
||||
len = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if(len + 1 > sizeof(MAXPATHLEN))
|
||||
{
|
||||
__set_errno(ENAMETOOLONG);
|
||||
goto out;
|
||||
}
|
||||
|
||||
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.5 2006-09-22 09:02:51 obarthel Exp $
|
||||
* $Id: libgen_dirname.c,v 1.6 2006-09-25 13:29:47 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@ -33,6 +33,14 @@
|
||||
|
||||
#include <string.h>
|
||||
#include <libgen.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
#ifndef _STDLIB_PROTOS_H
|
||||
#include "stdlib_protos.h"
|
||||
#endif /* _STDLIB_PROTOS_H */
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
@ -45,9 +53,12 @@
|
||||
/****************************************************************************/
|
||||
|
||||
char *
|
||||
dirname(char *path)
|
||||
dirname(const char *path)
|
||||
{
|
||||
char * result;
|
||||
static char new_path[MAXPATHLEN];
|
||||
char * result = NULL;
|
||||
const char * str;
|
||||
size_t len;
|
||||
|
||||
ENTER();
|
||||
|
||||
@ -58,11 +69,12 @@ dirname(char *path)
|
||||
|
||||
if(path == NULL || path[0] == '\0')
|
||||
{
|
||||
result = (char *)".";
|
||||
str = ".";
|
||||
len = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
int len,i;
|
||||
size_t i;
|
||||
|
||||
len = strlen(path);
|
||||
|
||||
@ -71,28 +83,44 @@ dirname(char *path)
|
||||
|
||||
if(len > 0)
|
||||
{
|
||||
result = (char *)".";
|
||||
str = ".";
|
||||
|
||||
for(i = len-1 ; i >= 0 ; i--)
|
||||
for(i = len-1 ; ; i--)
|
||||
{
|
||||
if(path[i] == '/')
|
||||
{
|
||||
path[i] = '\0';
|
||||
|
||||
result = path;
|
||||
str = path;
|
||||
len = i;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if(i == 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result = (char *)"/";
|
||||
str = "/";
|
||||
len = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if(len + 1 > sizeof(MAXPATHLEN))
|
||||
{
|
||||
__set_errno(ENAMETOOLONG);
|
||||
goto out;
|
||||
}
|
||||
|
||||
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