static void wsi_output(struct lws *wsi, pty_buf_t *buf) {
if (buf == NULL) return;
- char *wbuf = xmalloc(LWS_PRE + 1 + buf->len);
- memcpy(wbuf + LWS_PRE + 1, buf->base, buf->len);
- wbuf[LWS_PRE] = OUTPUT;
+ char message[LWS_PRE + 1 + buf->len];
+ char *ptr= &message[LWS_PRE];
+
+ *ptr = OUTPUT;
+ memcpy(ptr + 1, buf->base, buf->len);
size_t n = buf->len + 1;
- if (lws_write(wsi, (unsigned char *) wbuf + LWS_PRE, n, LWS_WRITE_BINARY) < n) {
+
+ if (lws_write(wsi, (unsigned char *) ptr, n, LWS_WRITE_BINARY) < n) {
lwsl_err("write OUTPUT to WS\n");
}
- free(wbuf);
}
int callback_tty(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in,
free(handle);
}
-pty_buf_t *pty_buf_init(char *base, ssize_t len) {
+pty_buf_t *pty_buf_init(char *base, size_t len) {
pty_buf_t *buf = xmalloc(sizeof(pty_buf_t));
buf->base = xmalloc(len);
memcpy(buf->base, base, len);
io->read_cb(io->ctx, NULL, true);
goto done;
}
- io->read_cb(io->ctx, pty_buf_init(buf->base, n), false);
+ io->read_cb(io->ctx, pty_buf_init(buf->base, (size_t) n), false);
done:
free(buf->base);
typedef struct {
char *base;
- ssize_t len;
+ size_t len;
} pty_buf_t;
typedef void (*pty_read_cb)(void *, pty_buf_t *, bool);
void *ctx;
};
-pty_buf_t *pty_buf_init(char *base, ssize_t len);
+pty_buf_t *pty_buf_init(char *base, size_t len);
void pty_buf_free(pty_buf_t *buf);
pty_process *process_init(void *ctx, uv_loop_t *loop, char **argv);
bool process_running(pty_process *process);