diff options
Diffstat (limited to 'src/alloc.c')
| -rw-r--r-- | src/alloc.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/alloc.c b/src/alloc.c index 7f0a74ca834..7c671e25cfc 100644 --- a/src/alloc.c +++ b/src/alloc.c | |||
| @@ -850,6 +850,20 @@ xlispstrdup (Lisp_Object string) | |||
| 850 | return memcpy (xmalloc (size), SSDATA (string), size); | 850 | return memcpy (xmalloc (size), SSDATA (string), size); |
| 851 | } | 851 | } |
| 852 | 852 | ||
| 853 | /* Assign to *PTR a copy of STRING, freeing any storage *PTR formerly | ||
| 854 | pointed to. If STRING is null, assign it without copying anything. | ||
| 855 | Allocate before freeing, to avoid a dangling pointer if allocation | ||
| 856 | fails. */ | ||
| 857 | |||
| 858 | void | ||
| 859 | dupstring (char **ptr, char const *string) | ||
| 860 | { | ||
| 861 | char *old = *ptr; | ||
| 862 | *ptr = string ? xstrdup (string) : 0; | ||
| 863 | xfree (old); | ||
| 864 | } | ||
| 865 | |||
| 866 | |||
| 853 | /* Like putenv, but (1) use the equivalent of xmalloc and (2) the | 867 | /* Like putenv, but (1) use the equivalent of xmalloc and (2) the |
| 854 | argument is a const pointer. */ | 868 | argument is a const pointer. */ |
| 855 | 869 | ||