ObjFW  Check-in [142572f90b]

Overview
Comment:Initial attempt to port to win32.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 142572f90b31a970e6062d6ea422ab7031690edcd3ac800c3635caaa0c598c57
User & Date: js on 2008-12-13 19:25:35
Other Links: manifest | tags
Context
2008-12-13
19:39
Fix IPv6 check. check-in: c667d39616 user: js tags: trunk
19:25
Initial attempt to port to win32. check-in: 142572f90b user: js tags: trunk
18:25
Some build related changes.
Thanks to Thorsten Glaser for a few ideas.
check-in: 8740f97cb3 user: js tags: trunk
Changes

Modified configure.ac from [c09c61d130] to [9d1cb91406].

1
2
3
4
5
6

7
8
9
10
11



12
13

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31


32
33
34
35
36
37
38
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44






+





+
+
+

-
+


















+
+







AC_INIT(objfw, 0.1, js-objfw@webkeks.org)
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])
AC_C_BIGENDIAN([AC_DEFINE(OF_BIG_ENDIAN, 1, [Whether we are big endian])])

AC_CHECK_HEADER(objc/runtime.h,
	[AC_DEFINE(HAVE_OBJC_RUNTIME_H, 1, [Whether we have objc/runtime.h])])

AC_CHECK_LIB(objc, sel_get_name, [
	have_sel_get_name="yes"
	AC_DEFINE(HAVE_SEL_GET_NAME, 1, [Whether we have sel_get_name])])
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 <sys/types.h>
	#include <sys/socket.h>
	#include <netinet/in.h>

Modified m4/buildsys.m4 from [22afbe045e] to [9ad0cdb277].

94
95
96
97
98
99
100
101

102
103
104
105
106
107
108
94
95
96
97
98
99
100

101
102
103
104
105
106
107
108







-
+







			LIB_LDFLAGS='-shared -Wl,--out-implib,${LIB}.a'
			LIB_PREFIX='lib'
			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)
			LIB_CPPFLAGS='-DPIC'
			LIB_CFLAGS='-fPIC'

Modified src/Makefile from [152581fb22] to [fd8a00574a].

1
2
3
4
5
6
7
8
9
10
11
12
13
14


15
16
17
18
19
20
21
1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21
22













-
+
+







LIB = ${LIB_PREFIX}objfw${LIB_SUFFIX}
LIB_MAJOR = 1
LIB_MINOR = 0

SRCS = OFArray.m		\
       OFExceptions.m		\
       OFHashes.m		\
       OFFile.m			\
       OFList.m			\
       OFListObject.m		\
       OFObject.m		\
       OFString.m		\
       OFTCPSocket.m		\
       OFXMLFactory.m
       OFXMLFactory.m		\
       asprintf.c

INCLUDES = ${SRCS:.m=.h}	\
	   OFMacros.h		\
	   OFStream.h

include ../buildsys.mk

Modified src/OFArray.m from [e1c0bd1b7d] to [9150d2b2a3].

16
17
18
19
20
21
22

23
24
25
26
27
28
29
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30







+







#import <unistd.h>

#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];
}

Modified src/OFExceptions.m from [bdb764e78a] to [fe916bd7cf].

23
24
25
26
27
28
29




30
31
32
33
34
35
36
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40







+
+
+
+







#if defined HAVE_SEL_GET_NAME
#define SEL_NAME(x) sel_get_name(x)
#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];
}

Modified src/OFFile.h from [a86ed41196] to [3298445bd5].

1
2
3
4
5
6
7
8
9
10
11
12


13

14
15
16
17
18
19
20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23












+
+

+







/*
 * Copyright (c) 2008
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * 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.
 */

#import <stdio.h>

#ifndef _WIN32
#import <sys/types.h>
#endif

#import "OFObject.h"
#import "OFStream.h"

/**
 * The OFFile class provides functions to read, write and manipulate files.
 */
28
29
30
31
32
33
34


35
36
37
38
39
40

41
42

43
44
45


46
47
48
49
50
51
52

53
54
55

56
57
58
59
60
61
62
63
64
65
66


67
68
69
70
71

72
73

74
75
76


77
78
79
80
81

82
83

84
85
86
87
88
89
90
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109







+
+






+


+



+
+







+



+











+
+





+


+



+
+





+


+







 * \param mode The mode in which the file should be opened as a C string
 * \return A new OFFile
 */
+ 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
 * \return A boolean whether the operation succeeded
 */
+ (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
 * \param mode The mode in which the file should be opened as a C string
 * \return An initialized OFFile

Modified src/OFFile.m from [e3b833eee4] to [8a9dff998b].

11
12
13
14
15
16
17

18
19

20
21
22
23
24
25
26
27
28
29
30
31

32
33

34
35
36
37

38

39
40
41


42
43
44
45

46
47
48
49
50
51
52

53
54

55
56
57
58
59
60
61

62
63
64
65

66
67
68
69
70
71
72
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

36
37
38
39
40
41
42
43
44


45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60

61
62
63
64
65
66
67

68
69
70
71
72
73
74
75
76
77
78
79
80







+


+












+

-
+




+

+

-
-
+
+




+







+

-
+






-
+




+








#import "config.h"

#import <stdio.h>
#import <string.h>
#import <unistd.h>

#ifndef _WIN32
#import <sys/types.h>
#import <sys/stat.h>
#endif

#import "OFFile.h"
#import "OFExceptions.h"

@implementation OFFile
+ newWithPath: (const char*)path
      andMode: (const char*)mode
{
	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])) {
		if ((fp = fopen(path, mode)) == NULL)
			@throw [OFOpenFileFailedException newWithObject: self

Modified src/OFTCPSocket.h from [dc54bd8b6a] to [59b06f95cb].

1
2
3
4
5
6
7
8
9
10
11
12
13




14
15
16


17
18
19
20










21
22
23
24
25
26
27
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43













+
+
+
+



+
+




+
+
+
+
+
+
+
+
+
+







/*
 * Copyright (c) 2008
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * 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.
 */

#import <stdio.h>

/*
 * Headers for UNIX systems
 */
#ifndef _WIN32
#import <sys/types.h>
#import <sys/socket.h>
#import <netdb.h>
#else
#endif

#import "OFObject.h"
#import "OFStream.h"

/*
 * Headers for Win32
 *
 * These must be imported after objc/Object and thus OFObject!
 */
#ifdef _WIN32
#import <winsock2.h>
#import <ws2tcpip.h>
#endif

/**
 * The OFTCPSocket class provides functions to create and use sockets.
 */
@interface OFTCPSocket: OFObject <OFStream>
{
	int sock;
	struct sockaddr *saddr;

Modified src/OFTCPSocket.m from [c69f2ecab6] to [eaaeb57c56].

15
16
17
18
19
20
21

22
23
24
25
26
27
28
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29







+







#import <stdlib.h>
#import <string.h>
#import <unistd.h>

#import "OFTCPSocket.h"
#import "OFExceptions.h"

#ifndef _WIN32	/* FIXME */
@implementation OFTCPSocket
- init
{
	if ((self = [super init])) {
		sock = -1;
		saddr = NULL;
		saddr_len = 0;
270
271
272
273
274
275
276

271
272
273
274
275
276
277
278







+
	if (saddr != NULL)
		[self freeMem: saddr];
	saddr_len = 0;

	return self;
}
@end
#endif

Added src/asprintf.c version [d3bfd74e8f].


































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
/*
 * Copyright (c) 2008
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * 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 <stdio.h>
#include <stdlib.h>
#include <stdarg.h>

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 version [5cb7f85c1e].













1
2
3
4
5
6
7
8
9
10
11
12
+
+
+
+
+
+
+
+
+
+
+
+
/*
 * Copyright (c) 2008
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * 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*, ...);