[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v2 1/4] sha1sum: use AF_ALG when available
From: |
Dmitry V. Levin |
Subject: |
Re: [PATCH v2 1/4] sha1sum: use AF_ALG when available |
Date: |
Wed, 25 Apr 2018 15:25:13 +0300 |
On Wed, Apr 25, 2018 at 01:26:08PM +0200, Matteo Croce wrote:
[...]
> +#include <config.h>
> +
> +#include <sys/socket.h>
> +
> +#ifdef AF_ALG
> +
> +#include <unistd.h>
> +#include <string.h>
> +#include <linux/if_alg.h>
> +#include <sys/stat.h>
> +#include <sys/sendfile.h>
> +
> +#include "af_alg.h"
> +
> +/* from linux/include/linux/fs.h: (INT_MAX & PAGE_MASK) */
> +#define MAX_RW_COUNT 0x7FFFF000
> +#define BLOCKSIZE 32768
> +
> +int
> +afalg_stream (FILE * stream, void *resblock, const char *alg, ssize_t
> hashlen)
> +{
> + struct sockaddr_alg salg = {
As struct sockaddr_alg is not provided by glibc,
you'd have to check for HAVE_LINUX_IF_ALG_H after all.
[...]
> + /* if file is a regular file, attempt sendfile() to pipe the data */
> + if (!fstat (fileno (stream), &st) && S_ISREG (st.st_mode) &&
> + st.st_size <= MAX_RW_COUNT)
> + {
> + if (sendfile (ofd, fileno (stream), NULL, st.st_size) != st.st_size)
Given that sendfile has offset argument, wouldn't it be better
to use a sendfile loop for handling large regular files?
--
ldv
signature.asc
Description: PGP signature