These will have additional users in an upcoming commit.
#include "gl/xalloc.h"
#include "libpspp/message.h"
+#include "libpspp/temp-file.h"
#include "gettext.h"
#define _(msgid) gettext (msgid)
member->name = xstrdup (member_name);
}
+/* Adds a member named MEMBER_NAME whose contents is the null-terminated string
+ CONTENT. */
+void
+zip_writer_add_string (struct zip_writer *zw, const char *member_name,
+ const char *content)
+{
+ zip_writer_add_memory (zw, member_name, content, strlen (content));
+}
+
+/* Adds a member named MEMBER_NAME whose contents is the SIZE bytes of
+ CONTENT. */
+void
+zip_writer_add_memory (struct zip_writer *zw, const char *member_name,
+ const void *content, size_t size)
+{
+ FILE *fp = create_temp_file ();
+ if (fp == NULL)
+ {
+ msg_error (errno, _("error creating temporary file"));
+ zw->ok = false;
+ return;
+ }
+ fwrite (content, size, 1, fp);
+ zip_writer_add (zw, fp, member_name);
+ close_temp_file (fp);
+}
+
/* Finalizes the contents of ZW and closes it. Returns true if successful,
false if a write error occurred while finalizing the file or at any earlier
time. */
struct zip_writer *zip_writer_create (const char *file_name);
void zip_writer_add (struct zip_writer *, FILE *, const char *member_name);
+void zip_writer_add_string (struct zip_writer *, const char *member_name,
+ const char *content);
+void zip_writer_add_memory (struct zip_writer *, const char *member_name,
+ const void *content, size_t size);
bool zip_writer_close (struct zip_writer *);
#endif /* libpspp/zip-writer.h */
return UP_CAST (driver, struct odt_driver, driver);
}
-/* Create the "mimetype" file needed by ODF */
-static bool
-create_mimetype (struct zip_writer *zip)
-{
- FILE *fp;
-
- fp = create_temp_file ();
- if (fp == NULL)
- {
- msg_error (errno, _("error creating temporary file"));
- return false;
- }
-
- fprintf (fp, "application/vnd.oasis.opendocument.text");
- zip_writer_add (zip, fp, "mimetype");
- close_temp_file (fp);
-
- return true;
-}
-
/* Creates a new temporary file and stores it in *FILE, then creates an XML
writer for it and stores it in *W. */
static void
odt->handle = fh;
odt->file_name = xstrdup (file_name);
- if (!create_mimetype (zip))
- {
- output_driver_destroy (d);
- return NULL;
- }
+ zip_writer_add_string (zip, "mimetype",
+ "application/vnd.oasis.opendocument.text");
/* Create the manifest */
create_writer (&odt->manifest_file, &odt->manifest_wtr);