--- /dev/null
+/* 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;
+}
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
@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:
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
@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,
/* 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
/* 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_
* 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;
*addr = *((struct sockaddr_in *) &ifr->ifr_addr);
addr->sin_port = htons (PMAPPORT);
__close (s);
- return;
+ return TRUE;
}
ifr++;
}
goto again;
}
__close (s);
+ return FALSE;
}
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)
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)
-/* 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
#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 */