add buffer_init_allocbuf, buffer_init_read, buffer_init_write, buffer_init_read_allocbuf, buffer_init_write_allocbuf

master
leitner 4 years ago
parent 68a04bf226
commit e2673d3782

@ -9,6 +9,7 @@
add fmt_strm_malloc
add cross references to open_* and mmap_* man pages
add fmt_strm_alloca and fmt_strm_malloc man pages
add buffer_init_allocbuf, buffer_init_read, buffer_init_write, buffer_init_read_allocbuf, buffer_init_write_allocbuf
0.32:
remove OpenBSD #warning (obsd maintainer says no longer needed)

@ -44,15 +44,39 @@ typedef struct buffer {
#define BUFFER_OUTSIZE 8192
/* Initialize a buffer with an existing memory area, which the buffer
* will NOT take ownership of (i.e. won't free the memory when it's done */
* will NOT take ownership of (i.e. won't free the memory when it's done) */
att_writen(4,5)
void buffer_init(buffer* b,ssize_t (*op)(),int fd,char* y,size_t ylen);
void buffer_init(buffer* b, ssize_t (*op)(), int fd, char* y, size_t ylen);
/* Initialize a buffer with an existing memory area, which the buffer
* WILL take ownership of (it will call free() on it when it's done) */
att_writen(4,5)
void buffer_init_free(buffer* b,ssize_t (*op)(),int fd,char* y,size_t ylen);
/* Call buffer_init with op=read(), return 0.
* If fd==-1, return -1 instead, leaving b untouched. */
att_writen(3,4)
int buffer_init_read(buffer* b, int fd, char* y, size_t ylen);
/* Call buffer_init with op=write(), return 0.
* If fd==-1, return -1 instead, leaving b untouched. */
att_writen(3,4)
int buffer_init_write(buffer* b, int fd, char* y, size_t ylen);
/* Will allocate a buffer of size ylen and then call
* buffer_init_free(b, op, fd, thebuffer, ylen) on it.
* Returns 0 on success, -1 on error (setting errno).
* Passing fd==-1 is treated as error (so you can pass open*() for fd). */
int buffer_init_allocbuf(buffer* b, ssize_t (*op)(), int fd, size_t ylen);
/* Call buffer_init_allocbuf with op=read */
int buffer_init_read_allocbuf(buffer* b, int fd, size_t ylen);
/* Call buffer_init_allocbuf with op=read */
int buffer_init_write_allocbuf(buffer* b, int fd, size_t ylen);
/* Initialize a buffer without actual I/O.
* You give it a pre-existing memory area.
* When reading from this buffer, it will simply return the data from

@ -0,0 +1,13 @@
#include <stdlib.h>
#include <unistd.h>
#include "buffer.h"
int buffer_init_allocbuf(buffer* b, ssize_t (*op)(), int fd, size_t ylen) {
if (fd==-1) return -1;
char* thebuffer;
if (!(thebuffer=malloc(ylen)))
return -1;
buffer_init_free(b, op, fd, thebuffer, ylen);
return 0;
}

@ -0,0 +1,9 @@
#include <unistd.h>
#include <buffer.h>
int buffer_init_read(buffer* b, int fd, char* y,size_t ylen) {
if (fd==-1) return -1;
buffer_init(b, read, fd, y, ylen);
return 0;
}

@ -0,0 +1,7 @@
#include <unistd.h>
#include "buffer.h"
int buffer_init_read_allocbuf(buffer* b, int fd, size_t ylen) {
return buffer_init_allocbuf(b, read, fd, ylen);
}

@ -0,0 +1,9 @@
#include <unistd.h>
#include <buffer.h>
int buffer_init_write(buffer* b, int fd, char* y,size_t ylen) {
if (fd==-1) return -1;
buffer_init(b, write, fd, y, ylen);
return 0;
}

@ -0,0 +1,7 @@
#include <unistd.h>
#include "buffer.h"
int buffer_init_write_allocbuf(buffer* b, int fd, size_t ylen) {
return buffer_init_allocbuf(b, write, fd, ylen);
}
Loading…
Cancel
Save