void-packages/srcpkgs/gpart/patches/0004-Speed-up-by-reading-larger-chunks.patch
Đoàn Trần Công Danh 7fc9190f0e srcpkgs/g*: convert patches to -Np1
* gcc is kept at -Np0, because of void-cross

```sh
git grep -l '^patch_args=-Np0' "srcpkgs/$1*/template" |
while read template; do
	for p in ${template%/template}/patches/*; do
		sed -i '
			\,^[+-][+-][+-] /dev/null,b
			/^[*-]\+ [0-9]\+\(,[0-9]\+\)\? [*-]\+$/b
			s,^[*][*][*] ,&a/,
			/^--- /{
				s,\(^--- \)\(./\)*,\1a/,
				s,[.][Oo][Rr][Ii][Gg]\([	/]\),\1,
				s/[.][Oo][Rr][Ii][Gg]$//
				s/[.]patched[.]\([^.]\)/.\1/
				h
			}
			/^+++ -/{
				g
				s/^--- a/+++ b/
				b
			}
			s,\(^+++ \)\(./\)*,\1b/,
		' "$p"
	done
	sed -i '/^patch_args=/d' $template
done
```
2021-06-20 13:17:29 +07:00

54 lines
1.2 KiB
Diff

From d56778515e88e8fd5821b49850006962fe81b18d Mon Sep 17 00:00:00 2001
From: Baruch Even <baruch@ev-en.org>
Date: Wed, 25 Nov 2015 08:58:10 +0200
Subject: [PATCH 4/5] Speed up by reading larger chunks
Based on work initiated by mwilck
---
src/gpart.c | 27 ++++++++++++++++-----------
1 file changed, 16 insertions(+), 11 deletions(-)
diff --git src/gpart.c src/gpart.c
index 63b36a5..d530547 100644
--- a/src/gpart.c
+++ b/src/gpart.c
@@ -163,20 +163,25 @@ byte_t *alloc(ssize_t s)
ssize_t bread(int fd,byte_t *buf,size_t ssize,size_t nsecs)
{
- ssize_t cs = 0, nr = 0;
-
- for ( ; nsecs > 0; nsecs--)
- {
- if ((nr = read(fd,buf,ssize)) == -1)
- {
+ const size_t total = ssize * nsecs;
+ size_t read_bytes = 0;
+
+ while (read_bytes < total) {
+ ssize_t ret = read(fd, buf + read_bytes, total - read_bytes);
+ if (ret > 0)
+ read_bytes += ret;
+ else if (ret == 0) {
+ return read_bytes;
+ } else {
+ // ret < 0, an error case
+ if (errno == EINTR)
+ continue; // Rogue signal interruption, retry
berrno = errno;
- return ((cs == 0) ? -1 : cs);
- }
- cs += nr; buf += nr;
- if (nr < ssize)
break;
+ }
}
- return (cs);
+
+ return read_bytes ? read_bytes : -1;
}
--
2.24.0