mirror of
https://github.com/adtools/clib2.git
synced 2025-12-08 14:59:05 +00:00
- Added some documenting comments to the source code.
git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@15157 87f5fb63-7c3d-0410-a384-fd976d0f7a62
This commit is contained in:
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: libgen_basename.c,v 1.7 2006-09-25 18:19:44 obarthel Exp $
|
* $Id: libgen_basename.c,v 1.8 2006-10-02 07:15:37 obarthel Exp $
|
||||||
*
|
*
|
||||||
* :ts=4
|
* :ts=4
|
||||||
*
|
*
|
||||||
@ -60,6 +60,7 @@ basename(const char *path)
|
|||||||
else
|
else
|
||||||
SHOWSTRING(path);
|
SHOWSTRING(path);
|
||||||
|
|
||||||
|
/* An empty path always comes out as the "current directory". */
|
||||||
if(path == NULL || path[0] == '\0')
|
if(path == NULL || path[0] == '\0')
|
||||||
{
|
{
|
||||||
str = ".";
|
str = ".";
|
||||||
@ -67,15 +68,18 @@ basename(const char *path)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
/* Strip all trailing slashes. */
|
||||||
len = strlen(path);
|
len = strlen(path);
|
||||||
|
|
||||||
while(len > 0 && path[len-1] == '/')
|
while(len > 0 && path[len-1] == '/')
|
||||||
len--;
|
len--;
|
||||||
|
|
||||||
|
/* Is there anything left? */
|
||||||
if(len > 0)
|
if(len > 0)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
|
/* Return what follows the last slash in the path. That's
|
||||||
|
usually a file or directory name. */
|
||||||
str = path;
|
str = path;
|
||||||
|
|
||||||
for(i = len - 1 ; ; i--)
|
for(i = len - 1 ; ; i--)
|
||||||
@ -93,6 +97,9 @@ basename(const char *path)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* If the whole operation produced an empty string, then it
|
||||||
|
means that we dealt with a string which consisted entirely
|
||||||
|
of slashes. And that's what we will return. */
|
||||||
if(len == 0)
|
if(len == 0)
|
||||||
{
|
{
|
||||||
str = "/";
|
str = "/";
|
||||||
@ -100,6 +107,9 @@ basename(const char *path)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Truncate the path name we can return. This function always returns
|
||||||
|
a valid pointer rather than NULL because some software expects it
|
||||||
|
to do so (I blame the specifications). */
|
||||||
if(len >= sizeof(new_path))
|
if(len >= sizeof(new_path))
|
||||||
len = sizeof(new_path)-1;
|
len = sizeof(new_path)-1;
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: libgen_dirname.c,v 1.7 2006-09-25 18:19:44 obarthel Exp $
|
* $Id: libgen_dirname.c,v 1.8 2006-10-02 07:15:37 obarthel Exp $
|
||||||
*
|
*
|
||||||
* :ts=4
|
* :ts=4
|
||||||
*
|
*
|
||||||
@ -60,16 +60,18 @@ dirname(const char *path)
|
|||||||
else
|
else
|
||||||
SHOWSTRING(path);
|
SHOWSTRING(path);
|
||||||
|
|
||||||
|
/* An empty path always comes out as the "current directory". */
|
||||||
str = ".";
|
str = ".";
|
||||||
len = 1;
|
len = 1;
|
||||||
|
|
||||||
if(path != NULL && path[0] != '\0')
|
if(path != NULL && path[0] != '\0')
|
||||||
{
|
{
|
||||||
|
/* Strip all trailing slashes. */
|
||||||
len = strlen(path);
|
len = strlen(path);
|
||||||
|
|
||||||
while(len > 1 && path[len-1] == '/')
|
while(len > 1 && path[len-1] == '/')
|
||||||
len--;
|
len--;
|
||||||
|
|
||||||
|
/* Is there anything left? */
|
||||||
if(len > 0)
|
if(len > 0)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
@ -78,9 +80,15 @@ dirname(const char *path)
|
|||||||
{
|
{
|
||||||
if(path[i] == '/')
|
if(path[i] == '/')
|
||||||
{
|
{
|
||||||
|
/* Return everything up to, but not including
|
||||||
|
the last slash in the path. That's usually
|
||||||
|
the directory name. */
|
||||||
str = path;
|
str = path;
|
||||||
len = i;
|
len = i;
|
||||||
|
|
||||||
|
/* If that produces an empty string, it means
|
||||||
|
that the entire string consists of slash
|
||||||
|
characters. We'll return only the first. */
|
||||||
if(i == 0)
|
if(i == 0)
|
||||||
len++;
|
len++;
|
||||||
|
|
||||||
@ -93,6 +101,9 @@ dirname(const char *path)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Truncate the path name we can return. This function always returns
|
||||||
|
a valid pointer rather than NULL because some software expects it
|
||||||
|
to do so (I blame the specifications). */
|
||||||
if(len >= sizeof(new_path))
|
if(len >= sizeof(new_path))
|
||||||
len = sizeof(new_path)-1;
|
len = sizeof(new_path)-1;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user