asynciomainproxy-ticket
Last change
on this file since c33b0ea was
9e56602,
checked in by Thomas Klute <thomas2.klute@…>, 7 years ago
|
Check for write errors in pgpcrc.c to get rid of build warning
|
-
Property mode set to
100644
|
File size:
982 bytes
|
Line | |
---|
1 | #include <unistd.h> |
---|
2 | #include <arpa/inet.h> |
---|
3 | #include <stdio.h> |
---|
4 | #include <errno.h> |
---|
5 | |
---|
6 | /* from RFC 4880 section 6.1 */ |
---|
7 | #define CRC24_INIT 0xB704CEL |
---|
8 | #define CRC24_POLY 0x1864CFBL |
---|
9 | |
---|
10 | typedef long crc24; |
---|
11 | crc24 crc_octets(unsigned char *octets, size_t len) |
---|
12 | { |
---|
13 | crc24 crc = CRC24_INIT; |
---|
14 | int i; |
---|
15 | while (len--) { |
---|
16 | crc ^= (*octets++) << 16; |
---|
17 | for (i = 0; i < 8; i++) { |
---|
18 | crc <<= 1; |
---|
19 | if (crc & 0x1000000) |
---|
20 | crc ^= CRC24_POLY; |
---|
21 | } |
---|
22 | } |
---|
23 | return crc & 0xFFFFFFL; |
---|
24 | } |
---|
25 | |
---|
26 | |
---|
27 | int main() |
---|
28 | { |
---|
29 | crc24 output; |
---|
30 | int i = 0; |
---|
31 | unsigned char o; |
---|
32 | unsigned char indata[100000]; |
---|
33 | ssize_t rr = read(0, indata, sizeof(indata)); |
---|
34 | if (rr <= 0) { |
---|
35 | perror("pgpcrc read"); |
---|
36 | return 1; |
---|
37 | } |
---|
38 | output = crc_octets(indata, rr); |
---|
39 | for (i = 2; i >= 0; i--) { |
---|
40 | o = ((output >> (8 * i)) & 0xff); |
---|
41 | if (write(1, &o, sizeof(o)) < 0) { |
---|
42 | perror("pgpcrc write"); |
---|
43 | return 2; |
---|
44 | } |
---|
45 | } |
---|
46 | return 0; |
---|
47 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.