Index: configure.ac ================================================================== --- configure.ac +++ configure.ac @@ -2,17 +2,21 @@ AC_CONFIG_SRCDIR(src) AC_CANONICAL_HOST AC_CANONICAL_TARGET +AC_PROG_CC AC_PROG_OBJC AC_PROG_CPP AC_PROG_LN_S AC_PATH_PROG(AR, ar) +CFLAGS="$CFLAGS -Wall" +test x"$GCC" = x"yes" && CFLAGS="$CFLAGS -Werror -pipe -g" + OBJCFLAGS="$OBJCFLAGS -Wall" -test x"$GCC" = x"yes" && OBJCFLAGS="$OBJSFLAGS -Werror -pipe -g" +test x"$GCC" = x"yes" && OBJCFLAGS="$OBJCFLAGS -Werror -pipe -g" OBJCFLAGS="$OBJCFLAGS -fobjc-exceptions" BUILDSYS_SHARED_LIB AC_DEFINE(OF_CONFIG_H, 1, [Define so that we know we got our config.h]) @@ -27,10 +31,12 @@ AC_CHECK_LIB(objc, sel_getName, [ have_sel_getName="yes" AC_DEFINE(HAVE_SEL_GETNAME, 1, [Whether we have sel_getName])]) test x"$have_sel_get_name" != x"yes" -a x"$have_sel_getName" != x"yes" && \ AC_ERROR(You need either sel_get_name or sel_getName in libobjc!) + +AC_CHECK_FUNC(asprintf, AC_DEFINE(HAVE_ASPRINTF, 1, "Whether we have asprintf")) AC_MSG_CHECKING(whether we have IPv6 support) AC_TRY_RUN([ #include #include Index: m4/buildsys.m4 ================================================================== --- m4/buildsys.m4 +++ m4/buildsys.m4 @@ -96,11 +96,11 @@ LIB_SUFFIX='.dll' PLUGIN_CPPFLAGS='' PLUGIN_CFLAGS='' PLUGIN_LDFLAGS='-shared' PLUGIN_SUFFIX='.dll' - INSTALL_LIB='${INSTALL} -m 755 $$i ${DESTDIR}${bindir}/$$i && ${INSTALL} -m 755 $$i.a ${DESTDIR}${libdir}/$$i.a' + INSTALL_LIB='${MKDIR_P} ${DESTDIR}${bindir} && ${INSTALL} -m 755 $$i ${DESTDIR}${bindir}/$$i && ${INSTALL} -m 755 $$i.a ${DESTDIR}${libdir}/$$i.a' UNINSTALL_LIB='rm -f ${DESTDIR}${bindir}/$$i ${DESTDIR}${libdir}/$$i.a' CLEAN_LIB='${LIB}.a' ;; *) AC_MSG_RESULT(GNU) Index: src/Makefile ================================================================== --- src/Makefile +++ src/Makefile @@ -9,11 +9,12 @@ OFList.m \ OFListObject.m \ OFObject.m \ OFString.m \ OFTCPSocket.m \ - OFXMLFactory.m + OFXMLFactory.m \ + asprintf.c INCLUDES = ${SRCS:.m=.h} \ OFMacros.h \ OFStream.h Index: src/OFArray.m ================================================================== --- src/OFArray.m +++ src/OFArray.m @@ -18,10 +18,11 @@ #import "OFArray.h" #import "OFExceptions.h" #import "OFMacros.h" static size_t lastpagebyte = 0; +extern int getpagesize(void); @implementation OFArray + newWithItemSize: (size_t)is { return [[self alloc] initWithItemSize: is]; Index: src/OFExceptions.m ================================================================== --- src/OFExceptions.m +++ src/OFExceptions.m @@ -25,10 +25,14 @@ #elif defined HAVE_SEL_GETNAME #define SEL_NAME(x) sel_getName(x) #else #error "You need either sel_get_name() or sel_getName!" #endif + +#ifndef HAVE_ASPRINTF +#import "asprintf.h" +#endif @implementation OFException + newWithObject: (id)obj { return [[self alloc] initWithObject: obj]; Index: src/OFFile.h ================================================================== --- src/OFFile.h +++ src/OFFile.h @@ -8,11 +8,14 @@ * Q Public License 1.0, which can be found in the file LICENSE included in * the packaging of this file. */ #import + +#ifndef _WIN32 #import +#endif #import "OFObject.h" #import "OFStream.h" /** @@ -30,31 +33,39 @@ */ + newWithPath: (const char*)path andMode: (const char*)mode; /** * Changes the mode of a file. + * + * Not available on Windows. * * \param path The path to the file of which the mode should be changed as a * C string * \param mode The new mode for the file * \return A boolean whether the operation succeeded */ +#ifndef _WIN32 + (BOOL)changeModeOfFile: (const char*)path toMode: (mode_t)mode; +#endif /** * Changes the owner of a file. + * + * Not available on Windows. * * \param path The path to the file of which the owner should be changed as a * C string * \param owner The new owner for the file * \param group The new group for the file * \return A boolean whether the operation succeeded */ +#ifndef _WIN32 + (BOOL)changeOwnerOfFile: (const char*)path toOwner: (uid_t)owner andGroup: (gid_t)group; +#endif /** * Deletes a file. * * \param path The path to the file of which should be deleted as a C string @@ -62,27 +73,35 @@ */ + (BOOL)delete: (const char*)path; /** * Hardlinks a file. + * + * Not available on Windows. * * \param src The path to the file of which should be linked as a C string * \param dest The path to where the file should be linked as a C string * \return A boolean whether the operation succeeded */ +#ifndef _WIN32 + (BOOL)link: (const char*)src to: (const char*)dest; +#endif /** * Symlinks a file. + * + * Not available on Windows. * * \param src The path to the file of which should be symlinked as a C string * \param dest The path to where the file should be symlinked as a C string * \return A boolean whether the operation succeeded */ +#ifndef _WIN32 + (BOOL)symlink: (const char*)src to: (const char*)dest; +#endif /** * Initializes an already allocated OFFile. * * \param path The path to the file to open as a C string Index: src/OFFile.m ================================================================== --- src/OFFile.m +++ src/OFFile.m @@ -13,12 +13,14 @@ #import #import #import +#ifndef _WIN32 #import #import +#endif #import "OFFile.h" #import "OFExceptions.h" @implementation OFFile @@ -27,44 +29,50 @@ { return [[self alloc] initWithPath: path andMode: mode]; } +#ifndef _WIN32 + (BOOL)changeModeOfFile: (const char*)path - toMode: (mode_t)mode + toMode: (mode_t)mode { // FIXME: On error, throw exception return (chmod(path, mode) == 0 ? YES : NO); } +#endif +#ifndef _WIN32 + (BOOL)changeOwnerOfFile: (const char*)path - toOwner: (uid_t)owner - andGroup: (gid_t)group + toOwner: (uid_t)owner + andGroup: (gid_t)group { // FIXME: On error, throw exception return (chown(path, owner, group) == 0 ? YES : NO); } +#endif + (BOOL)delete: (const char*)path { // FIXME: On error, throw exception return (unlink(path) == 0 ? YES : NO); } +#ifndef _WIN32 + (BOOL)link: (const char*)src - to: (const char*)dest + to: (const char*)dest { // FIXME: On error, throw exception return (link(src, dest) == 0 ? YES : NO); } + (BOOL)symlink: (const char*)src - to: (const char*)dest + to: (const char*)dest { // FIXME: On error, throw exception return (symlink(src, dest) == 0 ? YES : NO); } +#endif - initWithPath: (const char*)path andMode: (const char*)mode { if ((self = [super init])) { Index: src/OFTCPSocket.h ================================================================== --- src/OFTCPSocket.h +++ src/OFTCPSocket.h @@ -9,17 +9,33 @@ * the packaging of this file. */ #import +/* + * Headers for UNIX systems + */ +#ifndef _WIN32 #import #import #import +#else +#endif #import "OFObject.h" #import "OFStream.h" +/* + * Headers for Win32 + * + * These must be imported after objc/Object and thus OFObject! + */ +#ifdef _WIN32 +#import +#import +#endif + /** * The OFTCPSocket class provides functions to create and use sockets. */ @interface OFTCPSocket: OFObject { Index: src/OFTCPSocket.m ================================================================== --- src/OFTCPSocket.m +++ src/OFTCPSocket.m @@ -17,10 +17,11 @@ #import #import "OFTCPSocket.h" #import "OFExceptions.h" +#ifndef _WIN32 /* FIXME */ @implementation OFTCPSocket - init { if ((self = [super init])) { sock = -1; @@ -272,5 +273,6 @@ saddr_len = 0; return self; } @end +#endif ADDED src/asprintf.c Index: src/asprintf.c ================================================================== --- src/asprintf.c +++ src/asprintf.c @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2008 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of libobjfw. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE included in + * the packaging of this file. + */ + +#include "config.h" + +#ifndef HAVE_ASPRINTF +#include +#include +#include + +int +asprintf(char **strp, const char *fmt, ...) +{ + size_t size; + va_list args; + + va_start(args, fmt); + + size = vsnprintf(NULL, 0, fmt, args); + if ((*strp = malloc(size)) == NULL) + return -1; + + return vsnprintf(*strp, size, fmt, args); +} +#endif ADDED src/asprintf.h Index: src/asprintf.h ================================================================== --- src/asprintf.h +++ src/asprintf.h @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2008 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of libobjfw. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE included in + * the packaging of this file. + */ + +extern int asprintf(char**, const char*, ...);