summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 6d4dcea)
raw | patch | inline | side by side (parent: 6d4dcea)
author | octo <octo> | |
Sun, 28 May 2006 15:15:04 +0000 (15:15 +0000) | ||
committer | octo <octo> | |
Sun, 28 May 2006 15:15:04 +0000 (15:15 +0000) |
src/common.c | patch | blob | history | |
src/common.h | patch | blob | history |
diff --git a/src/common.c b/src/common.c
index 78be3afce48a6318336367b618c7660b0bad3034..138b7678cf3767fc7c3a6f551e86842ac3176b84 100644 (file)
--- a/src/common.c
+++ b/src/common.c
}
#endif
+ssize_t sread (int fd, void *buf, size_t count)
+{
+ char *ptr;
+ size_t nleft;
+ ssize_t status;
+
+ ptr = (char *) buf;
+ nleft = count;
+
+ while (nleft > 0)
+ {
+ status = read (fd, (void *) ptr, nleft);
+
+ if ((status < 0) && ((errno == EAGAIN) || (errno == EINTR)))
+ continue;
+
+ if (status < 0)
+ return (status);
+
+ assert (nleft >= status);
+
+ nleft = nleft - status;
+ ptr = ptr + status;
+ }
+
+ return (0);
+}
+
+
+ssize_t swrite (int fd, const void *buf, size_t count)
+{
+ const char *ptr;
+ size_t nleft;
+ ssize_t status;
+
+ ptr = (const char *) buf;
+ nleft = buflen;
+
+ while (nleft > 0)
+ {
+ status = write (fd, (const void *) ptr, nleft);
+
+ if ((status < 0) && ((errno == EAGAIN) || (errno == EINTR)))
+ continue;
+
+ if (status < 0)
+ return (status);
+
+ nleft = nleft - status;
+ ptr = ptr + status;
+ }
+
+ return (0);
+}
+
int strsplit (char *string, char **fields, size_t size)
{
size_t i;
diff --git a/src/common.h b/src/common.h
index 4dc34b07f0420c5f2e8cf5e68c74efb717a6839e..f6a8e19a68843b71acec79896d5592dc41e244ad 100644 (file)
--- a/src/common.h
+++ b/src/common.h
char *sstrdup(const char *s);
void *smalloc(size_t size);
+/*
+ * NAME
+ * sread
+ *
+ * DESCRIPTION
+ * Reads exactly `n' bytes or failes. Syntax and other behavior is analogous
+ * to `read(2)'.
+ *
+ * PARAMETERS
+ * `fd' File descriptor to write to.
+ * `buf' Buffer that is to be written.
+ * `count' Numver of bytes in the buffer.
+ *
+ * RETURN VALUE
+ * Zero upon success or non-zero if an error occured. `errno' is set in this
+ * case.
+ */
+ssize_t sread (int fd, void *buf, size_t count);
+
+/*
+ * NAME
+ * swrite
+ *
+ * DESCRIPTION
+ * Writes exactly `n' bytes or failes. Syntax and other behavior is analogous
+ * to `write(2)'.
+ *
+ * PARAMETERS
+ * `fd' File descriptor to write to.
+ * `buf' Buffer that is to be written.
+ * `count' Numver of bytes in the buffer.
+ *
+ * RETURN VALUE
+ * Zero upon success or non-zero if an error occured. `errno' is set in this
+ * case.
+ */
+ssize_t swrite (int fd, const void *buf, size_t count);
+
/*
* NAME
* strsplit