From 72055744b9b243a3c4ccd02b62385e639f75ac68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20=C3=85strand?= Date: Thu, 4 Aug 2005 12:50:15 +0000 Subject: [PATCH] Created a common xstrdup function. git-svn-id: svn://svn.code.sf.net/p/rdesktop/code/trunk/rdesktop@973 423420c4-83ab-492f-b58f-81f9feb106b5 --- proto.h | 1 + rdesktop.c | 20 ++++++++++++++------ rdpsnd_oss.c | 2 +- rdpsnd_sun.c | 2 +- xkeymap.c | 7 +------ 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/proto.h b/proto.h index a5e8dd6..383104d 100644 --- a/proto.h +++ b/proto.h @@ -77,6 +77,7 @@ BOOL pstcache_init(uint8 cache_id); int main(int argc, char *argv[]); void generate_random(uint8 * random); void *xmalloc(int size); +char *xstrdup(const char *s); void *xrealloc(void *oldmem, int size); void xfree(void *mem); void error(char *format, ...); diff --git a/rdesktop.c b/rdesktop.c index 80bd7f0..f736ca0 100644 --- a/rdesktop.c +++ b/rdesktop.c @@ -382,12 +382,7 @@ main(int argc, char *argv[]) locale = setlocale(LC_ALL, ""); if (locale) { - locale = strdup(locale); - if (locale == NULL) - { - perror("strdup"); - exit(1); - } + locale = xstrdup(locale); } #endif @@ -941,6 +936,19 @@ xmalloc(int size) return mem; } +/* strdup */ +char * +xstrdup(const char *s) +{ + char *mem = strdup(s); + if (mem == NULL) + { + perror("strdup"); + exit(1); + } + return mem; +} + /* realloc; exit if out of memory */ void * xrealloc(void *oldmem, int size) diff --git a/rdpsnd_oss.c b/rdpsnd_oss.c index 1fe5965..020c9c5 100644 --- a/rdpsnd_oss.c +++ b/rdpsnd_oss.c @@ -50,7 +50,7 @@ wave_out_open(void) if (dsp_dev == NULL) { - dsp_dev = strdup("/dev/dsp"); + dsp_dev = xstrdup("/dev/dsp"); } if ((g_dsp_fd = open(dsp_dev, O_WRONLY | O_NONBLOCK)) == -1) diff --git a/rdpsnd_sun.c b/rdpsnd_sun.c index f86225f..2a9eee7 100644 --- a/rdpsnd_sun.c +++ b/rdpsnd_sun.c @@ -54,7 +54,7 @@ wave_out_open(void) if (dsp_dev == NULL) { - dsp_dev = strdup("/dev/audio"); + dsp_dev = xstrdup("/dev/audio"); } if ((g_dsp_fd = open(dsp_dev, O_WRONLY | O_NONBLOCK)) == -1) diff --git a/xkeymap.c b/xkeymap.c index 93a25c9..ccca3d1 100644 --- a/xkeymap.c +++ b/xkeymap.c @@ -166,12 +166,7 @@ xkeymap_from_locale(const char *locale) FILE *fp; /* Create a working copy */ - str = strdup(locale); - if (str == NULL) - { - perror("strdup"); - exit(1); - } + str = xstrdup(locale); /* Truncate at dot and at */ ptr = strrchr(str, '.');