This is the mail archive of the newlib@sources.redhat.com mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: swab() in string.h


Geoffrey Keating wrote:
> 
> Having swab() in string.h means we need to drag in ssize_t, or
> something similar.  The SVID doesn't specify a header file; XPG says
> <unistd.h>.  GLibc defines it in <unistd.h> only, Solaris defines it
> in <stdlib.h> and <unistd.h>, AIX defines it in <string.h> (only if
> _ALL_SOURCE) and <unistd.h>.  HPUX defines it in <unistd.h>, or in
> <string.h> only if _INCLUDE_AES_SOURCE is defined.
> 
> So in short I think it'd be better if we didn't define it in
> <string.h>.  GCC knows about its prototype anyway, so this should not
> cause any problems.  This lets us remove <sys/types.h> from
> <string.h>.
> 
> Oh, and the doc is certainly wrong.  No-one should be expecting it in
> string.h, even if it's there.  The Solaris, AIX, and HPUX manual pages
> all say <unistd.h>.
> 
> (The reason for all this is that a customer was complaining that
> including <string.h> caused, among other things, time_t and fdset_t to
> be defined, a particularly nasty bit of namespace pollution especially
> as the customer was using their own I/O library and only wanted the
> string routines from newlib.)
> 
> OK to commit?
> 

Yes, go ahead.

-- Jeff Johnston (Red Hat Inc)

> --
> Geoff Keating <geoffk@cygnus.com>
> 
> ===File ~/patches/newlib-swab.patch=========================
> 2000-08-29  Geoffrey Keating  <geoffk@cygnus.com>
> 
>         * libc/string/swab.c: Specify that it's defined in <unistd.h>.
>         * libc/include/string.h: Don't include <sys/types.h>,
>         as it causes really bad namespace pollution.  Don't declare
>         swab(), it is properly declared in unistd.h.
> 
> Index: libc/include/string.h
> ===================================================================
> RCS file: /cvs/src/src/newlib/libc/include/string.h,v
> retrieving revision 1.7
> diff -u -p -r1.7 string.h
> --- string.h    2000/06/03 03:03:03     1.7
> +++ string.h    2000/08/30 03:54:12
> @@ -13,7 +13,6 @@ extern "C" {
> 
>  #include "_ansi.h"
>  #include <sys/reent.h>
> -#include <sys/types.h>
> 
>  #define __need_size_t
>  #include <stddef.h>
> @@ -72,7 +71,6 @@ const char  *_EXFUN(strsignal, (int __si
>  #endif
>  int     _EXFUN(strtosigno, (const char *__name));
>  #endif
> -void    _EXFUN(swab,(const void *, void *, ssize_t));
> 
>  /* These function names are used on Windows and perhaps other systems.  */
>  #ifndef strcmpi
> Index: libc/string/swab.c
> ===================================================================
> RCS file: /cvs/src/src/newlib/libc/string/swab.c,v
> retrieving revision 1.3
> diff -u -p -r1.3 swab.c
> --- swab.c      2000/03/09 22:25:01     1.3
> +++ swab.c      2000/08/30 03:54:13
> @@ -3,7 +3,7 @@ FUNCTION
>         <<swab>>---swap adjacent bytes
> 
>  ANSI_SYNOPSIS
> -       #include <string.h>
> +       #include <unistd.h>
>         void swab(const void *<[in]>, void *<[out]>, ssize_t <[n]>);
> 
>  TRAD_SYNOPSIS
> ============================================================

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]