ARGSUSED */
| 110 | |
| 111 | /* ARGSUSED */ |
| 112 | void |
| 113 | crashreport_init(int argc, char *argv[]) |
| 114 | { |
| 115 | static int once = 0; |
| 116 | if (once++) /* NetHackW.exe calls us twice */ |
| 117 | return; |
| 118 | HASH_BINFILE_DECL; |
| 119 | HASH_PRAGMA_START |
| 120 | HASH_CONTEXTPTR(ctxp); |
| 121 | if (HASH_INIT(ctxp)) |
| 122 | goto skip; |
| 123 | HASH_BINFILE(); /* Does "goto skip" on error. */ |
| 124 | |
| 125 | int fd = open(binfile, HASH_OFLAGS, 0); |
| 126 | if (fd == -1) { |
| 127 | # ifdef BETA |
| 128 | raw_printf("open e=%s", strerror(errno)); |
| 129 | # endif |
| 130 | goto skip; |
| 131 | } |
| 132 | |
| 133 | int segsize; |
| 134 | unsigned char segment[4096]; |
| 135 | |
| 136 | while (0 < (segsize = read(fd, segment, sizeof segment))) { |
| 137 | if (HASH_UPDATE(ctxp, segment, segsize)) |
| 138 | goto skip; |
| 139 | } |
| 140 | if (segsize < 0) { |
| 141 | close(fd); |
| 142 | goto skip; |
| 143 | } |
| 144 | if (HASH_FINISH(ctxp)) |
| 145 | goto skip; |
| 146 | close(fd); |
| 147 | |
| 148 | static const char hexdigits[] = "0123456789abcdef"; |
| 149 | char *p = bid; |
| 150 | unsigned char *in; |
| 151 | HASH_RESULT(ctxp, &in); |
| 152 | uint8 cnt = (uint8) HASH_RESULT_SIZE(ctxp); |
| 153 | /* Just in case, make sure not to overflow the bid buffer. |
| 154 | Divide size by 2 because each octet in the hash uses two slots |
| 155 | in bid[] when formatted as a pair of hexadecimal digits. */ |
| 156 | if (cnt >= (uint8) sizeof bid / 2) |
| 157 | cnt = (uint8) sizeof bid / 2 - 1; |
| 158 | while (cnt) { |
| 159 | /* sprintf(p, "%02x", *in++), p += 2; */ |
| 160 | *p++ = hexdigits[(*in >> 4) & 0x0f]; |
| 161 | *p++ = hexdigits[*in++ & 0x0f]; |
| 162 | --cnt; |
| 163 | } |
| 164 | *p = '\0'; |
| 165 | HASH_CLEANUP(ctxp); |
| 166 | return; |
| 167 | |
| 168 | skip: |
| 169 | Strcpy(bid, "unknown"); |
no test coverage detected