- Added missing basename.c;
- Added original dirname.c;
- Added getcwd (extension of POSIX.1 standard, as in the original NewLib).

git-svn-id: svn://kolibrios.org@9989 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
turbocat 2024-03-07 20:39:33 +00:00
parent 64d4ca96c4
commit aae3ae86cc
7 changed files with 134 additions and 93 deletions

View File

@ -117,7 +117,6 @@ CORE_SRCS:= \
sys/close.c \
sys/conio.c \
sys/chdir.c \
sys/getcwd.c \
sys/errno.c \
sys/fstat.c \
sys/gettod.c \
@ -326,8 +325,7 @@ STRING_SRCS= \
wmemcmp.c \
wmemcpy.c \
wmemmove.c \
wmemset.c \
dirname.c
wmemset.c
STDIO_SRCS= \
@ -517,6 +515,10 @@ POSIX_SRCS = opendir.c \
telldir.c \
rewinddir.c
UNIX_SRCS = basename.c \
dirname.c \
getcwd.c
STATIC_OBJS = $(patsubst %.S, %.o, $(patsubst %.c, %.o, $(STATIC_SRCS)))
LIBCRT_OBJS = $(patsubst %.S, %.o, $(patsubst %.c, %.o, $(LIBCRT_SRCS)))
@ -542,6 +544,8 @@ MATH_OBJS = $(patsubst %.S, math/%.o, $(patsubst %.asm, math/%.o,\
POSIX_OBJS = $(patsubst %.c, posix/%.o, $(POSIX_SRCS))
UNIX_OBJS = $(patsubst %.c, unix/%.o, $(UNIX_SRCS))
PRINTF_OBJS= stdio/vfprintf.o \
stdio/vfiprintf.o \
stdio/svfprintf.o \
@ -574,7 +578,8 @@ LIB_SRCS+= \
$(STDIO_SRCS) \
$(STRING_SRCS) \
$(STDLIB_SRCS) \
$(POSIX_SRCS)
$(POSIX_SRCS) \
$(UNIX_SRCS)
LIB_OBJS+= \
$(CORE_OBJS) \
@ -583,7 +588,8 @@ LIB_OBJS+= \
$(STDIO_OBJS) \
$(PRINTF_OBJS) \
$(MATH_OBJS) \
$(POSIX_OBJS)
$(POSIX_OBJS) \
$(UNIX_OBJS)
LIB_OBJS+= time/wcsftime.o

View File

@ -100,7 +100,6 @@ CORE_SRCS = {
"sys/close.c",
"sys/conio.c",
"sys/chdir.c",
"sys/getcwd.c",
"sys/errno.c",
"sys/fstat.c",
"sys/gettod.c",
@ -307,8 +306,7 @@ STRING_SRCS = {
"wmemcmp.c",
"wmemcpy.c",
"wmemmove.c",
"wmemset.c",
"dirname.c"
"wmemset.c"
}
STDIO_SRCS = {
@ -455,6 +453,7 @@ STDIO_SRCS = {
"wscanf.c",
"wsetup.c"
}
POSIX_SRCS = {
"opendir.c",
"closedir.c",
@ -464,6 +463,12 @@ POSIX_SRCS = {
"rewinddir.c"
}
UNIX_SRCS = {
"getcwd.c",
"dirname.c",
"basename.c"
}
MATH_SRCS = {
"e_acos.c", "e_acosh.c", "e_asin.c", "e_atan2.c", "e_atanh.c", "e_cosh.c", "e_exp.c", "e_fmod.c",
"e_hypot.c", "e_j0.c", "e_j1.c", "e_jn.c", "e_log.c", "e_log10.c", "e_pow.c", "e_rem_pio2.c",
@ -516,6 +521,7 @@ LIB_SRCS += prepend("stdio/", STDIO_SRCS)
LIB_SRCS += prepend("string/", STRING_SRCS)
LIB_SRCS += prepend("stdlib/", STDLIB_SRCS)
LIB_SRCS += prepend("posix/", POSIX_SRCS)
LIB_SRCS += prepend("unix/", UNIX_SRCS)
LIB_SRCS += prepend("math/", MATH_SRCS)
ALL_OBJS = {}

View File

@ -1,67 +0,0 @@
/* dirname - return directory part of PATH.
Copyright (C) 1996-2019 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#include <libgen.h>
#include <string.h>
char *
dirname (char *path)
{
static const char dot[] = ".";
char *last_slash;
/* Find last '/'. */
last_slash = path != NULL ? strrchr (path, '/') : NULL;
if (last_slash != NULL && last_slash != path && last_slash[1] == '\0')
{
/* Determine whether all remaining characters are slashes. */
char *runp;
for (runp = last_slash; runp != path; --runp)
if (runp[-1] != '/')
break;
/* The '/' is the last character, we have to look further. */
if (runp != path)
last_slash = memrchr (path, '/', runp - path);
}
if (last_slash != NULL)
{
/* Determine whether all remaining characters are slashes. */
char *runp;
for (runp = last_slash; runp != path; --runp)
if (runp[-1] != '/')
break;
/* Terminate the path. */
if (runp == path)
{
/* The last slash is the first character in the string. We have to
return "/". As a special case we have to return "//" if there
are exactly two slashes at the beginning of the string. See
XBD 4.10 Path Name Resolution for more information. */
if (last_slash == path + 1)
++last_slash;
else
last_slash = path + 1;
}
else
last_slash = runp;
last_slash[0] = '\0';
}
else
/* This assignment is ill-designed but the XPG specs require to
return a string containing "." in any case no directory part is
found and so a static and constant string is required. */
path = (char *) dot;
return path;
}

View File

@ -1,17 +0,0 @@
/*
* Copyright (C) KolibriOS team 2004-2024. All rights reserved.
* Distributed under terms of the GNU General Public License
*/
#include <stdlib.h>
#include <sys/ksys.h>
char *getcwd(char *buf, unsigned size){
if(!buf){
if((buf = malloc(size))==NULL){
return NULL;
}
}
_ksys_getcwd(buf, size);
return(buf);
}

View File

@ -0,0 +1,28 @@
#ifndef _NO_BASENAME
/* 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;
}
#endif /* !_NO_BASENAME */

View File

@ -0,0 +1,32 @@
#ifndef _NO_DIRNAME
/* 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);
}
#endif /* !_NO_DIRNAME */

View File

@ -0,0 +1,53 @@
#ifndef _NO_GETCWD
/*
* Copyright (C) KolibriOS team 2024. All rights reserved.
* Distributed under terms of the GNU General Public License
*/
#include <stdlib.h>
#include <limits.h>
#include <sys/errno.h>
#include <sys/unistd.h>
#include <sys/ksys.h>
#ifndef _REENT_ONLY
char *
_DEFUN (getcwd, (buf, size),
char *buf _AND
size_t size)
{
if (buf != NULL && size == 0)
{
errno = EINVAL;
return NULL;
}
if (buf == NULL)
{
if (size == 0)
size = PATH_MAX;
buf = malloc(size);
if (buf == NULL)
{
errno = ENOMEM;
return NULL;
}
}
_ksys_getcwd(buf, size);
if (access(buf, R_OK) == -1)
{
errno = EACCES;
return NULL;
}
return buf;
}
#endif /* _REENT_ONLY */
#endif /* !_NO_GETCWD */