tAdd xstrdup function - st - [fork] customized build of st, the simple terminal (HTM) git clone git://src.adamsgaard.dk/st (DIR) Log (DIR) Files (DIR) Refs (DIR) README (DIR) LICENSE --- (DIR) commit cdb3b1892af40110660da8c3f6fc06b1b054fd12 (DIR) parent 315b7ee9ce13603339104cab0402d7d6c10e92b8 (HTM) Author: Roberto E. Vargas Caballero <k0ga@shike2.com> Date: Sat, 1 Feb 2014 11:12:47 +0100 Add xstrdup function Since we are using xmalloc, xrealloc ..., then it is not logical call directly to strdup. Signed-off-by: Roberto E. Vargas Caballero <k0ga@shike2.com> Diffstat: M st.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) --- (DIR) diff --git a/st.c b/st.c t@@ -441,6 +441,7 @@ static int isfullutf8(char *, int); static ssize_t xwrite(int, char *, size_t); static void *xmalloc(size_t); static void *xrealloc(void *, size_t); +static char *xstrdup(char *s); static void (*handler[LASTEvent])(XEvent *) = { [KeyPress] = kpress, t@@ -529,6 +530,16 @@ xrealloc(void *p, size_t len) { return p; } +char * +xstrdup(char *s) { + char *p = strdup(s); + + if (!p) + die("Out of memory\n"); + + return p; +} + int utf8decode(char *s, long *u) { uchar c; t@@ -3789,7 +3800,7 @@ main(int argc, char *argv[]) { if(argc > 1) { opt_cmd = &argv[1]; if(argv[1] != NULL && opt_title == NULL) { - titles = strdup(argv[1]); + titles = xstrdup(argv[1]); opt_title = basename(titles); } }