You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
578 B
C

#include <string.h>
#include "buffer.h"
extern int buffer_stubborn(ssize_t (*op)(),int fd,const char* buf, size_t len,void* cookie);
#ifndef __unlikely
#ifdef __GNUC__
#define __unlikely(x) __builtin_expect((x),0)
#else
#define __unlikely(x) (x)
#endif
#endif
int buffer_put(buffer* b,const char* buf,size_t len) {
if (__unlikely(len>b->a-b->p)) { /* doesn't fit */
if (buffer_flush(b)==-1) return -1;
if (len>b->a) {
if (buffer_stubborn(b->op,b->fd,buf,len,b)<0) return -1;
return 0;
}
}
memcpy(b->x+b->p, buf, len);
b->p+=len;
return 0;
}