/* PSPP - a program for statistical analysis.
- Copyright (C) 2010 Free Software Foundation, Inc.
+ Copyright (C) 2010, 2012 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#include <config.h>
#include "libpspp/zip-writer.h"
+#include "libpspp/zip-private.h"
+#include <byteswap.h>
#include <errno.h>
#include <stdlib.h>
#include <time.h>
-#include "libpspp/integer-format.h"
-
#include "gl/crc.h"
#include "gl/error.h"
#include "gl/fwriteerror.h"
static void
put_u16 (struct zip_writer *zw, uint16_t x)
{
- if (INTEGER_NATIVE != INTEGER_LSB_FIRST)
- integer_convert (INTEGER_NATIVE, &x, INTEGER_MSB_FIRST, &x, sizeof x);
+#ifdef WORDS_BIGENDIAN
+ x = bswap_16 (x);
+#endif
put_bytes (zw, &x, sizeof x);
}
static void
put_u32 (struct zip_writer *zw, uint32_t x)
{
- if (INTEGER_NATIVE != INTEGER_LSB_FIRST)
- integer_convert (INTEGER_NATIVE, &x, INTEGER_MSB_FIRST, &x, sizeof x);
+#ifdef WORDS_BIGENDIAN
+ x = bswap_32 (x);
+#endif
put_bytes (zw, &x, sizeof x);
}
char buf[4096];
/* Local file header. */
- offset = ftell (zw->file);
- put_u32 (zw, 0x04034b50); /* local file header signature */
+ offset = ftello (zw->file);
+ put_u32 (zw, MAGIC_LHDR); /* local file header signature */
put_u16 (zw, 10); /* version needed to extract */
put_u16 (zw, 1 << 3); /* general purpose bit flag */
put_u16 (zw, 0); /* compression method */
/* File data. */
size = crc = 0;
- fseek (file, 0, SEEK_SET);
+ fseeko (file, 0, SEEK_SET);
while ((bytes_read = fread (buf, 1, sizeof buf, file)) > 0)
{
put_bytes (zw, buf, bytes_read);
}
/* Data descriptor. */
- put_u32 (zw, 0x08074b50);
+ put_u32 (zw, MAGIC_DDHD);
put_u32 (zw, crc);
put_u32 (zw, size);
put_u32 (zw, size);
if (zw == NULL)
return true;
- dir_start = ftell (zw->file);
+ dir_start = ftello (zw->file);
for (i = 0; i < zw->n_members; i++)
{
struct zip_member *m = &zw->members[i];
/* Central directory file header. */
- put_u32 (zw, 0x02014b50); /* central file header signature */
+ put_u32 (zw, MAGIC_SOCD); /* central file header signature */
put_u16 (zw, 63); /* version made by */
put_u16 (zw, 10); /* version needed to extract */
put_u16 (zw, 1 << 3); /* general purpose bit flag */
free (m->name);
}
free (zw->members);
- dir_end = ftell (zw->file);
+ dir_end = ftello (zw->file);
/* End of central directory record. */
- put_u32 (zw, 0x06054b50); /* end of central dir signature */
+ put_u32 (zw, MAGIC_EOCD); /* end of central dir signature */
put_u16 (zw, 0); /* number of this disk */
put_u16 (zw, 0); /* number of the disk with the
start of the central directory */