2005-04-08 Jeff Johnston <jjohnstn@redhat.com>

* libc/include/libgen.h: New file.

2005-04-08  Shaun Jackman  <sjackman@gmail.com>

        * libc/unix/Makefile.am: Add support for basename and dirname.
        * libc/unix/Makefile.in: Regenerated.
        * libc/unix/basename.c: New file.
        * libc/unix/dirname.c: New file.
This commit is contained in:
Jeff Johnston 2005-04-08 20:48:40 +00:00
parent c400419414
commit 6e75bff67d
6 changed files with 90 additions and 1 deletions

View File

@ -1,3 +1,14 @@
2005-04-08 Jeff Johnston <jjohnstn@redhat.com>
* libc/include/libgen.h: New file.
2005-04-08 Shaun Jackman <sjackman@gmail.com>
* libc/unix/Makefile.am: Add support for basename and dirname.
* libc/unix/Makefile.in: Regenerated.
* libc/unix/basename.c: New file.
* libc/unix/dirname.c: New file.
2005-04-07 Shaun Jackman <sjackman@gmail.com>
* libc/sys/linux/inode.c (lchown): New function.

View File

@ -0,0 +1,23 @@
/*
* libgen.h - defined by XPG4
*/
#ifndef _LIBGEN_H_
#define _LIBGEN_H_
#include "_ansi.h"
#include <sys/reent.h>
#ifdef __cplusplus
extern "C" {
#endif
char *_EXFUN(basename, (char *));
char *_EXFUN(dirname, (char *));
#ifdef __cplusplus
}
#endif
#endif /* _LIBGEN_H_ */

View File

@ -15,6 +15,8 @@ ELIX_2_OBJS = \
ttyname.$(oext)
ELIX_4_OBJS = \
basename.$(oext) \
dirname.$(oext) \
getlogin.$(oext) \
getpass.$(oext) \
getpwent.$(oext) \

View File

@ -116,7 +116,7 @@ GENERAL_SOURCES = getcwd.c pread.c pwrite.c sigset.c
ELIX_2_OBJS = ttyname.$(oext)
ELIX_4_OBJS = getlogin.$(oext) getpass.$(oext) getpwent.$(oext) getut.$(oext)
ELIX_4_OBJS = basename.$(oext) dirname.$(oext) getlogin.$(oext) getpass.$(oext) getpwent.$(oext) getut.$(oext)
@ELIX_LEVEL_1_TRUE@LIB_OBJS =
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_TRUE@LIB_OBJS = $(ELIX_2_OBJS)

View File

@ -0,0 +1,25 @@
/* Copyright 2005 Shaun Jackman
* Permission to use, copy, modify, and distribute this software
* is freely granted, provided that this notice is preserved.
*/
#include <libgen.h>
#include <string.h>
char*
_DEFUN (basename, (path),
char *path)
{
char *p;
if( path == NULL || *path == '\0' )
return ".";
p = path + strlen(path) - 1;
while( *p == '/' ) {
if( p == path )
return path;
*p-- = '\0';
}
while( p >= path && *p != '/' )
p--;
return p + 1;
}

View File

@ -0,0 +1,28 @@
/* Copyright 2005 Shaun Jackman
* Permission to use, copy, modify, and distribute this software
* is freely granted, provided that this notice is preserved.
*/
#include <libgen.h>
#include <string.h>
char *
_DEFUN (dirname, (path),
char *path)
{
char *p;
if( path == NULL || *path == '\0' )
return ".";
p = path + strlen(path) - 1;
while( *p == '/' ) {
if( p == path )
return path;
*p-- = '\0';
}
while( p >= path && *p != '/' )
p--;
return
p < path ? "." :
p == path ? "/" :
(*p = '\0', path);
}