Created a common xstrdup function.

git-svn-id: svn://svn.code.sf.net/p/rdesktop/code/trunk/rdesktop@973 423420c4-83ab-492f-b58f-81f9feb106b5
This commit is contained in:
Peter Åstrand 2005-08-04 12:50:15 +00:00
parent 65b28a80a4
commit 72055744b9
5 changed files with 18 additions and 14 deletions

View File

@ -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, ...);

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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, '.');