1 /* 2 * Byte checking routines for CUPS. 3 * 4 * Copyright 2007 by Apple Inc. 5 * Copyright 1993-2005 by Easy Software Products. 6 * 7 * These coded instructions, statements, and computer programs are the 8 * property of Apple Inc. and are protected by Federal copyright 9 * law. Distribution and use rights are outlined in the file "COPYING" 10 * which should have been included with this file. 11 * 12 * Contents: 13 * 14 * cupsCheckBytes() - Check to see if all bytes are zero. 15 * cupsCheckValue() - Check to see if all bytes match the given value. 16 */ 17 18 /* 19 * Include necessary headers. 20 */ 21 22 #include "driver.h" 23 24 25 /* 26 * 'cupsCheckBytes()' - Check to see if all bytes are zero. 27 */ 28 29 int /* O - 1 if they match */ cupsCheckBytes(const unsigned char * bytes,int length)30cupsCheckBytes(const unsigned char *bytes, /* I - Bytes to check */ 31 int length) /* I - Number of bytes to check */ 32 { 33 while (length > 7) 34 { 35 if (*bytes++) 36 return (0); 37 if (*bytes++) 38 return (0); 39 if (*bytes++) 40 return (0); 41 if (*bytes++) 42 return (0); 43 if (*bytes++) 44 return (0); 45 if (*bytes++) 46 return (0); 47 if (*bytes++) 48 return (0); 49 if (*bytes++) 50 return (0); 51 52 length -= 8; 53 } 54 55 while (length > 0) 56 if (*bytes++) 57 return (0); 58 else 59 length --; 60 61 return (1); 62 } 63 64 65 /* 66 * 'cupsCheckValue()' - Check to see if all bytes match the given value. 67 */ 68 69 int /* O - 1 if they match */ cupsCheckValue(const unsigned char * bytes,int length,const unsigned char value)70cupsCheckValue(const unsigned char *bytes, /* I - Bytes to check */ 71 int length, /* I - Number of bytes to check */ 72 const unsigned char value) /* I - Value to check */ 73 { 74 while (length > 7) 75 { 76 if (*bytes++ != value) 77 return (0); 78 if (*bytes++ != value) 79 return (0); 80 if (*bytes++ != value) 81 return (0); 82 if (*bytes++ != value) 83 return (0); 84 if (*bytes++ != value) 85 return (0); 86 if (*bytes++ != value) 87 return (0); 88 if (*bytes++ != value) 89 return (0); 90 if (*bytes++ != value) 91 return (0); 92 93 length -= 8; 94 } 95 96 while (length > 0) 97 if (*bytes++ != value) 98 return (0); 99 else 100 length --; 101 102 return (1); 103 } 104 105