Skip to content

Commit

Permalink
lib/util_hash: revert change to FILE stream.
Browse files Browse the repository at this point in the history
It makes tests fail like crazy. Investigate.
  • Loading branch information
ericonr committed Aug 25, 2020
1 parent 228097e commit 80cf547
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/util_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ xbps_mmap_file(const char *file, void **mmf, size_t *mmflen, size_t *filelen)
bool
xbps_file_sha256_raw(unsigned char *dst, size_t dstlen, const char *file)
{
FILE *stream;
size_t len;
int fd;
ssize_t len;
char buf[65536];
br_sha256_context sha256;

Expand All @@ -122,17 +122,17 @@ xbps_file_sha256_raw(unsigned char *dst, size_t dstlen, const char *file)
return false;
}

if ((stream = fopen(file, "r")) == 0)
if ((fd = open(file, O_RDONLY)) < 0)
return false;

br_sha256_init(&sha256);

while ((len = fread(buf, 1, sizeof(buf), stream)) == sizeof(buf))
while ((len = read(fd, buf, sizeof(buf))) > 0)
br_sha256_update(&sha256, buf, len);

fclose(stream);
close(fd);

if(len == 0)
if(len == -1)
return false;

br_sha256_out(&sha256, dst);
Expand Down

0 comments on commit 80cf547

Please sign in to comment.