History

Update pragma once for file operations

Use open/read/close instead of fopen/fread/fclose for tcc4tcl and ziptcc

herman ten brugge committed 3 years ago

Commit c92f4f51 parent 4e363a11 file · +4 −4Browse files

Unified · Split

tccpp.c+4−4
@@ -1611,20 +1611,20 @@ bad_twosharp: · 1610 unmodified lines
1611static unsigned long long calc_file_hash(const char *filename)1611static 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_prime1625 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#endif1630#endif

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t