]> diplodocus.org Git - nmh/commitdiff
Rewrite getcpy() using mh_x*() allocation functions.
authorRalph Corderoy <ralph@inputplus.co.uk>
Sun, 16 Oct 2016 23:08:26 +0000 (00:08 +0100)
committerRalph Corderoy <ralph@inputplus.co.uk>
Sun, 16 Oct 2016 23:08:26 +0000 (00:08 +0100)
h/prototypes.h
sbr/getcpy.c

index a6c412e2ff09e6ed53394a98f73a393259632016..f06322b508c6ef0fdb91c3132a7dc7bb09d740db 100644 (file)
@@ -167,7 +167,9 @@ char **getarguments (char *, int, char **, int);
  */
 char *get_charset(void);
 
  */
 char *get_charset(void);
 
-char *getcpy (const char *);
+/* Return malloc'd copy of str, or of "" if NULL, exit on failure. */
+char *getcpy(const char *str);
+
 char *get_default_editor(void);
 char *getfolder(int);
 
 char *get_default_editor(void);
 char *getfolder(int);
 
index 4d99a8036164747ecdd6e031f05d193a9d9663fa..32c8db437ff223317af65b877f7f293db34f7cc2 100644 (file)
 #include <h/mh.h>
 #include <h/utils.h>
 
 #include <h/mh.h>
 #include <h/utils.h>
 
-
-char *
-getcpy (const char *str)
+/* Return malloc'd copy of str, or of "" if NULL, exit on failure. */
+char *getcpy(const char *str)
 {
 {
-    char *cp;
-    size_t len;
+    if (str)
+        return mh_xstrdup(str);
 
 
-    if (str) {
-       len = strlen(str) + 1;
-       cp = mh_xmalloc (len);
-       memcpy (cp, str, len);
-    } else {
-       cp = mh_xmalloc ((size_t) 1);
-       *cp = '\0';
-    }
-    return cp;
+    return mh_xcalloc(1, 1);
 }
 }