+/*
+ * Read a specific number of bytes of binary data from the Citadel server.
+ * Returns the number of bytes read or -1 for error.
+ */
+int ctdl_read_binary(struct ctdlsession *ctdl, char *buf, int bytes_requested)
+{
+ int bytes_read = 0;
+ int c = 0;
+
+ while (bytes_read < bytes_requested) {
+ c = read(ctdl->sock, &buf[bytes_read], bytes_requested-bytes_read);
+ if (c <= 0) {
+ syslog(LOG_DEBUG, "Socket error or zero-length read");
+ return (-1);
+ }
+ bytes_read += c;
+ }
+ return (bytes_read);
+}
+
+