[S.Marshall@uk.ac.hull.seq: BSD/SYSV bzero/memset]

[S.Marshall@uk.ac.hull.seq: BSD/SYSV bzero/memset]

Post by Simon Marsha » Wed, 02 Oct 1991 04:41:41



| I am lead to believe that BSD versions of Unix comes with bzero, while USG
| and SYSV come with memset.  Am I being lead right?  I need to know to reduce
| the complexity of an #ifdef in some (ultra) portable code; I want to be able
| to say:

| #if defined(BSD)
| #define               ZERO(s,n)       bzero((s),(n))
| #else
| #define               ZERO(s,n)       memset((s), 0, (n))
| #endif

| Is this the best way to do this?  Or should I just assume that everyone has
| bzero accept SYSV?  Post/email is fine.

        Thanks to the 100s who replied; I couldn't reply to everyone.
     Most people seemed to think it was mostly OK & reliable, except that
     that's not quite enough!  The solution?  Write my own.  This is it.
     Anything wrong with it?  This is for writing zeros into a string.

/*
 * Why don't I use memset?  Err...  Or is it bzero?  Cos it's easier
 * to write my own:
 */

static void Zero (start)
  char  *start;
{
    char  *c;
    int   length = strlen (start);

    for (c=start; c<(start+length); c++)

        thanx, Simon.   *c = '\0';

Quote:}

_______________________________________________________________________________
Simon Marshall, Dept. of Computer Science, University of Hull, Hull HU6 7RX, UK
              "``La la la la la la la la la'' means I love you."

 
 
 

[S.Marshall@uk.ac.hull.seq: BSD/SYSV bzero/memset]

Post by Simon Marsha » Wed, 02 Oct 1991 04:48:15



/*
 * Why don't I use memset?  Err...  Or is it bzero?  Cos it's easier
 * to write my own:
 */

static void Zero (start)
  char  *start;
{
    char  *c;
    int   length = strlen (start);

    for (c=start; c<(start+length); c++)
        *c = '\0';

Quote:}

        Thanx, Simon.
_______________________________________________________________________________
Simon Marshall, Dept. of Computer Science, University of Hull, Hull HU6 7RX, UK
              "``La la la la la la la la la'' means I love you."


 
 
 

[S.Marshall@uk.ac.hull.seq: BSD/SYSV bzero/memset]

Post by Geoff Cla » Tue, 08 Oct 1991 21:10:25


[ I was sure there would be a flood of follow-ups to this one, but none
have arrived yet and the article is about to expire here, so I'll risk it.]


>/*
> * Why don't I use memset?  Err...  Or is it bzero?  Cos it's easier
> * to write my own:
> */
>static void Zero (start)
>  char  *start;
>{
>    char  *c;
>    int   length = strlen (start);
>    for (c=start; c<(start+length); c++)
>    *c = '\0';
>}

Apart from being horribly inefficient, the main problem I can see with
this function is that there is no possible use for it.  It takes a
null-terminated string and zeroes out each character in the string.
But a null-terminated string can be truncated simply by setting the
first byte to zero, so why bother to zero out all the rest?

If it's supposed to be a replacement for memset/bzero, it should take
an argument which specifies the number of bytes to be zeroed.
--

UniSoft Limited, London, England.   Tel: +44 71 729 3773   Fax: +44 71 729 3273

 
 
 

1. BSD/SYSV bzero/memset

        Sorry to hassle this group again, but I am lead to believe that
     BSD versions of Unix comes with bzero, while USG and SYSV come with
     memset.  Am I being lead right?  I need to know to reduce the
     complexity of an #ifdef in some (ultra) portable code; I want to be
     able to say:

#if defined(BSD)
#define         ZERO(s,n)       bzero((s),(n))
#else
#define         ZERO(s,n)       memset((s), 0, (n))
#endif

        Are there any other considerations I need to make?  Post/email is
     fine.

        Thanx, Simon.
_______________________________________________________________________________
Simon Marshall, Dept. of Computer Science, University of Hull, Hull HU6 7RX, UK
              "``La la la la la la la la la'' means I love you."

2. how tuff is it to install?

3. In article 81A@compsci.liverpool.ac.uk, m3apc@csc.liv.ac.uk (A.P. Crossan) writes:

4. Colors in UNIX

5. More wordlists at ftp.ox.ac.uk

6. /usr/bin/df reports false size on big NFS shares

7. OWEN LEBLANC (LeBlanc@mcc.ac.uk) CONTACT ME

8. Finding needed shared libs

9. Janet access to ftp.mcc.ac.uk

10. alfie@dcs.warwick.ac.uk bounced mail

11. Why does my computer call it's self pbwpwbw.nottingham.ac.uk

12. attn: Jeffrey Ng Sing Kwong <jeffng@dcs.qmw.ac.uk>

13. emacs from kuso.shef.ac.uk...HELP!