summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2001-01-06 23:27:53 +0000
committerUlrich Drepper <drepper@redhat.com>2001-01-06 23:27:53 +0000
commitec28fc7c4f3e136a38f361cf7ce2274452f0d849 (patch)
tree1c6a7ba85ddbb9ce7e5f0aed31271a494131e9ad
parentf1813b562b7d4aebfde07f0991126e2de7a55d73 (diff)
downloadglibc-ec28fc7c4f3e136a38f361cf7ce2274452f0d849.tar.gz
(Finding Tokens in a String): Document XPG basename() and dirname(), aswell as GNU basename().
-rw-r--r--iconv/tst-iconv3.c52
-rw-r--r--manual/stdio.texi4
-rw-r--r--manual/string.texi85
-rw-r--r--math/bits/cmathcalls.h7
-rw-r--r--sunrpc/pmap_clnt.c11
-rw-r--r--sysdeps/generic/netinet/if_ether.h8
6 files changed, 152 insertions, 15 deletions
diff --git a/iconv/tst-iconv3.c b/iconv/tst-iconv3.c
new file mode 100644
index 0000000000..60aa5c3ed8
--- /dev/null
+++ b/iconv/tst-iconv3.c
@@ -0,0 +1,52 @@
+/* Contributed by Owen Taylor <otaylor@redhat.com>. */
+
+#include <iconv.h>
+#include <errno.h>
+#include <stdio.h>
+
+#define BUFSIZE 10000
+
+int
+main (int argc, char *argv[])
+{
+ char inbuf[BUFSIZE];
+ wchar_t outbuf[BUFSIZE];
+
+ iconv_t cd;
+ int i;
+ char *inptr;
+ char *outptr;
+ size_t inbytes_left, outbytes_left;
+ int count;
+ int result = 0;
+
+ for (i=0; i < BUFSIZE; i++)
+ inbuf[i] = 'a';
+
+ cd = iconv_open ("UCS-4LE", "UTF-8");
+
+ inbytes_left = BUFSIZE;
+ outbytes_left = BUFSIZE * 4;
+ inptr = inbuf;
+ outptr = (char *) outbuf;
+
+ count = iconv (cd, &inptr, &inbytes_left, &outptr, &outbytes_left);
+
+ if (count < 0)
+ {
+ if (errno == E2BIG)
+ printf ("Received E2BIG\n");
+ else
+ printf ("Received something else\n");
+
+ printf ("inptr change: %td\n", inptr - inbuf);
+ printf ("inlen change: %d\n", BUFSIZE - inbytes_left);
+ printf ("outptr change: %zd\n", outptr - (char *) outbuf);
+ printf ("outlen change: %d\n", BUFSIZE * 4 - outbytes_left);
+ result = 1;
+ }
+ else
+ printf ("Succeeded\n");
+
+ return result;
+}
diff --git a/manual/stdio.texi b/manual/stdio.texi
index 0b030cf2d8..b2f46ba460 100644
--- a/manual/stdio.texi
+++ b/manual/stdio.texi
@@ -592,8 +592,8 @@ the line from the null character inserted as a terminator.
This function is a GNU extension, but it is the recommended way to read
lines from a stream. The alternative standard functions are unreliable.
-If an error occurs or end of file is reached, @code{getline} returns
-@code{-1}.
+If an error occurs or end of file is reached without any bytes read,
+@code{getline} returns @code{-1}.
@end deftypefun
@comment stdio.h
diff --git a/manual/string.texi b/manual/string.texi
index c91fe350da..aa87eecfba 100644
--- a/manual/string.texi
+++ b/manual/string.texi
@@ -1097,11 +1097,11 @@ specifying a null character as the value of the @var{c} argument.
@comment ???
@deftypefun {char *} strchrnul (const char *@var{string}, int @var{c})
@code{strchrnul} is the same as @code{strchr} except that if it does
-not find the character, it returns a pointer to string's terminating
+not find the character, it returns a pointer to string's terminating
null character rather than a null pointer.
@end deftypefun
-One useful, but unusual, use of the @code{strchr}
+One useful, but unusual, use of the @code{strchr}
function is when one wants to have a pointer pointing to the NUL byte
terminating a string. This is often written in this way:
@@ -1421,6 +1421,85 @@ token = strsep (&running, delimiters); /* token => "" */
token = strsep (&running, delimiters); /* token => NULL */
@end smallexample
+@comment string.h
+@comment GNU
+@deftypefun {char *} basename (const char *@var{filename})
+The GNU version of the @code{basename} function returns the last
+component of the path in @var{filename}. This function is the prefered
+usage, since it does not modify the argument, @var{filename}, and
+respects trailing slashes. The prototype for @code{basename} can be
+found in @file{string.h}. Note, this function is overriden by the XPG
+version, if @file{libgen.h} is included.
+
+Example of using GNU @code{basename}:
+
+@smallexample
+#include <string.h>
+
+int
+main (int argc, char *argv[])
+@{
+ char *prog = basename (argv[0]);
+
+ if (argc < 2)
+ @{
+ fprintf (stderr, "Usage %s <arg>\n", prog);
+ exit (1);
+ @}
+
+ @dots{}
+@}
+@end smallexample
+
+@strong{Portability Note:} This function may produce different results
+on different systems.
+
+@end deftypefun
+
+@comment libgen.h
+@comment XPG
+@deftypefun {char *} basename (char *@var{path})
+This is the standard XPG defined @code{basename}. It is similar in
+spirit to the GNU version, but may modify the @var{path} by removing
+trailing '/' characters. If the @var{path} is made up entirely of '/'
+characters, then "/" will be returned. Also, if @var{path} is
+@code{NULL} or an empty string, then "." is returned. The prototype for
+the XPG version can be found in @file{string.h}.
+
+Example of using XPG @code{basename}:
+
+@smallexample
+#include <libgen.h>
+
+int
+main (int argc, char *argv[])
+@{
+ char *prog;
+ char *path = strdupa (argv[0]);
+
+ prog = basename (path);
+
+ if (argc < 2)
+ @{
+ fprintf (stderr, "Usage %s <arg>\n", prog);
+ exit (1);
+ @}
+
+ @dots{}
+
+@}
+@end smallexample
+@end deftypefun
+
+@comment libgen.h
+@comment XPG
+@deftypefun {char *} dirname (char *@var{path})
+The @code{dirname} function is the compliment to the XPG version of
+@code{basename}. It returns the parent directory of the file specified
+by @var{path}. If @var{path} is @code{NULL}, an empty string, or
+contains no '/' characters, then "." is returned. The prototype for this
+function can be found in @file{libgen.h}.
+@end deftypefun
@node strfry
@section strfry
@@ -1436,7 +1515,7 @@ The prototype for this function is in @file{string.h}.
@comment string.h
@comment GNU
-@deftypefun {char *} strfry (char *@var{string})
+@deftypefun {char *} strfry (char *@var{string})
@code{strfry} creates a pseudorandom anagram of a string, replacing the
input with the anagram in place. For each position in the string,
diff --git a/math/bits/cmathcalls.h b/math/bits/cmathcalls.h
index 3a46822cb5..2d186c41e9 100644
--- a/math/bits/cmathcalls.h
+++ b/math/bits/cmathcalls.h
@@ -1,6 +1,6 @@
/* Prototype declarations for complex math functions;
helper file for <complex.h>.
- Copyright (C) 1997, 1998 Free Software Foundation, Inc.
+ Copyright (C) 1997, 1998, 2001 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
@@ -130,8 +130,9 @@ __MATHDECL (_Mdouble_,creal, (_Mdouble_complex_ __z));
/* Now some optimized versions. GCC has handy notations for these
- functions. */
-#if defined __GNUC__ && defined __OPTIMIZE__
+ functions. Recent GCC handles these as builtin functions so does
+ not need inlines. */
+#if defined __GNUC__ && !__GNUC_PREREQ (2, 97) && defined __OPTIMIZE__
/* Imaginary part of Z. */
extern __inline _Mdouble_
diff --git a/sunrpc/pmap_clnt.c b/sunrpc/pmap_clnt.c
index 05cfe2fa52..4db0f023b6 100644
--- a/sunrpc/pmap_clnt.c
+++ b/sunrpc/pmap_clnt.c
@@ -51,7 +51,7 @@
* interface. portmap caches interfaces, and on DHCP clients,
* it could be that only loopback is started at this time.
*/
-static void
+static bool_t
__get_myaddress (struct sockaddr_in *addr)
{
int s;
@@ -89,7 +89,7 @@ __get_myaddress (struct sockaddr_in *addr)
*addr = *((struct sockaddr_in *) &ifr->ifr_addr);
addr->sin_port = htons (PMAPPORT);
__close (s);
- return;
+ return TRUE;
}
ifr++;
}
@@ -99,6 +99,7 @@ __get_myaddress (struct sockaddr_in *addr)
goto again;
}
__close (s);
+ return FALSE;
}
@@ -118,7 +119,8 @@ pmap_set (u_long program, u_long version, int protocol, u_short port)
struct pmap parms;
bool_t rslt;
- __get_myaddress (&myaddress);
+ if (!__get_myaddress (&myaddress))
+ return FALSE;
client = clntudp_bufcreate (&myaddress, PMAPPROG, PMAPVERS,
timeout, &socket, RPCSMALLMSGSIZE, RPCSMALLMSGSIZE);
if (client == (CLIENT *) NULL)
@@ -152,7 +154,8 @@ pmap_unset (u_long program, u_long version)
struct pmap parms;
bool_t rslt;
- __get_myaddress (&myaddress);
+ if (!__get_myaddress (&myaddress))
+ return FALSE;
client = clntudp_bufcreate (&myaddress, PMAPPROG, PMAPVERS,
timeout, &socket, RPCSMALLMSGSIZE, RPCSMALLMSGSIZE);
if (client == (CLIENT *) NULL)
diff --git a/sysdeps/generic/netinet/if_ether.h b/sysdeps/generic/netinet/if_ether.h
index 8e8a1f0661..055395d527 100644
--- a/sysdeps/generic/netinet/if_ether.h
+++ b/sysdeps/generic/netinet/if_ether.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+/* Copyright (C) 1996, 1997, 2001 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
@@ -21,11 +21,13 @@
#define __NETINET_IF_ETHER_H 1
#include <features.h>
+#include <sys/types.h>
+
/* This is a name for the 48 bit ethernet address available on many
systems. */
struct ether_addr
{
- unsigned char ether_addr_octet[6];
-};
+ u_int8_t ether_addr_octet[6];
+} __attribute__ ((__packed__));
#endif /* netinet/if_ether.h */