commit 4af0be8f006db00cdbe97b881eedf2b0d5275702
parent ef1837bac8326e899ab2f9d0d9066874f92955a7
Author: Jacob R. Edwards <n/a>
Date: Sun, 11 Dec 2022 17:35:02 -0600
Add bufread function
It was suppost to be commited when b812bd1c77fa47277f75c5d161962ce4941176c3
was.
Diffstat:
2 files changed, 37 insertions(+), 0 deletions(-)
diff --git a/lib/ap/read.c b/lib/ap/read.c
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2022 Jacob R. Edwards
+ *
+ * ap -- audio player
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <sys/socket.h>
+
+#include "buf.h"
+
+ssize_t
+bufread(struct buf *buf, int fd, size_t space)
+{
+ ssize_t len;
+
+ if (bufenlarge(buf, space))
+ return -1;
+ len = recv(fd, buf->data + buf->len, buf->size - buf->len, 0);
+ if (len <= 0)
+ return len;
+ buf->len += len;
+ return len;
+}
diff --git a/lib/ap/read.h b/lib/ap/read.h
@@ -0,0 +1 @@
+ssize_t bufread(struct buf *, int, size_t);