rows = json_object_get_int(o);
json_object_put(obj);
- struct winsize *size = t_malloc(sizeof(struct winsize));
+ struct winsize *size = xmalloc(sizeof(struct winsize));
memset(size, 0, sizeof(struct winsize));
size->ws_col = (unsigned short) columns;
size->ws_row = (unsigned short) rows;
// free the buffer
if (client->buffer != NULL)
- t_free(client->buffer);
+ free(client->buffer);
// remove from clients list
pthread_mutex_lock(&server->lock);
if (FD_ISSET (pty, &des_set)) {
memset(buf, 0, BUF_SIZE);
bytes = (int) read(pty, buf, BUF_SIZE);
- struct pty_data *frame = (struct pty_data *) t_malloc(sizeof(struct pty_data));
+ struct pty_data *frame = (struct pty_data *) xmalloc(sizeof(struct pty_data));
frame->len = bytes;
if (bytes > 0) {
- frame->data = t_malloc((size_t) bytes);
+ frame->data = xmalloc((size_t) bytes);
memcpy(frame->data, buf, bytes);
}
pthread_mutex_lock(&client->lock);
// read error or client exited, close connection
if (frame->len <= 0) {
STAILQ_REMOVE_HEAD(&client->queue, list);
- t_free(frame);
+ free(frame);
return -1;
}
unsigned char *p = &message[LWS_PRE];
size_t n = sprintf((char *) p, "%c%s", OUTPUT, b64_text);
- t_free(b64_text);
+ free(b64_text);
if (lws_write(wsi, p, n, LWS_WRITE_TEXT) < n) {
lwsl_err("lws_write\n");
}
STAILQ_REMOVE_HEAD(&client->queue, list);
- t_free(frame->data);
- t_free(frame);
+ free(frame->data);
+ free(frame);
if (lws_partial_buffered(wsi)) {
lws_callback_on_writable(wsi);
case LWS_CALLBACK_RECEIVE:
if (client->buffer == NULL) {
- client->buffer = t_malloc(len + 1);
+ client->buffer = xmalloc(len + 1);
client->len = len;
memcpy(client->buffer, in, len);
} else {
- client->buffer = t_realloc(client->buffer, client->len + len + 1);
+ client->buffer = xrealloc(client->buffer, client->len + len + 1);
memcpy(client->buffer + client->len, in, len);
client->len += len;
}
if (ioctl(client->pty, TIOCSWINSZ, size) == -1) {
lwsl_err("ioctl TIOCSWINSZ: %d (%s)\n", errno, strerror(errno));
}
- t_free(size);
+ free(size);
}
break;
case JSON_DATA:
}
if (client->buffer != NULL) {
- t_free(client->buffer);
+ free(client->buffer);
client->buffer = NULL;
}
break;
struct tty_server *ts;
size_t cmd_len = 0;
- ts = t_malloc(sizeof(struct tty_server));
+ ts = xmalloc(sizeof(struct tty_server));
memset(ts, 0, sizeof(struct tty_server));
LIST_INIT(&ts->clients);
int cmd_argc = argc - start;
char **cmd_argv = &argv[start];
- ts->argv = t_malloc(sizeof(char *) * (cmd_argc + 1));
+ ts->argv = xmalloc(sizeof(char *) * (cmd_argc + 1));
for (int i = 0; i < cmd_argc; i++) {
ts->argv[i] = strdup(cmd_argv[i]);
cmd_len += strlen(ts->argv[i]);
}
ts->argv[cmd_argc] = NULL;
- ts->command = t_malloc(cmd_len);
+ ts->command = xmalloc(cmd_len);
char *ptr = ts->command;
for (int i = 0; i < cmd_argc; i++) {
ptr = stpcpy(ptr, ts->argv[i]);
calc_command_start(int argc, char **argv) {
// make a copy of argc and argv
int argc_copy = argc;
- char **argv_copy = t_malloc(sizeof(char *) * argc);
+ char **argv_copy = xmalloc(sizeof(char *) * argc);
for (int i = 0; i < argc; i++) {
argv_copy[i] = strdup(argv[i]);
}
// free argv copy
for (int i = 0; i < argc; i++) {
- t_free(argv_copy[i]);
+ free(argv_copy[i]);
}
- t_free(argv_copy);
+ free(argv_copy);
// reset for next use
opterr = 1;
return -1;
}
char *value = strsep(&option, "=");
- t_free(option);
+ free(option);
struct json_object *obj = json_tokener_parse(value);
json_object_object_add(client_prefs, key, obj != NULL ? obj : json_object_new_string(value));
}
// cleanup
if (server->credential != NULL)
- t_free(server->credential);
- t_free(server->command);
- t_free(server->prefs_json);
+ free(server->credential);
+ free(server->command);
+ free(server->prefs_json);
int i = 0;
do {
- t_free(server->argv[i++]);
+ free(server->argv[i++]);
} while (server->argv[i] != NULL);
- t_free(server->argv);
- t_free(server->sig_name);
- t_free(server);
+ free(server->argv);
+ free(server->sig_name);
+ free(server);
return 0;
}
#include <string.h>
#include <signal.h>
-// http://web.mit.edu/~svalente/src/kill/kill.c
-#ifdef __linux__
-/*
- * sys_signame -- an ordered list of signals.
- * lifted from /usr/include/linux/signal.h
- * this particular order is only correct for linux.
- * this is _not_ portable.
- */
-const char *sys_signame[NSIG] = {
- "zero", "HUP", "INT", "QUIT", "ILL", "TRAP", "IOT", "UNUSED",
- "FPE", "KILL", "USR1", "SEGV", "USR2", "PIPE", "ALRM", "TERM",
- "STKFLT","CHLD", "CONT", "STOP", "TSTP", "TTIN", "TTOU", "IO",
- "XCPU", "XFSZ", "VTALRM","PROF", "WINCH", NULL
-};
-#endif
-
-#ifdef __CYGWIN__
-#define SIG_NAME(x) strsignal(x)
-#else
-#define SIG_NAME(x) sys_signame[x]
-#endif
-
void *
-t_malloc(size_t size) {
+xmalloc(size_t size) {
if (size == 0)
return NULL;
void *p = malloc(size);
return p;
}
-void t_free(void *p) {
- free(p);
-}
-
void *
-t_realloc(void *p, size_t size) {
+xrealloc(void *p, size_t size) {
if ((size == 0) && (p == NULL))
return NULL;
p = realloc(p, size);
int
get_sig_name(int sig, char *buf) {
- int n = sprintf(buf, "SIG%s", sig < NSIG ? SIG_NAME(sig) : "unknown");
+ int n = sprintf(buf, "SIG%s", sig < NSIG ? strsignal(sig) : "unknown");
uppercase(buf);
return n;
}
return -1;
}
for (int sig = 1; sig < NSIG; sig++) {
- const char *name = SIG_NAME(sig);
+ const char *name = strsignal(sig);
if (strcasecmp(name, sig_name + 3) == 0)
return sig;
}
int i_shift = 0;
int bytes_remaining = (int) length;
- ret = dst = t_malloc((size_t) (((length + 2) / 3 * 4) + 1));
+ ret = dst = xmalloc((size_t) (((length + 2) / 3 * 4) + 1));
while (bytes_remaining) {
i_bits = (i_bits << 8) + *buffer++;
bytes_remaining--;
// malloc with NULL check
void *
-t_malloc(size_t size);
-
-// free with NULL check
-void
-t_free(void *p);
+xmalloc(size_t size);
// realloc with NULL check
void *
-t_realloc(void *p, size_t size);
+xrealloc(void *p, size_t size);
// Convert a string to upper case
char *