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