gcc 15 and C23 force some union trickery on buffer.h :-(
add a few buffer_init*_forread variants to pretend we have type safety make sure buffer_init_staticcontents handles flushing attempts
This commit is contained in:
@@ -1,14 +1,28 @@
|
||||
#include <libowfat/buffer.h>
|
||||
#include <errno.h>
|
||||
|
||||
static ssize_t op() {
|
||||
static ssize_t op(int fd,const void* buf,size_t l) {
|
||||
(void)fd;
|
||||
(void)buf;
|
||||
(void)l;
|
||||
errno=ENOENT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void buffer_init_staticcontents(buffer* b, char* y, size_t len) {
|
||||
b->x=y;
|
||||
b->p=0; b->a=b->n=len;
|
||||
b->p=0; b->a=len; b->n=0;
|
||||
b->fd=-1;
|
||||
b->op=op;
|
||||
b->op.wop=op;
|
||||
b->deinit=0;
|
||||
}
|
||||
|
||||
void buffer_init_staticcontents_forread(buffer* b, const char* y, size_t len) {
|
||||
b->x=(char*)y;
|
||||
b->p=0;
|
||||
b->a=b->n=len;
|
||||
b->fd=-1;
|
||||
b->op.wop=op;
|
||||
b->deinit=0;
|
||||
}
|
||||
|
||||
@@ -26,7 +40,7 @@ void buffer_init_staticcontents(buffer* b, char* y, size_t len) {
|
||||
|
||||
int main() {
|
||||
buffer b;
|
||||
buffer_init_staticcontents(&b, "fnord", 5);
|
||||
buffer_init_staticcontents_forread(&b, "fnord", 5);
|
||||
char tmp[6];
|
||||
assert(buffer_get(&b, tmp, 6) == 5);
|
||||
assert(!memcmp(tmp,"fnord",5));
|
||||
|
||||
Reference in New Issue
Block a user