#include <unistd.h>
#include <errno.h>
+#include "config.h"
+
using namespace zipper;
const timeval zipper::s_now = {0,0};
m_fd(-1),
m_closeOnExit(true)
{
- m_fd = ::open(filename.c_str(), O_RDONLY);
+ m_fd = ::open(filename.c_str(), O_RDONLY | O_BINARY);
if (m_fd < 0)
{
#include <utime.h>
#include <errno.h>
+#include "config.h"
+
using namespace zipper;
class FileWriter::FileWriterImpl
m_fd =
::open(
filename.c_str(),
- O_WRONLY | O_TRUNC | O_CREAT,
+ O_WRONLY | O_TRUNC | O_CREAT | O_BINARY,
createPermissions);
if (m_fd < 0)
# You should have received a copy of the GNU General Public License
# along with libzipper. If not, see <http://www.gnu.org/licenses/>.
+AUTOMAKE_OPTIONS = subdir-objects
+
include doxygen.am
dist_noinst_SCRIPTS = \
port/strerror_posix.cc
endif
+if !HAVE_PREAD
+libzipper_la_SOURCES += \
+ port/pread.c
+endif
+
+if !HAVE_PWRITE
+libzipper_la_SOURCES += \
+ port/pwrite.c
+endif
+
+if !HAVE_UTIMES
+libzipper_la_SOURCES += \
+ port/utimes.c
+endif
+
# Public API headers go here, for installation to /usr/include
include_HEADERS = zipper.hh
+2014-12-18 Version 1.0.4
+ - mingw support for cross-compiling for a Windows target.
+
2011-10-05 Version 1.0.3
- Added Android NDK support
--- /dev/null
+// Copyright (C) 2014 Michael McMaster <michael@codesrc.com>
+//
+// This file is part of libzipper.
+//
+// libzipper is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// libzipper is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with libzipper. If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef zipper_config_h
+#define zipper_config_h
+
+#include "autoconfig.h"
+#include <sys/types.h>
+#include <sys/time.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef HAVE_PREAD
+// Use port/pread.c
+extern ssize_t pread(int fd, void *buf, size_t nbyte, off_t offset);
+#endif
+#ifndef HAVE_PWRITE
+// Use port/pwrite.c
+extern ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset);
+#endif
+
+#ifndef HAVE_UTIMES
+extern int utimes(const char *filename, const struct timeval times[2]);
+#endif
+
+// Thread un-safe alternative
+#ifndef HAVE_LOCALTIME_R
+#define localtime_r(timep, result) localtime( (timep) )
+#endif
+
+#ifdef _WIN32
+ #define MKDIR(file,mode) mkdir(file)
+#else
+ #define MKDIR(file,mode) mkdir(file,mode)
+
+ // no automagic CR/LF conversion undr mingw
+ #define O_BINARY 0
+#endif
+
+#ifdef __cplusplus
+// extern "C"
+}
+#endif
+
+#endif
AC_FUNC_STRERROR_R
AM_CONDITIONAL(HAVE_GNU_STRERROR,[test x$ac_cv_func_strerror_r_char_p = xyes])
+AC_CHECK_FUNCS([pread pwrite utimes localtime_r])
+AM_CONDITIONAL(HAVE_PREAD,[test x$ac_cv_func_pread = xyes])
+AM_CONDITIONAL(HAVE_PWRITE,[test x$ac_cv_func_pwrite = xyes])
+AM_CONDITIONAL(HAVE_UTIMES,[test x$ac_cv_func_utimes = xyes])
+
DX_DOXYGEN_FEATURE([ON])
DX_HTML_FEATURE([ON])
DX_CHM_FEATURE(OFF)
--- /dev/null
+/* replacement pread function
+ Copyright (C) 2009-2014 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
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <unistd.h>
+
+#include <errno.h>
+
+#define __libc_lseek(f,o,w) lseek (f, o, w)
+#define __set_errno(Val) errno = (Val)
+#define __libc_read(f,b,n) read (f, b, n)
+
+/* pread substitute for systems that the function, such as mingw32 and BeOS. */
+/* The following is identical to the function from glibc's
+ sysdeps/posix/pread.c */
+
+/* Note: This implementation of pread is not multithread-safe. */
+
+ssize_t
+pread (int fd, void *buf, size_t nbyte, off_t offset)
+{
+ /* Since we must not change the file pointer preserve the value so that
+ we can restore it later. */
+ int save_errno;
+ ssize_t result;
+ off_t old_offset = __libc_lseek (fd, 0, SEEK_CUR);
+ if (old_offset == (off_t) -1)
+ return -1;
+
+ /* Set to wanted position. */
+ if (__libc_lseek (fd, offset, SEEK_SET) == (off_t) -1)
+ return -1;
+
+ /* Write out the data. */
+ result = __libc_read (fd, buf, nbyte);
+
+ /* Now we have to restore the position. If this fails we have to
+ return this as an error. But if the writing also failed we
+ return this error. */
+ save_errno = errno;
+ if (__libc_lseek (fd, old_offset, SEEK_SET) == (off_t) -1)
+ {
+ if (result == -1)
+ __set_errno (save_errno);
+ return -1;
+ }
+ __set_errno (save_errno);
+
+ return result;
+}
--- /dev/null
+/* Write block to given position in file without changing file pointer.
+ POSIX version.
+ Copyright (C) 1997-1999, 2002, 2011-2014 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
+
+ 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
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <unistd.h>
+
+#include <errno.h>
+
+#define __libc_lseek(f,o,w) lseek (f, o, w)
+#define __set_errno(Val) errno = (Val)
+#define __libc_write(f,b,n) write (f, b, n)
+
+/* Note: This implementation of pwrite is not multithread-safe. */
+
+ssize_t
+pwrite (int fd, const void *buf, size_t nbyte, off_t offset)
+{
+ /* Since we must not change the file pointer preserve the value so that
+ we can restore it later. */
+ int save_errno;
+ ssize_t result;
+ off_t old_offset = __libc_lseek (fd, 0, SEEK_CUR);
+ if (old_offset == (off_t) -1)
+ return -1;
+
+ /* Set to wanted position. */
+ if (__libc_lseek (fd, offset, SEEK_SET) == (off_t) -1)
+ return -1;
+
+ /* Write out the data. */
+ result = __libc_write (fd, buf, nbyte);
+
+ /* Now we have to restore the position. If this fails we have to
+ return this as an error. But if the writing also failed we
+ return this error. */
+ save_errno = errno;
+ if (__libc_lseek (fd, old_offset, SEEK_SET) == (off_t) -1)
+ {
+ if (result == -1)
+ __set_errno (save_errno);
+ return -1;
+ }
+ __set_errno (save_errno);
+
+ return result;
+}
--- /dev/null
+// Copyright (C) 2014 Michael McMaster <michael@codesrc.com>
+//
+// This file is part of libzipper.
+//
+// libzipper is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// libzipper is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with libzipper. If not, see <http://www.gnu.org/licenses/>.
+
+#include <sys/types.h>
+#include <sys/time.h>
+#include <utime.h>
+
+// Replacement function using the older low-resolution utime function
+int utimes(const char *filename, const struct timeval times[2])
+{
+ struct utimbuf buf;
+ buf.actime = times[0].tv_sec;
+ buf.modtime = times[1].tv_sec;
+ return utime(filename, &buf);
+}
+
#include <time.h>
#include <string.h>
+#include "config.h"
+
using namespace zipper;
namespace
#include <sstream>
#include <string>
+#include "config.h"
+
using namespace zipper;
static std::string argv0;
++it)
{
builtPath << *it;
- int result(mkdir(builtPath.str().c_str(), 0775));
+ int result(MKDIR(builtPath.str().c_str(), 0775));
if (result != 0 && errno != EEXIST)
{
std::string errMsg(zipper::strerror(errno));