Commit
4d7a2ed5 "odt: Remove dependency on <pwd.h> 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 <pwd.h>.
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.
PSPP_READLINE
dnl Checks for header files.
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])
#include <errno.h>
#include <libgen.h>
#include <libxml/xmlwriter.h>
#include <errno.h>
#include <libgen.h>
#include <libxml/xmlwriter.h>
+#ifdef HAVE_PWD_H
+#include <pwd.h>
+#endif
#include <sys/stat.h>
#include <sys/types.h>
#include <time.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <time.h>
xmlTextWriterEndElement (w);
}
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);
xmlTextWriterEndElement (w);
xmlTextWriterEndElement (w);
xmlTextWriterEndDocument (w);