=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/Attic/imsg-buffer.c,v retrieving revision 1.2 retrieving revision 1.3 diff -c -r1.2 -r1.3 *** src/usr.bin/tmux/Attic/imsg-buffer.c 2009/09/15 18:12:51 1.2 --- src/usr.bin/tmux/Attic/imsg-buffer.c 2010/05/26 13:56:07 1.3 *************** *** 1,4 **** ! /* $OpenBSD: imsg-buffer.c,v 1.2 2009/09/15 18:12:51 jacekm Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer --- 1,4 ---- ! /* $OpenBSD: imsg-buffer.c,v 1.3 2010/05/26 13:56:07 nicm Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer *************** *** 28,43 **** #include "imsg.h" ! int buf_realloc(struct buf *, size_t); ! void buf_enqueue(struct msgbuf *, struct buf *); ! void buf_dequeue(struct msgbuf *, struct buf *); ! struct buf * ! buf_open(size_t len) { ! struct buf *buf; ! if ((buf = calloc(1, sizeof(struct buf))) == NULL) return (NULL); if ((buf->buf = malloc(len)) == NULL) { free(buf); --- 28,43 ---- #include "imsg.h" ! int ibuf_realloc(struct ibuf *, size_t); ! void ibuf_enqueue(struct msgbuf *, struct ibuf *); ! void ibuf_dequeue(struct msgbuf *, struct ibuf *); ! struct ibuf * ! ibuf_open(size_t len) { ! struct ibuf *buf; ! if ((buf = calloc(1, sizeof(struct ibuf))) == NULL) return (NULL); if ((buf->buf = malloc(len)) == NULL) { free(buf); *************** *** 49,63 **** return (buf); } ! struct buf * ! buf_dynamic(size_t len, size_t max) { ! struct buf *buf; if (max < len) return (NULL); ! if ((buf = buf_open(len)) == NULL) return (NULL); if (max > 0) --- 49,63 ---- return (buf); } ! struct ibuf * ! ibuf_dynamic(size_t len, size_t max) { ! struct ibuf *buf; if (max < len) return (NULL); ! if ((buf = ibuf_open(len)) == NULL) return (NULL); if (max > 0) *************** *** 67,73 **** } int ! buf_realloc(struct buf *buf, size_t len) { u_char *b; --- 67,73 ---- } int ! ibuf_realloc(struct ibuf *buf, size_t len) { u_char *b; *************** *** 87,96 **** } int ! buf_add(struct buf *buf, const void *data, size_t len) { if (buf->wpos + len > buf->size) ! if (buf_realloc(buf, len) == -1) return (-1); memcpy(buf->buf + buf->wpos, data, len); --- 87,96 ---- } int ! ibuf_add(struct ibuf *buf, const void *data, size_t len) { if (buf->wpos + len > buf->size) ! if (ibuf_realloc(buf, len) == -1) return (-1); memcpy(buf->buf + buf->wpos, data, len); *************** *** 99,110 **** } void * ! buf_reserve(struct buf *buf, size_t len) { void *b; if (buf->wpos + len > buf->size) ! if (buf_realloc(buf, len) == -1) return (NULL); b = buf->buf + buf->wpos; --- 99,110 ---- } void * ! ibuf_reserve(struct ibuf *buf, size_t len) { void *b; if (buf->wpos + len > buf->size) ! if (ibuf_realloc(buf, len) == -1) return (NULL); b = buf->buf + buf->wpos; *************** *** 113,119 **** } void * ! buf_seek(struct buf *buf, size_t pos, size_t len) { /* only allowed to seek in already written parts */ if (pos + len > buf->wpos) --- 113,119 ---- } void * ! ibuf_seek(struct ibuf *buf, size_t pos, size_t len) { /* only allowed to seek in already written parts */ if (pos + len > buf->wpos) *************** *** 123,150 **** } size_t ! buf_size(struct buf *buf) { return (buf->wpos); } size_t ! buf_left(struct buf *buf) { return (buf->max - buf->wpos); } void ! buf_close(struct msgbuf *msgbuf, struct buf *buf) { ! buf_enqueue(msgbuf, buf); } int ! buf_write(struct msgbuf *msgbuf) { struct iovec iov[IOV_MAX]; ! struct buf *buf; unsigned int i = 0; ssize_t n; --- 123,150 ---- } size_t ! ibuf_size(struct ibuf *buf) { return (buf->wpos); } size_t ! ibuf_left(struct ibuf *buf) { return (buf->max - buf->wpos); } void ! ibuf_close(struct msgbuf *msgbuf, struct ibuf *buf) { ! ibuf_enqueue(msgbuf, buf); } int ! ibuf_write(struct msgbuf *msgbuf) { struct iovec iov[IOV_MAX]; ! struct ibuf *buf; unsigned int i = 0; ssize_t n; *************** *** 176,182 **** } void ! buf_free(struct buf *buf) { free(buf->buf); free(buf); --- 176,182 ---- } void ! ibuf_free(struct ibuf *buf) { free(buf->buf); free(buf); *************** *** 193,206 **** void msgbuf_drain(struct msgbuf *msgbuf, size_t n) { ! struct buf *buf, *next; for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0; buf = next) { next = TAILQ_NEXT(buf, entry); if (buf->rpos + n >= buf->wpos) { n -= buf->wpos - buf->rpos; ! buf_dequeue(msgbuf, buf); } else { buf->rpos += n; n = 0; --- 193,206 ---- void msgbuf_drain(struct msgbuf *msgbuf, size_t n) { ! struct ibuf *buf, *next; for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0; buf = next) { next = TAILQ_NEXT(buf, entry); if (buf->rpos + n >= buf->wpos) { n -= buf->wpos - buf->rpos; ! ibuf_dequeue(msgbuf, buf); } else { buf->rpos += n; n = 0; *************** *** 211,227 **** void msgbuf_clear(struct msgbuf *msgbuf) { ! struct buf *buf; while ((buf = TAILQ_FIRST(&msgbuf->bufs)) != NULL) ! buf_dequeue(msgbuf, buf); } int msgbuf_write(struct msgbuf *msgbuf) { struct iovec iov[IOV_MAX]; ! struct buf *buf; unsigned int i = 0; ssize_t n; struct msghdr msg; --- 211,227 ---- void msgbuf_clear(struct msgbuf *msgbuf) { ! struct ibuf *buf; while ((buf = TAILQ_FIRST(&msgbuf->bufs)) != NULL) ! ibuf_dequeue(msgbuf, buf); } int msgbuf_write(struct msgbuf *msgbuf) { struct iovec iov[IOV_MAX]; ! struct ibuf *buf; unsigned int i = 0; ssize_t n; struct msghdr msg; *************** *** 284,297 **** } void ! buf_enqueue(struct msgbuf *msgbuf, struct buf *buf) { TAILQ_INSERT_TAIL(&msgbuf->bufs, buf, entry); msgbuf->queued++; } void ! buf_dequeue(struct msgbuf *msgbuf, struct buf *buf) { TAILQ_REMOVE(&msgbuf->bufs, buf, entry); --- 284,297 ---- } void ! ibuf_enqueue(struct msgbuf *msgbuf, struct ibuf *buf) { TAILQ_INSERT_TAIL(&msgbuf->bufs, buf, entry); msgbuf->queued++; } void ! ibuf_dequeue(struct msgbuf *msgbuf, struct ibuf *buf) { TAILQ_REMOVE(&msgbuf->bufs, buf, entry); *************** *** 299,303 **** close(buf->fd); msgbuf->queued--; ! buf_free(buf); } --- 299,303 ---- close(buf->fd); msgbuf->queued--; ! ibuf_free(buf); }