aboutsummaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
Diffstat (limited to 'misc')
-rw-r--r--misc/Makefile5
-rw-r--r--misc/dirname.c52
-rw-r--r--misc/hsearch.c30
-rw-r--r--misc/hsearch_r.c30
-rw-r--r--misc/insremque.c51
-rw-r--r--misc/libgen.h30
-rw-r--r--misc/search.h36
-rw-r--r--misc/sys/select.h34
-rw-r--r--misc/sys/uio.h35
-rw-r--r--misc/tst-dirname.c59
10 files changed, 252 insertions, 110 deletions
diff --git a/misc/Makefile b/misc/Makefile
index 43b6bbda43..46b078c081 100644
--- a/misc/Makefile
+++ b/misc/Makefile
@@ -24,7 +24,7 @@ subdir := misc
headers := sys/uio.h iovec.h sys/ioctl.h ioctls.h ioctl-types.h \
sys/ptrace.h sys/file.h sys/dir.h sys/cdefs.h \
- ar.h a.out.h stab.h stab.def sgtty.h \
+ ar.h a.out.h libgen.h stab.h stab.def sgtty.h \
ttyent.h syslog.h sys/syslog.h paths.h sys/reboot.h \
sys/mman.h sys/param.h fstab.h mntent.h search.h err.h error.h\
sys/queue.h sysexits.h syscall.h sys/syscall.h sys/swap.h \
@@ -55,7 +55,7 @@ routines := brk sbrk sstk ioctl \
efgcvt efgcvt_r qefgcvt qefgcvt_r \
hsearch hsearch_r tsearch lsearch \
err error ustat \
- getsysstats
+ getsysstats dirname
aux := init-misc
distribute := bsd-compat.c
extra-objs := bsd-compat.o
@@ -63,6 +63,7 @@ install-lib := libbsd-compat.a libg.a
non-lib.a := libbsd-compat.a
gpl2lgpl := error.c error.h
+tests := tst-dirname
include ../Rules
diff --git a/misc/dirname.c b/misc/dirname.c
new file mode 100644
index 0000000000..26c5a8b1ee
--- /dev/null
+++ b/misc/dirname.c
@@ -0,0 +1,52 @@
+/* dirname - return directory part of PATH.
+ Copyright (C) 1996 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 Library General Public License as
+ published by the Free Software Foundation; either version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#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 == path)
+ /* The last slash is the first character in the string. We have to
+ return "/". */
+ ++last_slash;
+ else if (last_slash != NULL && last_slash[1] == '\0')
+ /* The '/' is the last character, we have to look further. */
+ last_slash = memchr (path, last_slash - path, '/');
+
+ if (last_slash != NULL)
+ /* Terminate the path. */
+ 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;
+}
diff --git a/misc/hsearch.c b/misc/hsearch.c
index e0b2e3e0ff..f2739b8801 100644
--- a/misc/hsearch.c
+++ b/misc/hsearch.c
@@ -1,21 +1,21 @@
/* Copyright (C) 1993, 1995, 1996 Free Software Foundation, Inc.
-Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>
-This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>
+ This file is part of the GNU C Library.
-The GNU C Library is free software; you can redistribute it and/or
-modify it under the terms of the GNU Library General Public License as
-published by the Free Software Foundation; either version 2 of the
-License, or (at your option) any later version.
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 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
-Library General Public License for more details.
+ 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
+ Library General Public License for more details.
-You should have received a copy of the GNU Library General Public
-License along with the GNU C Library; see the file COPYING.LIB. If
-not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA. */
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
#include <search.h>
@@ -39,7 +39,7 @@ hsearch (item, action)
int
hcreate (nel)
- unsigned int nel;
+ size_t nel;
{
return hcreate_r (nel, &htab);
}
diff --git a/misc/hsearch_r.c b/misc/hsearch_r.c
index d0fb3e183f..bf7cadc536 100644
--- a/misc/hsearch_r.c
+++ b/misc/hsearch_r.c
@@ -1,21 +1,21 @@
/* Copyright (C) 1993, 1995, 1996 Free Software Foundation, Inc.
-Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>
-This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>
+ This file is part of the GNU C Library.
-The GNU C Library is free software; you can redistribute it and/or
-modify it under the terms of the GNU Library General Public License as
-published by the Free Software Foundation; either version 2 of the
-License, or (at your option) any later version.
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 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
-Library General Public License for more details.
+ 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
+ Library General Public License for more details.
-You should have received a copy of the GNU Library General Public
-License along with the GNU C Library; see the file COPYING.LIB. If
-not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA. */
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
#include <errno.h>
#include <malloc.h>
@@ -64,7 +64,7 @@ isprime (unsigned int number)
becomes zero. */
int
hcreate_r (nel, htab)
- unsigned int nel;
+ size_t nel;
struct hsearch_data *htab;
{
/* Test for correct arguments. */
diff --git a/misc/insremque.c b/misc/insremque.c
index 2658397294..d71ed04265 100644
--- a/misc/insremque.c
+++ b/misc/insremque.c
@@ -1,49 +1,46 @@
-/* Copyright (C) 1992, 1995 Free Software Foundation, Inc.
-This file is part of the GNU C Library.
+/* Copyright (C) 1992, 1995, 1996 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
-The GNU C Library is free software; you can redistribute it and/or
-modify it under the terms of the GNU Library General Public License as
-published by the Free Software Foundation; either version 2 of the
-License, or (at your option) any later version.
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 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
-Library General Public License for more details.
+ 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
+ Library General Public License for more details.
-You should have received a copy of the GNU Library General Public
-License along with the GNU C Library; see the file COPYING.LIB. If
-not, write to the Free Software Foundation, Inc., 675 Mass Ave,
-Cambridge, MA 02139, USA. */
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
-#include <ansidecl.h>
#include <stddef.h>
#include <search.h>
/* Insert ELEM into a doubly-linked list, after PREV. */
void
-DEFUN(insque, (elem, prev) ,
- struct qelem *elem AND struct qelem *prev)
+insque (void *elem, void *prev)
{
- struct qelem *next = prev->q_forw;
- prev->q_forw = elem;
+ struct qelem *next = ((struct qelem *) prev)->q_forw;
+ ((struct qelem *) prev)->q_forw = (struct qelem *) elem;
if (next != NULL)
- next->q_back = elem;
- elem->q_forw = next;
- elem->q_back = prev;
+ next->q_back = (struct qelem *) elem;
+ ((struct qelem *) elem)->q_forw = next;
+ ((struct qelem *) elem)->q_back = (struct qelem *) prev;
}
/* Unlink ELEM from the doubly-linked list that it is in. */
void
-DEFUN(remque, (elem),
- struct qelem *elem)
+remque (void *elem)
{
- struct qelem *next = elem->q_forw;
- struct qelem *prev = elem->q_back;
+ struct qelem *next = ((struct qelem *) elem)->q_forw;
+ struct qelem *prev = ((struct qelem *) elem)->q_back;
if (next != NULL)
next->q_back = prev;
if (prev != NULL)
- prev->q_forw = next;
+ prev->q_forw = (struct qelem *) next;
}
diff --git a/misc/libgen.h b/misc/libgen.h
new file mode 100644
index 0000000000..be8258e72a
--- /dev/null
+++ b/misc/libgen.h
@@ -0,0 +1,30 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifndef _LIBGEN_H
+
+#define _LIBGEN_H 1
+#include <sys/cdefs.h>
+
+/* Return directory part of PATH or "." if none is available. */
+extern char *dirname __P ((char *__path));
+
+/* Return filename part of PATH. */
+extern char *basename __P ((__const char *__path));
+
+#endif /* libgen.h */
diff --git a/misc/search.h b/misc/search.h
index 158332cd61..2103d66cbe 100644
--- a/misc/search.h
+++ b/misc/search.h
@@ -1,21 +1,21 @@
/* search.h -- declarations for System V style searching functions.
-Copyright (C) 1995, 1996 Free Software Foundation, Inc.
-This file is part of the GNU C Library.
+ Copyright (C) 1995, 1996 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
-The GNU C Library is free software; you can redistribute it and/or
-modify it under the terms of the GNU Library General Public License as
-published by the Free Software Foundation; either version 2 of the
-License, or (at your option) any later version.
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 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
-Library General Public License for more details.
+ 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
+ Library General Public License for more details.
-You should have received a copy of the GNU Library General Public
-License along with the GNU C Library; see the file COPYING.LIB. If
-not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA. */
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
#ifndef _SEARCH_H
#define _SEARCH_H 1
@@ -28,6 +28,7 @@ Boston, MA 02111-1307, USA. */
__BEGIN_DECLS
+#if defined(__USE_SVID) || defined(__USE_XOPEN_EXTENDED)
/* Prototype structure for a linked-list data structure.
This is the type used by the `insque' and `remque' functions. */
@@ -40,10 +41,11 @@ struct qelem
/* Insert ELEM into a doubly-linked list, after PREV. */
-extern void insque __P ((struct qelem *__elem, struct qelem *__prev));
+extern void insque __P ((void *__elem, void *__prev));
/* Unlink ELEM from the doubly-linked list that it is in. */
-extern void remque __P ((struct qelem *__elem));
+extern void remque __P ((void *__elem));
+#endif
/* For use with hsearch(3). */
@@ -81,7 +83,7 @@ struct hsearch_data
/* Family of hash table handling functions. The functions also have
reentrant counterparts ending with _r. */
extern ENTRY *hsearch __P ((ENTRY __item, ACTION __action));
-extern int hcreate __P ((unsigned int __nel));
+extern int hcreate __P ((size_t __nel));
extern void hdestroy __P ((void));
extern int hsearch_r __P ((ENTRY __item, ACTION __action, ENTRY **__retval,
diff --git a/misc/sys/select.h b/misc/sys/select.h
index 42c3e3e363..6a7e0213fb 100644
--- a/misc/sys/select.h
+++ b/misc/sys/select.h
@@ -1,21 +1,21 @@
/* `fd_set' type and related macros, and `select'/`pselect' declarations.
-Copyright (C) 1996 Free Software Foundation, Inc.
-This file is part of the GNU C Library.
-
-The GNU C Library is free software; you can redistribute it and/or
-modify it under the terms of the GNU Library General Public License as
-published by the Free Software Foundation; either version 2 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
-Library General Public License for more details.
-
-You should have received a copy of the GNU Library General Public
-License along with the GNU C Library; see the file COPYING.LIB. If
-not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA. */
+ Copyright (C) 1996 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
/* POSIX 1003.1g: 6.2 Select from File Descriptor Sets <sys/select.h> */
diff --git a/misc/sys/uio.h b/misc/sys/uio.h
index 8a577bdb75..0127efba14 100644
--- a/misc/sys/uio.h
+++ b/misc/sys/uio.h
@@ -1,20 +1,20 @@
/* Copyright (C) 1991, 1992, 1996 Free Software Foundation, Inc.
-This file is part of the GNU C Library.
+ This file is part of the GNU C Library.
-The GNU C Library is free software; you can redistribute it and/or
-modify it under the terms of the GNU Library General Public License as
-published by the Free Software Foundation; either version 2 of the
-License, or (at your option) any later version.
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 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
-Library General Public License for more details.
+ 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
+ Library General Public License for more details.
-You should have received a copy of the GNU Library General Public
-License along with the GNU C Library; see the file COPYING.LIB. If
-not, write to the Free Software Foundation, Inc., 675 Mass Ave,
-Cambridge, MA 02139, USA. */
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
#ifndef _SYS_UIO_H
@@ -23,8 +23,7 @@ Cambridge, MA 02139, USA. */
__BEGIN_DECLS
-#define __need_size_t
-#include <stddef.h>
+#include <sys/types.h>
/* This file defines `struct iovec'. */
#include <iovec.h>
@@ -35,14 +34,16 @@ __BEGIN_DECLS
The buffers are filled in the order specified.
Operates just like `read' (see <unistd.h>) except that data are
put in VECTOR instead of a contiguous buffer. */
-int readv __P ((int __fd, __const struct iovec * __vector, size_t __count));
+extern ssize_t readv __P ((int __fd, __const struct iovec * __vector,
+ int __count));
/* Write data pointed by the buffers described by VECTOR, which
is a vector of COUNT `struct iovec's, to file descriptor FD.
The data is written in the order specified.
Operates just like `write' (see <unistd.h>) except that the data
are taken from VECTOR instead of a contiguous buffer. */
-int writev __P ((int __fd, __const struct iovec * __vector, size_t __count));
+extern ssize_t writev __P ((int __fd, __const struct iovec * __vector,
+ int __count));
__END_DECLS
diff --git a/misc/tst-dirname.c b/misc/tst-dirname.c
new file mode 100644
index 0000000000..78eb1b5db0
--- /dev/null
+++ b/misc/tst-dirname.c
@@ -0,0 +1,59 @@
+/* Test program for dirname function a la XPG.
+ Copyright (C) 1996 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 Library General Public License as
+ published by the Free Software Foundation; either version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#define _GNU_SOURCE 1
+#include <libgen.h>
+#include <stdio.h>
+#include <string.h>
+
+
+extern int test __P ((const char *input, const char *result));
+
+int
+test (input, result)
+ const char *input;
+ const char *result;
+{
+ int retval;
+ char *cp;
+ cp = strdupa (input);
+ cp = dirname (cp);
+ retval = strcmp (cp, result);
+ if (retval)
+ printf ("dirname(\"%s\") should be \"%s\", but is \"%s\"\n",
+ input, result, cp);
+ return retval;
+}
+
+int
+main ()
+{
+ int result = 0;
+
+ /* These are the examples given in XPG4.2. */
+ result |= test ("/usr/lib", "/usr");
+ result |= test ("/usr", "/");
+ result |= test ("usr", ".");
+ result |= test ("/", "/");
+ result |= test (".", ".");
+ result |= test ("..", ".");
+
+ return result != 0;
+}