libgen: basename and dirname [PATCH]
Jeff Johnston
jjohnstn@redhat.com
Fri Apr 8 20:53:00 GMT 2005
Checked in with massaging. The declarations of functions and their prototypes
should use the _DEFUN and _EXFUN macros from <_ansi.h>.
I moved the functions to ELIX_LEVEL_4_OBJS. You will see the same thing as you
do now.
I also created a new libgen.h header file from scratch that doesn't have the
Cygwin license..
-- Jeff J.
Shaun Jackman wrote:
> On Apr 8, 2005 10:51 AM, Jeff Johnston <jjohnstn@redhat.com> wrote:
>
>>I realize it is a pain, but it could be a whole lot worse if we forced everyone
>>to sign a permission form like the FSF does.
>>
>>Regards,
>>
>>-- Jeff J.
>
>
> It's not a problem. I understand the purpose of copyrights and
> licenses. Here's the revised patch. I stole libgen.h from
> winsup/cygwin/include/libgen.h..
>
> Cheers,
> Shaun
>
> 2005-04-08 Shaun Jackman <sjackman@gmail.com>
>
> * libc/unix/Makefile.am: Add basename.c and dirname.c to GENERAL_SOURCES.
> * libc/include/libgen.h: New file.
> * libc/unix/basename.c: Ditto.
> * libc/unix/dirname.c: Ditto.
>
> diff -u -r1.4 Makefile.am
> --- libc/unix/Makefile.am 26 Aug 2002 18:56:09 -0000 1.4
> +++ libc/unix/Makefile.am 8 Apr 2005 18:25:57 -0000
> @@ -5,6 +5,8 @@
> INCLUDES = $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS)
>
> GENERAL_SOURCES = \
> + basename.c \
> + dirname.c \
> getcwd.c \
> pread.c \
> pwrite.c \
> diff -u /dev/null libc/include/libgen.h
> --- /dev/null 2005-04-04 21:44:30.000000000 -0700
> +++ libc/include/libgen.h 2005-04-08 10:12:06.000000000 -0700
> @@ -0,0 +1,23 @@
> +/* libgen.h
> +
> + Copyright 2005 Red Hat, Inc.
> +
> +This file is part of Cygwin.
> +
> +This software is a copyrighted work licensed under the terms of the
> +Cygwin license. Please consult the file "CYGWIN_LICENSE" for
> +details. */
> +
> +#ifndef _LIBGEN_H
> +#define _LIBGEN_H
> +
> +#include <sys/cdefs.h>
> +
> +__BEGIN_DECLS
> +
> +extern char *basename (char *path);
> +extern char *dirname (char *path);
> +
> +__END_DECLS
> +
> +#endif /* _LIBGEN_H */
> diff -u /dev/null libc/unix/basename.c
> --- /dev/null 2005-04-04 21:44:30.000000000 -0700
> +++ libc/unix/basename.c 2005-04-08 11:28:08.000000000 -0700
> @@ -0,0 +1,22 @@
> +/* Copyright 2005 Shaun Jackman
> + * Permission to use, copy, modify, and distribute this software
> + * is freely granted, provided that this notice is preserved.
> + */
> +
> +#include <string.h>
> +
> +char* basename(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;
> +}
> diff -u /dev/null libc/unix/dirname.c
> --- /dev/null 2005-04-04 21:44:30.000000000 -0700
> +++ libc/unix/dirname.c 2005-04-08 11:28:11.000000000 -0700
> @@ -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 <string.h>
> +
> +char* dirname(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);
> +}
More information about the Newlib
mailing list