1
0
Fork 0
mirror of https://github.com/pygos/pkg-utils.git synced 2024-12-22 09:50:49 +01:00

Split utility code up into translation-unit per function

Signed-off-by: David Oberhollenzer <goliath@infraroot.at>
This commit is contained in:
David Oberhollenzer 2019-02-04 15:29:16 +01:00
parent 16f3e4d97c
commit 4d8b8f52d5
4 changed files with 55 additions and 47 deletions

View file

@ -4,7 +4,9 @@ AM_CPPFLAGS = -I$(top_srcdir)/include -D_GNU_SOURCE
AM_CFLAGS = $(WARN_CFLAGS)
# helper libraries
libutil_a_SOURCES = lib/util/input_file.c lib/util/mkdir_p.c lib/util/util.c
libutil_a_SOURCES = lib/util/input_file.c lib/util/mkdir_p.c
libutil_a_SOURCES += lib/util/write_retry.c lib/util/read_retry.c
libutil_a_SOURCES += lib/util/canonicalize_name.c
libutil_a_SOURCES += include/util/util.h include/util/input_file.h
# application core

View file

@ -1,6 +1,4 @@
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include "util/util.h"
@ -55,47 +53,3 @@ int canonicalize_name(char *filename)
return 0;
}
ssize_t write_retry(int fd, void *data, size_t size)
{
ssize_t ret, total = 0;
while (size > 0) {
ret = write(fd, data, size);
if (ret == 0)
break;
if (ret < 0) {
if (errno == EINTR)
continue;
return -1;
}
data = (char *)data + ret;
size -= ret;
total += ret;
}
return total;
}
ssize_t read_retry(int fd, void *buffer, size_t size)
{
ssize_t ret, total = 0;
while (size > 0) {
ret = read(fd, buffer, size);
if (ret < 0) {
if (errno == EINTR)
continue;
return -1;
}
if (ret == 0)
break;
total += ret;
size -= ret;
buffer = (char *)buffer + ret;
}
return total;
}

26
lib/util/read_retry.c Normal file
View file

@ -0,0 +1,26 @@
#include <unistd.h>
#include <errno.h>
#include "util/util.h"
ssize_t read_retry(int fd, void *buffer, size_t size)
{
ssize_t ret, total = 0;
while (size > 0) {
ret = read(fd, buffer, size);
if (ret < 0) {
if (errno == EINTR)
continue;
return -1;
}
if (ret == 0)
break;
total += ret;
size -= ret;
buffer = (char *)buffer + ret;
}
return total;
}

26
lib/util/write_retry.c Normal file
View file

@ -0,0 +1,26 @@
#include <unistd.h>
#include <errno.h>
#include "util/util.h"
ssize_t write_retry(int fd, void *data, size_t size)
{
ssize_t ret, total = 0;
while (size > 0) {
ret = write(fd, data, size);
if (ret == 0)
break;
if (ret < 0) {
if (errno == EINTR)
continue;
return -1;
}
data = (char *)data + ret;
size -= ret;
total += ret;
}
return total;
}