if (len == 0) { if (fstat(fd, &sb) == -1) { close(fd); return (NULL); } len = sb.st_size; }
HASHFileChunk(const char *filename, char *buf, off_t off, off_t len){	u_char buffer[BUFSIZ];	HASH_CTX ctx;	int fd, save_errno;	ssize_t nr;	HASHInit(&ctx);	if ((fd = open(filename, O_RDONLY)) < 0)		return (NULL);	if (off > 0 && lseek(fd, off, SEEK_SET) < 0)		return (NULL);	while ((nr = read(fd, buffer, MIN(sizeof(buffer), len))) > 0) {		HASHUpdate(&ctx, buffer, (size_t)nr);		if (len > 0 && (len -= nr) == 0)			break;	}	save_errno = errno;	close(fd);	errno = save_errno;	return (nr < 0 ? NULL : HASHEnd(&ctx, buf));}