X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flibpspp%2Fzip-writer.c;h=e286a7eb1c5f281ddc739d88ab9c3a33e57c512b;hb=f3eba902a0deb8e3ce93383de255f7e0d39921b5;hp=7e1a6ccc178f5b3e3956c0d3d1e5b1c8f469248b;hpb=9389f9870643a519cf69b84a9388a0a40315d903;p=pspp diff --git a/src/libpspp/zip-writer.c b/src/libpspp/zip-writer.c index 7e1a6ccc17..e286a7eb1c 100644 --- a/src/libpspp/zip-writer.c +++ b/src/libpspp/zip-writer.c @@ -1,5 +1,5 @@ /* 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 @@ -17,18 +17,19 @@ #include #include "libpspp/zip-writer.h" +#include "libpspp/zip-private.h" +#include #include #include #include -#include "libpspp/integer-format.h" - #include "gl/crc.h" -#include "gl/error.h" #include "gl/fwriteerror.h" #include "gl/xalloc.h" +#include "libpspp/message.h" + #include "gettext.h" #define _(msgid) gettext (msgid) @@ -62,16 +63,18 @@ put_bytes (struct zip_writer *zw, const void *p, size_t n) 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); } @@ -88,7 +91,7 @@ zip_writer_create (const char *file_name) file = fopen (file_name, "wb"); if (file == NULL) { - error (0, errno, _("%s: error opening output file"), file_name); + msg_error (errno, _("%s: error opening output file"), file_name); return NULL; } @@ -120,7 +123,7 @@ zip_writer_add (struct zip_writer *zw, FILE *file, const char *member_name) /* Local file header. */ offset = ftello (zw->file); - put_u32 (zw, 0x04034b50); /* local file header signature */ + 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 */ @@ -144,7 +147,7 @@ zip_writer_add (struct zip_writer *zw, FILE *file, const char *member_name) } /* Data descriptor. */ - put_u32 (zw, 0x08074b50); + put_u32 (zw, MAGIC_DDHD); put_u32 (zw, crc); put_u32 (zw, size); put_u32 (zw, size); @@ -179,7 +182,7 @@ zip_writer_close (struct zip_writer *zw) 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 */ @@ -203,7 +206,7 @@ zip_writer_close (struct zip_writer *zw) 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 */ @@ -221,7 +224,7 @@ zip_writer_close (struct zip_writer *zw) ok = true; else { - error (0, errno, _("%s: write failed"), zw->file_name); + msg_error (errno, _("%s: write failed"), zw->file_name); ok = false; }