Moved 8 static error functions to sysdeps/common/error.c. This is the end

* include/glibtop/error.h: Moved 8 static error functions to
        sysdeps/common/error.c. This is the end of an big useless code
        bloat : expect ~8KB of object size reduction.

        * include/glibtop/procuid.h: s/int/gint32/g

        * lib/errors.c: (glibtop_error_quark):
        * lib/read.c: (do_read), (glibtop_read_l):
        * lib/read_data.c: (glibtop_read_data_l): Minor cleanups.
This commit is contained in:
Benoît Dejean
2004-06-18 07:38:37 +00:00
parent bb01063e93
commit 6b3d52ff0e
6 changed files with 41 additions and 113 deletions

View File

@@ -31,37 +31,25 @@
static void
do_read (int s, void *ptr, size_t total_size)
{
int nread;
size_t already_read = 0, remaining = total_size;
char *tmp_ptr;
ssize_t nread;
while (already_read < total_size) {
nread = recv (s, ptr, remaining, 0);
if(!total_size) return;
if (nread == 0) {
close (s);
continue;
}
if (nread <= 0) {
glibtop_error_io ("recv");
return;
}
already_read += nread;
remaining -= nread;
/* (char *) ptr += nread; */
tmp_ptr = ptr;
tmp_ptr += nread;
ptr = tmp_ptr;
while (total_size && (nread = recv (s, ptr, total_size, 0)) > 0) {
total_size -= nread;
ptr = (char*)ptr + nread;
}
if(nread == 0)
close (s);
if (nread < 0)
glibtop_error_io ("recv");
}
void
glibtop_read_l (glibtop *server, size_t size, void *buf)
{
int ret = 0;
glibtop_init_r (&server, 0, 0);
#ifdef DEBUG
@@ -71,9 +59,11 @@ glibtop_read_l (glibtop *server, size_t size, void *buf)
if (server->socket) {
do_read (server->socket, buf, size);
} else {
ret = read (server->input [0], buf, size);
if(read (server->input [0], buf, size) < 0)
glibtop_error_io_r (
server,
ngettext ("read %d byte",
"read %d bytes", size),
size);
}
if (ret < 0)
glibtop_error_io_r (server, ngettext ("read %d byte", "read %d bytes", size), size);
}