Some portability fixes.
[gedcom-parse.git] / gedcom / write.c
index f8721da6cc91bab6fd841a150a586a9a79407831..e338b948c30108142a02cebe1e6c30b1e9c848ef 100644 (file)
@@ -26,7 +26,7 @@
 #include "encoding.h"
 #include "tag_data.h"
 #include "buffer.h"
-#include "utf8.h"
+#include "utf8tools.h"
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -127,13 +127,14 @@ int supports_continuation(int elt_or_rec, int which_continuation)
 int write_long(Gedcom_write_hndl hndl, int elt_or_rec,
               int level, char* xref, char* tag, char* value)
 {
-  int prefix_len, value_len, term_len;
-  char* nl_pos = strchr(value, '\n');
+  int prefix_len, value_len = 0, term_len;
+  char* nl_pos = NULL;
+  if (value) nl_pos = strchr(value, '\n');
 
   prefix_len = utf8_strlen(tag) + 3;  /* for e.g. "0 INDI " */
   if (level > 9) prefix_len++;
   if (xref)      prefix_len += utf8_strlen(xref) + 1;
-  value_len  = utf8_strlen(value);
+  if (value)     value_len  = utf8_strlen(value);
   term_len   = strlen(hndl->term);
 
   if (!nl_pos && prefix_len + value_len + term_len <= MAXWRITELEN)