mirror of
https://github.com/tmux/tmux.git
synced 2024-12-14 10:58:48 +00:00
Sync OpenBSD patchset 499:
Bye-bye buffer*.c.
This commit is contained in:
parent
2df0882722
commit
142962742c
@ -1,53 +0,0 @@
|
|||||||
/* $Id: buffer-poll.c,v 1.19 2009-11-08 22:40:36 tcunha Exp $ */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
|
||||||
*
|
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
|
||||||
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#include <event.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "tmux.h"
|
|
||||||
|
|
||||||
/* Fill buffers from socket based on poll results. */
|
|
||||||
int
|
|
||||||
buffer_poll(int fd, int events, struct buffer *in, struct buffer *out)
|
|
||||||
{
|
|
||||||
ssize_t n;
|
|
||||||
|
|
||||||
if (in != NULL && events & EV_READ) {
|
|
||||||
buffer_ensure(in, BUFSIZ);
|
|
||||||
n = read(fd, BUFFER_IN(in), BUFFER_FREE(in));
|
|
||||||
if (n == 0)
|
|
||||||
return (-1);
|
|
||||||
if (n == -1) {
|
|
||||||
if (errno != EINTR && errno != EAGAIN)
|
|
||||||
return (-1);
|
|
||||||
} else
|
|
||||||
buffer_add(in, n);
|
|
||||||
}
|
|
||||||
if (out != NULL && BUFFER_USED(out) > 0 && events & EV_WRITE) {
|
|
||||||
n = write(fd, BUFFER_OUT(out), BUFFER_USED(out));
|
|
||||||
if (n == -1) {
|
|
||||||
if (errno != EINTR && errno != EAGAIN)
|
|
||||||
return (-1);
|
|
||||||
} else
|
|
||||||
buffer_remove(out, n);
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
139
buffer.c
139
buffer.c
@ -1,139 +0,0 @@
|
|||||||
/* $Id: buffer.c,v 1.8 2009-08-21 21:09:13 tcunha Exp $ */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
|
||||||
*
|
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
|
||||||
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "tmux.h"
|
|
||||||
|
|
||||||
/* Create a buffer. */
|
|
||||||
struct buffer *
|
|
||||||
buffer_create(size_t size)
|
|
||||||
{
|
|
||||||
struct buffer *b;
|
|
||||||
|
|
||||||
if (size == 0)
|
|
||||||
fatalx("zero size");
|
|
||||||
|
|
||||||
b = xcalloc(1, sizeof *b);
|
|
||||||
|
|
||||||
b->base = xmalloc(size);
|
|
||||||
b->space = size;
|
|
||||||
|
|
||||||
return (b);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Destroy a buffer. */
|
|
||||||
void
|
|
||||||
buffer_destroy(struct buffer *b)
|
|
||||||
{
|
|
||||||
xfree(b->base);
|
|
||||||
xfree(b);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Ensure free space for size in buffer. */
|
|
||||||
void
|
|
||||||
buffer_ensure(struct buffer *b, size_t size)
|
|
||||||
{
|
|
||||||
if (size == 0)
|
|
||||||
fatalx("zero size");
|
|
||||||
|
|
||||||
if (BUFFER_FREE(b) >= size)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (b->off > 0) {
|
|
||||||
if (b->size > 0)
|
|
||||||
memmove(b->base, b->base + b->off, b->size);
|
|
||||||
b->off = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (SIZE_MAX - b->size < size)
|
|
||||||
fatalx("size too big");
|
|
||||||
while (b->space < b->size + size) {
|
|
||||||
b->base = xrealloc(b->base, 2, b->space);
|
|
||||||
b->space *= 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Adjust buffer after data appended. */
|
|
||||||
void
|
|
||||||
buffer_add(struct buffer *b, size_t size)
|
|
||||||
{
|
|
||||||
if (size == 0)
|
|
||||||
fatalx("zero size");
|
|
||||||
if (size > b->space - b->size)
|
|
||||||
fatalx("overflow");
|
|
||||||
|
|
||||||
b->size += size;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Adjust buffer after data removed. */
|
|
||||||
void
|
|
||||||
buffer_remove(struct buffer *b, size_t size)
|
|
||||||
{
|
|
||||||
if (size == 0)
|
|
||||||
fatalx("zero size");
|
|
||||||
if (size > b->size)
|
|
||||||
fatalx("underflow");
|
|
||||||
|
|
||||||
b->size -= size;
|
|
||||||
b->off += size;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Copy data into a buffer. */
|
|
||||||
void
|
|
||||||
buffer_write(struct buffer *b, const void *data, size_t size)
|
|
||||||
{
|
|
||||||
buffer_ensure(b, size);
|
|
||||||
memcpy(BUFFER_IN(b), data, size);
|
|
||||||
buffer_add(b, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Copy data out of a buffer. */
|
|
||||||
void
|
|
||||||
buffer_read(struct buffer *b, void *data, size_t size)
|
|
||||||
{
|
|
||||||
if (size == 0)
|
|
||||||
fatalx("zero size");
|
|
||||||
if (size > b->size)
|
|
||||||
fatalx("underflow");
|
|
||||||
|
|
||||||
memcpy(data, BUFFER_OUT(b), size);
|
|
||||||
buffer_remove(b, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Store an 8-bit value. */
|
|
||||||
void
|
|
||||||
buffer_write8(struct buffer *b, uint8_t n)
|
|
||||||
{
|
|
||||||
buffer_ensure(b, 1);
|
|
||||||
BUFFER_IN(b)[0] = n;
|
|
||||||
b->size++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Extract an 8-bit value. */
|
|
||||||
uint8_t
|
|
||||||
buffer_read8(struct buffer *b)
|
|
||||||
{
|
|
||||||
uint8_t n;
|
|
||||||
|
|
||||||
n = BUFFER_OUT(b)[0];
|
|
||||||
buffer_remove(b, 1);
|
|
||||||
return (n);
|
|
||||||
}
|
|
31
tmux.h
31
tmux.h
@ -1,4 +1,4 @@
|
|||||||
/* $Id: tmux.h,v 1.501 2009-11-08 23:02:56 tcunha Exp $ */
|
/* $Id: tmux.h,v 1.502 2009-11-08 23:05:36 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -95,21 +95,6 @@ extern char **environ;
|
|||||||
#define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
|
#define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Buffer macros. */
|
|
||||||
#define BUFFER_USED(b) ((b)->size)
|
|
||||||
#define BUFFER_FREE(b) ((b)->space - (b)->off - (b)->size)
|
|
||||||
#define BUFFER_IN(b) ((b)->base + (b)->off + (b)->size)
|
|
||||||
#define BUFFER_OUT(b) ((b)->base + (b)->off)
|
|
||||||
|
|
||||||
/* Buffer structure. */
|
|
||||||
struct buffer {
|
|
||||||
u_char *base; /* buffer start */
|
|
||||||
size_t space; /* total size of buffer */
|
|
||||||
|
|
||||||
size_t size; /* size of data in buffer */
|
|
||||||
size_t off; /* offset of data in buffer */
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Bell option values. */
|
/* Bell option values. */
|
||||||
#define BELL_NONE 0
|
#define BELL_NONE 0
|
||||||
#define BELL_ANY 1
|
#define BELL_ANY 1
|
||||||
@ -1907,20 +1892,6 @@ int utf8_append(struct utf8_data *, u_char);
|
|||||||
/* osdep-*.c */
|
/* osdep-*.c */
|
||||||
char *osdep_get_name(int, char *);
|
char *osdep_get_name(int, char *);
|
||||||
|
|
||||||
/* buffer.c */
|
|
||||||
struct buffer *buffer_create(size_t);
|
|
||||||
void buffer_destroy(struct buffer *);
|
|
||||||
void buffer_ensure(struct buffer *, size_t);
|
|
||||||
void buffer_add(struct buffer *, size_t);
|
|
||||||
void buffer_remove(struct buffer *, size_t);
|
|
||||||
void buffer_write(struct buffer *, const void *, size_t);
|
|
||||||
void buffer_read(struct buffer *, void *, size_t);
|
|
||||||
void buffer_write8(struct buffer *, uint8_t);
|
|
||||||
uint8_t buffer_read8(struct buffer *);
|
|
||||||
|
|
||||||
/* buffer-poll.c */
|
|
||||||
int buffer_poll(int, int, struct buffer *, struct buffer *);
|
|
||||||
|
|
||||||
/* log.c */
|
/* log.c */
|
||||||
void log_open_tty(int);
|
void log_open_tty(int);
|
||||||
void log_open_file(int, const char *);
|
void log_open_file(int, const char *);
|
||||||
|
Loading…
Reference in New Issue
Block a user