From 16c70c9f2e041d4ff21f57c29be37e60be40c089 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Thu, 11 Feb 2010 21:53:38 -0800 Subject: [PATCH] odt: Restore writing creator metadata. Commit 4d7a2ed5 "odt: Remove dependency on because mingw32 does not have it" stopped writing creator metadata to ODT output files. This commit adds it back, but only on systems that have . This commit also adds avoids a null pointer dereference if getpwuid() returns NULL. That should happen only rarely, but it is best to handle it properly. At John Darrington's request. --- configure.ac | 2 +- src/output/odt.c | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index e5eb13a9..55bb24e4 100644 --- a/configure.ac +++ b/configure.ac @@ -194,7 +194,7 @@ fi PSPP_READLINE dnl Checks for header files. -AC_CHECK_HEADERS([sys/wait.h fpu_control.h ieeefp.h fenv.h]) +AC_CHECK_HEADERS([sys/wait.h fpu_control.h ieeefp.h fenv.h pwd.h]) # For gnulib. gl_INIT diff --git a/src/output/odt.c b/src/output/odt.c index 66e986be..99f5e60d 100644 --- a/src/output/odt.c +++ b/src/output/odt.c @@ -21,6 +21,9 @@ #include #include #include +#ifdef HAVE_PWD_H +#include +#endif #include #include #include @@ -268,6 +271,22 @@ write_meta_data (struct odt_driver *odt) xmlTextWriterEndElement (w); } +#ifdef HAVE_PWD_H + { + struct passwd *pw = getpwuid (getuid ()); + if (pw != NULL) + { + xmlTextWriterStartElement (w, _xml ("meta:initial-creator")); + xmlTextWriterWriteString (w, _xml (strtok (pw->pw_gecos, ","))); + xmlTextWriterEndElement (w); + + xmlTextWriterStartElement (w, _xml ("dc:creator")); + xmlTextWriterWriteString (w, _xml (strtok (pw->pw_gecos, ","))); + xmlTextWriterEndElement (w); + } + } +#endif + xmlTextWriterEndElement (w); xmlTextWriterEndElement (w); xmlTextWriterEndDocument (w); -- 2.30.2