diff options
author | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2002-10-21 04:05:48 (GMT) |
---|---|---|
committer | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2002-10-21 04:05:48 (GMT) |
commit | 0bcf2bb4749f1e164f0bfc25b325531d25efa5a5 (patch) | |
tree | fc009235b71f9d78a863122fdaa523b3806bb2c7 /plugins/utils.c | |
parent | 019b96a3ba9e9864151d91bb2d1ce25d2292f4b4 (diff) | |
download | monitoring-plugins-0bcf2bb4749f1e164f0bfc25b325531d25efa5a5.tar.gz |
use asprintf to do strscpy
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@150 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/utils.c')
-rw-r--r-- | plugins/utils.c | 20 |
1 files changed, 3 insertions, 17 deletions
diff --git a/plugins/utils.c b/plugins/utils.c index 697b5a6..a4519f2 100644 --- a/plugins/utils.c +++ b/plugins/utils.c | |||
@@ -353,13 +353,7 @@ strip (char *buffer) | |||
353 | 353 | ||
354 | /****************************************************************************** | 354 | /****************************************************************************** |
355 | * | 355 | * |
356 | * Copies one string to another | 356 | * Copies one string to another. Any previously existing data in |
357 | * | ||
358 | * Given a pointer destination string, which may or may not already | ||
359 | * hold some text, and a source string with additional text (possibly | ||
360 | * NULL or empty), returns a pointer to a a copy of the source | ||
361 | * string. Uses realloc to free memory held by the dest argument if | ||
362 | * new storage space is required, and any previously existing data in | ||
363 | * the destination string is lost. | 357 | * the destination string is lost. |
364 | * | 358 | * |
365 | * Example: | 359 | * Example: |
@@ -375,17 +369,9 @@ strscpy (char *dest, const char *src) | |||
375 | size_t len; | 369 | size_t len; |
376 | 370 | ||
377 | if (src == NULL) | 371 | if (src == NULL) |
378 | return dest; | 372 | return NULL; |
379 | |||
380 | len = strlen (src) + 1; | ||
381 | if (dest == NULL) | ||
382 | dest = malloc (len); | ||
383 | else if (strlen (dest) < len) | ||
384 | dest = realloc (dest, len); | ||
385 | if (dest == NULL) | ||
386 | terminate (STATE_UNKNOWN, "failed realloc in strscpy\n"); | ||
387 | 373 | ||
388 | strncpy (dest, src, len); | 374 | asprintf (&dest, "%s", src); |
389 | 375 | ||
390 | return dest; | 376 | return dest; |
391 | } | 377 | } |