| Index | Submit class | Submit snippet | Submission feed | List |

Snippet #29

Language: C, Author: Zachary Schneirov
License: Public domain

Function that returns true if all bytes in a buffer are NULL. This is useful for testing whether opaque structures like FSRef are valid, presumably after having been bzero'd.

int IsZeros(const void *s1, size_t n) {
  if (n != 0) {
    const unsigned char *p1 = s1;
    
    do {
      if (*p1++ != 0)
        return (0);
    } while (--n != 0);
  }
  return (1);
}

Compatible with:


Comments

Name

Website

Do you hate spammers? (Answer "Yes")