diff options
| author | Roberto E. Vargas Caballero <k0ga@shike2.com> | 2014-02-01 11:12:47 +0100 |
|---|---|---|
| committer | Roberto E. Vargas Caballero <k0ga@shike2.com> | 2014-02-08 19:58:37 +0100 |
| commit | cdb3b1892af40110660da8c3f6fc06b1b054fd12 (patch) | |
| tree | 5fc8da65b8b76dcc64d1db2ace8b7eed556a666f | |
| parent | 315b7ee9ce13603339104cab0402d7d6c10e92b8 (diff) | |
| download | st-cdb3b1892af40110660da8c3f6fc06b1b054fd12.tar.gz st-cdb3b1892af40110660da8c3f6fc06b1b054fd12.zip | |
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>
| -rw-r--r-- | st.c | 13 |
1 files changed, 12 insertions, 1 deletions
| @@ -441,6 +441,7 @@ static int isfullutf8(char *, int); | |||
| 441 | static ssize_t xwrite(int, char *, size_t); | 441 | static ssize_t xwrite(int, char *, size_t); |
| 442 | static void *xmalloc(size_t); | 442 | static void *xmalloc(size_t); |
| 443 | static void *xrealloc(void *, size_t); | 443 | static void *xrealloc(void *, size_t); |
| 444 | static char *xstrdup(char *s); | ||
| 444 | 445 | ||
| 445 | static void (*handler[LASTEvent])(XEvent *) = { | 446 | static void (*handler[LASTEvent])(XEvent *) = { |
| 446 | [KeyPress] = kpress, | 447 | [KeyPress] = kpress, |
| @@ -529,6 +530,16 @@ xrealloc(void *p, size_t len) { | |||
| 529 | return p; | 530 | return p; |
| 530 | } | 531 | } |
| 531 | 532 | ||
| 533 | char * | ||
| 534 | xstrdup(char *s) { | ||
| 535 | char *p = strdup(s); | ||
| 536 | |||
| 537 | if (!p) | ||
| 538 | die("Out of memory\n"); | ||
| 539 | |||
| 540 | return p; | ||
| 541 | } | ||
| 542 | |||
| 532 | int | 543 | int |
| 533 | utf8decode(char *s, long *u) { | 544 | utf8decode(char *s, long *u) { |
| 534 | uchar c; | 545 | uchar c; |
| @@ -3789,7 +3800,7 @@ main(int argc, char *argv[]) { | |||
| 3789 | if(argc > 1) { | 3800 | if(argc > 1) { |
| 3790 | opt_cmd = &argv[1]; | 3801 | opt_cmd = &argv[1]; |
| 3791 | if(argv[1] != NULL && opt_title == NULL) { | 3802 | if(argv[1] != NULL && opt_title == NULL) { |
| 3792 | titles = strdup(argv[1]); | 3803 | titles = xstrdup(argv[1]); |
| 3793 | opt_title = basename(titles); | 3804 | opt_title = basename(titles); |
| 3794 | } | 3805 | } |
| 3795 | } | 3806 | } |
