This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


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

Re: bcopy -> memcpy/memmove transition proposal


| It is really ridiculous that gcc still uses the non-ANSI functions
| (such as bcopy), rather than the standard ANSI functions.  We all
| (I hope) agree this is bogus, but fixing them all is a hassle.

I fully agree.

In the past I have moved the IRC daemon (undernet) also to
ANSI functions and have had no problems.

Of course this daemon doesn't run on as many Operating Systems
as the GNU compiler, but in general it is compiled on a LOT, and
I never had any complaint.

Here is how I did it in that package:

---
1) In configure.in :

AC_HEADER_STDC
AC_CHECK_HEADERS(string.h memory.h)
AC_FUNC_MEMCMP
AC_CHECK_FUNCS(strchr memcpy memmove)

---
2) Using the following in a header file which is included before
   all other #includes in all files:

#if STDC_HEADERS
#include <string.h>
#else

#if HAVE_STRING_H
#include <string.h>
#endif

#ifndef HAVE_STRCHR
#define strchr index
#define strrchr rindex
#endif

char *strchr(), *strrchr(), *strtok();

#if HAVE_MEMORY_H
#include <memory.h>
#endif

#ifndef HAVE_MEMCPY
#define memcpy(d, s, n) bcopy ((s), (d), (n))
#define memset(a, b, c) bzero((a), (c))		/* We ONLY use memset(x, 0, y) */
#else

#if NEED_BZERO		/* This is not used yet - needs to be added to `configure' */
#define bzero(a, c) memset((a), 0, (c))		/* Some use it in FD_ZERO */
#endif

#endif /*HAVE_MEMCPY*/

#ifndef HAVE_MEMMOVE
#define memmove(d, s, n) bcopy ((s), (d), (n))
#endif

#endif /*STDC_HEADERS*/

---
3) Using in source without (compile) problems:

memcpy(...)
memcmp(...)
memmove(...)
memset(s, 0, n) <-- Only used for filling with zero's.

strchr()
strrchr()
strtok()

---
NOTES:

* I only use memset() to fill with zero's, there might be Operating Systems that
  actually still don't have memset and which uses the bzero() instead :/.
  I wouldn't know actually :)

* There are Operating Systems which use `bzero()' in a macro FD_ZERO.
  Those Operating Systems also have bzero itself defined it seems (I didn't need
  to #define NEED_BZERO yet), it should be kept in mind thought that on
  machines like that it is impossible to ONLY use the mem-family (most also
  have memset).

* I didn't run into a machine yet that didn't have strtok().
  (Some have strtoken() (not ANSI), most don't).


I hope this was helpful,

-- 
 Carlo Wood  <carlo@runaway.xs4all.nl>


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