From: Ben Pfaff Date: Fri, 12 Feb 2010 05:53:38 +0000 (-0800) Subject: odt: Restore writing creator metadata. X-Git-Tag: v0.7.4~6 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=16c70c9f2e041d4ff21f57c29be37e60be40c089;p=pspp-builds.git 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. --- 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);