Use open/read/close instead of fopen/fread/fclose for tcc4tcl and ziptcc
Unified · Split
| @@ -1611,20 +1611,20 @@ bad_twosharp: · 1610 unmodified lines | |||
| 1611 | static unsigned long long calc_file_hash(const char *filename) | 1611 | static unsigned long long calc_file_hash(const char *filename) |
| 1612 | { | 1612 | { |
| 1613 | unsigned long long hash = 14695981039346656037ull; // FNV_offset_basis; | 1613 | unsigned long long hash = 14695981039346656037ull; // FNV_offset_basis; |
| 1614 | FILE *fp = fopen (filename, "rb"); | 1614 | int fd = open (filename, O_RDONLY | O_BINARY); |
| 1615 | 1615 | ||
| 1616 | if (fp == NULL) | 1616 | if (fd < 0) |
| 1617 | return 0; | 1617 | return 0; |
| 1618 | for (;;) { | 1618 | for (;;) { |
| 1619 | unsigned char temp[IO_BUF_SIZE]; | 1619 | unsigned char temp[IO_BUF_SIZE]; |
| 1620 | int i, n = fread(temp, 1, sizeof(temp), fp); | 1620 | int i, n = read(fd, temp, sizeof(temp)); |
| 1621 | 1621 | ||
| 1622 | if (n <= 0) | 1622 | if (n <= 0) |
| 1623 | break; | 1623 | break; |
| 1624 | for (i = 0; i < n; i++) | 1624 | for (i = 0; i < n; i++) |
| 1625 | hash = hash * 1099511628211ull ^ temp[i]; // FNV_prime | 1625 | hash = hash * 1099511628211ull ^ temp[i]; // FNV_prime |
| 1626 | } | 1626 | } |
| 1627 | fclose(fp); | 1627 | close(fd); |
| 1628 | return hash ? hash : 1ull; | 1628 | return hash ? hash : 1ull; |
| 1629 | } | 1629 | } |
| 1630 | #endif | 1630 | #endif |