str: Add function xstrdup_if_nonnull() and introduce many users.
[pspp] / src / libpspp / str.h
index 66552a396486133a7642366152f7d98b72151bf1..7917d58a70dd3a62e305ff84c6884aa85e7061cb 100644 (file)
@@ -29,6 +29,8 @@
 #include "memcasecmp.h"
 #include "xstrndup.h"
 #include "xvasprintf.h"
+
+#include "gl/xalloc.h"
 \f
 /* Miscellaneous. */
 
@@ -50,6 +52,8 @@ void str_lowercase (char *);
 bool str_format_26adic (unsigned long int number, bool uppercase,
                         char buffer[], size_t);
 
+static inline char *xstrdup_if_nonnull (const char *);
+
 void *mempset (void *, int, size_t);
 \f
 /* Common character classes for use with substring and string functions. */
@@ -281,4 +285,10 @@ ss_buffer (const char *buffer, size_t cnt)
   return ss;
 }
 
+static inline char *
+xstrdup_if_nonnull (const char *s)
+{
+  return s ? xstrdup (s) : NULL;
+}
+
 #endif /* str_h */