ObjFW  Check-in [c01ed004b0]

Overview
Comment:Better checks for functions used in OFFile.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: c01ed004b016b6024db250ccc6d35e6195deb81d7917baae002d643d1b9c4723
User & Date: js on 2013-04-26 22:25:13
Other Links: manifest | tags
Context
2013-04-26
22:32
Check for sysconf(). check-in: 3f7dee97e8 user: js tags: trunk
22:25
Better checks for functions used in OFFile. check-in: c01ed004b0 user: js tags: trunk
21:10
Use nanosleep() if available. check-in: db70226153 user: js tags: trunk
Changes

Modified configure.ac from [5b0cf6b041] to [0e15f6a1ab].

329
330
331
332
333
334
335
336

337
338
339
340
341
342
343
329
330
331
332
333
334
335

336
337
338
339
340
341
342
343







-
+








AC_CHECK_FUNC(objc_autoreleasePoolPush, [], [
	AC_SUBST(AUTORELEASE_M, "autorelease.m")
])

AC_CHECK_FUNC(objc_enumerationMutation, [
	AC_DEFINE(HAVE_OBJC_ENUMERATIONMUTATION, 1,
		[Whether we have objc_enumerationMutation])
		[Whether we have objc_enumerationMutation()])
])

case "$host_os" in
	darwin*)
		AC_SUBST(LDFLAGS_REEXPORT, ["-Wl,-reexport-lobjfw"])
		AS_IF([test x"$objc_runtime" = x"Apple runtime"], [
			AC_SUBST(REEXPORT_LIBOBJC, ["-Wl,-reexport-lobjc"])
415
416
417
418
419
420
421
422

423
424
425
426
427
428
429
415
416
417
418
419
420
421

422
423
424
425
426
427
428
429







-
+







			have_asprintf="no"
			AC_SUBST(ASPRINTF_M, "asprintf.m")
			ac_cv_snprintf_useful_ret="yes"
			;;
		*)
			have_asprintf="yes"
			AC_DEFINE(OF_HAVE_ASPRINTF, 1,
				[Whether we have asprintf])
				[Whether we have asprintf()])
			AC_SUBST(ASPRINTF_DEF, "-DOF_HAVE_ASPRINTF")
		;;
	esac
], [
	have_asprintf="no"
	AC_SUBST(ASPRINTF_M, "asprintf.m")

489
490
491
492
493
494
495
496

497
498
499
500
501
502
503
489
490
491
492
493
494
495

496
497
498
499
500
501
502
503







-
+







			AC_CHECK_FUNC(pthread_spin_lock, [
				AC_DEFINE(OF_HAVE_PTHREAD_SPINLOCKS, 1,
					[Whether we have pthread spinlocks])
			])

			AC_CHECK_FUNC(sched_yield, [
				AC_DEFINE(OF_HAVE_SCHED_YIELD, 1,
					[Whether we have sched_yield])
					[Whether we have sched_yield()])
			])
		], [
			AC_MSG_ERROR(No supported threads found!)
		])
		;;
	esac

570
571
572
573
574
575
576














577
578
579
580
581
582
583
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597







+
+
+
+
+
+
+
+
+
+
+
+
+
+







AS_IF([test x"$atomic_ops" != x"none"], [
	AC_DEFINE(OF_HAVE_ATOMIC_OPS, 1, [Whether we have atomic operations])
	AC_SUBST(ATOMIC_H, "atomic.h")
])
AC_MSG_RESULT($atomic_ops)

AC_CHECK_FUNCS([gmtime_r localtime_r nanosleep])

AC_CHECK_HEADERS([pwd.h grp.h])
AC_CHECK_FUNC(chmod, [
	AC_DEFINE(OF_HAVE_CHMOD, 1, [Whether we have chmod()])
])
AC_CHECK_FUNC(chown, [
	AC_DEFINE(OF_HAVE_CHOWN, 1, [Whether we have chown()])
])
AC_CHECK_FUNC(link, [
	AC_DEFINE(OF_HAVE_LINK, 1, [Whether we have link()])
])
AC_CHECK_FUNC(symlink, [
	AC_DEFINE(OF_HAVE_SYMLINK, 1, [Whether we have symlink()])
])

AC_ARG_ENABLE(sockets,
	AS_HELP_STRING([--disable-sockets], [disable socket support]))
AS_IF([test x"$enable_sockets" != x"no"], [
	AC_DEFINE(OF_HAVE_SOCKETS, 1, [Whether we have sockets])
	AC_SUBST(USE_SRCS_SOCKETS, '${SRCS_SOCKETS}')

616
617
618
619
620
621
622
623

624
625
626
627
628
629
630
630
631
632
633
634
635
636

637
638
639
640
641
642
643
644







-
+







		# include <ws2tcpip.h>
		#endif
	], [
		struct addrinfo ai;
		getaddrinfo(NULL, NULL, NULL, NULL);
	], [
		AC_MSG_RESULT(yes)
		AC_DEFINE(HAVE_GETADDRINFO, 1, [Whether we have getaddrinfo])
		AC_DEFINE(HAVE_GETADDRINFO, 1, [Whether we have getaddrinfo()])

		AS_IF([test x"$enable_threads" != x"no"], [
			AC_MSG_CHECKING(whether getaddrinfo is thread-safe)

			case "$host_os" in
				darwin[[12345]].*)
					have_threadsafe_getaddrinfo="no"

Modified src/OFFile.h from [bad7a67060] to [2f0e7153ad].

144
145
146
147
148
149
150
151

152
153
154
155
156
157
158
159
160
161
162
163
164
165

166
167
168
169
170
171
172
144
145
146
147
148
149
150

151
152
153
154
155
156
157
158
159
160
161
162
163
164

165
166
167
168
169
170
171
172







-
+













-
+







/*!
 * @brief Returns the date of the last modification of the file.
 *
 * @return The date of the last modification of the file
 */
+ (OFDate*)modificationDateOfFileAtPath: (OFString*)path;

#ifndef _PSP
#ifdef OF_HAVE_CHMOD
/*!
 * @brief Changes the mode of a file.
 *
 * Only changes read-only flag on Windows.
 *
 * @param path The path to the file of which the mode should be changed as a
 *	       string
 * @param mode The new mode for the file
 */
+ (void)changeModeOfFileAtPath: (OFString*)path
			  mode: (mode_t)mode;
#endif

#if !defined(_WIN32) && !defined(_PSP)
#ifdef OF_HAVE_CHOWN
/*!
 * @brief 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
 *	       string
206
207
208
209
210
211
212
213

214
215
216
217
218
219
220
221
222
223
224
225
226

227
228
229
230
231
232
233
206
207
208
209
210
211
212

213
214
215
216
217
218
219
220
221
222
223
224
225

226
227
228
229
230
231
232
233







-
+












-
+







/*!
 * @brief Deletes an empty directory.
 *
 * @param path The path to the directory which should be deleted as a string
 */
+ (void)deleteDirectoryAtPath: (OFString*)path;

#ifndef _WIN32
#ifdef OF_HAVE_LINK
/*!
 * @brief Creates a hard link for a file.
 *
 * Not available on Windows.
 *
 * @param source The path to the file of which should be linked as a string
 * @param destination The path to where the file should be linked as a string
 */
+ (void)linkFileAtPath: (OFString*)source
		toPath: (OFString*)destination;
#endif

#if !defined(_WIN32) && !defined(_PSP)
#ifdef OF_HAVE_SYMLINK
/*!
 * @brief Creates a symbolink link for a file.
 *
 * Not available on Windows.
 *
 * @param source The path to the file of which should be symlinked as a string
 * @param destination The path to where the file should be symlinked as a string

Modified src/OFFile.m from [6182cd74e1] to [526afc5ebd].

31
32
33
34
35
36
37
38

39


40
41
42
43
44
45
46
31
32
33
34
35
36
37

38
39
40
41
42
43
44
45
46
47
48







-
+

+
+







#include <unistd.h>

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <dirent.h>

#ifndef _WIN32
#ifdef HAVE_PWD_H
# include <pwd.h>
#endif
#ifdef HAVE_GRP_H
# include <grp.h>
#endif

#import "OFFile.h"
#import "OFString.h"
#import "OFArray.h"
#ifdef OF_HAVE_THREADS
97
98
99
100
101
102
103
104

105
106
107
108
109
110
111
99
100
101
102
103
104
105

106
107
108
109
110
111
112
113







-
+







#define DEFAULT_MODE S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH
#define DIR_MODE DEFAULT_MODE | S_IXUSR | S_IXGRP | S_IXOTH

OFStream *of_stdin = nil;
OFStream *of_stdout = nil;
OFStream *of_stderr = nil;

#if defined(OF_HAVE_THREADS) && !defined(_WIN32)
#if defined(OF_HAVE_CHOWN) && defined(OF_HAVE_THREADS)
static of_mutex_t mutex;
#endif

static int parse_mode(const char *mode)
{
	if (!strcmp(mode, "r"))
		return O_RDONLY;
158
159
160
161
162
163
164
165

166
167
168
169
170
171
172
160
161
162
163
164
165
166

167
168
169
170
171
172
173
174







-
+







	objc_autoreleasePoolPop(pool);
}

@interface OFFileSingleton: OFFile
@end

@implementation OFFile
#if defined(OF_HAVE_THREADS) && !defined(_WIN32)
#if defined(OF_HAVE_CHOWN) && defined(OF_HAVE_THREADS)
+ (void)initialize
{
	if (self != [OFFile class])
		return;

	if (!of_mutex_new(&mutex))
		@throw [OFInitializationFailedException
385
386
387
388
389
390
391
392

393
394
395
396
397
398
399
387
388
389
390
391
392
393

394
395
396
397
398
399
400
401







-
+







	if (_wchdir([path UTF16String]))
#endif
		@throw [OFChangeDirectoryFailedException
		    exceptionWithClass: self
				  path: path];
}

#ifndef _PSP
#ifdef OF_HAVE_CHMOD
+ (void)changeModeOfFileAtPath: (OFString*)path
			  mode: (mode_t)mode
{
# ifndef _WIN32
	if (chmod([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE], mode))
# else
	if (_wchmod([path UTF16String], mode))
442
443
444
445
446
447
448
449

450
451
452
453
454
455
456
444
445
446
447
448
449
450

451
452
453
454
455
456
457
458







-
+







								path: path
								mode: @"r"];

	/* FIXME: We could be more precise on some OSes */
	return [OFDate dateWithTimeIntervalSince1970: s.st_mtime];
}

#if !defined(_WIN32) && !defined(_PSP)
#ifdef OF_HAVE_CHOWN
+ (void)changeOwnerOfFileAtPath: (OFString*)path
			  owner: (OFString*)owner
			  group: (OFString*)group
{
	uid_t uid = -1;
	gid_t gid = -1;

543
544
545
546
547
548
549
550

551
552
553
554
555
556
557
545
546
547
548
549
550
551

552
553
554
555
556
557
558
559







-
+








			length = [sourceFile readIntoBuffer: buffer
						     length: pageSize];
			[destinationFile writeBuffer: buffer
					      length: length];
		}

#if !defined(_WIN32) && !defined(_PSP)
#ifdef OF_HAVE_CHMOD
		if (!override) {
			struct stat s;

			if (fstat(sourceFile->_fd, &s) == 0)
				fchmod(destinationFile->_fd, s.st_mode);
		}
#else
610
611
612
613
614
615
616
617

618
619
620
621
622
623
624
612
613
614
615
616
617
618

619
620
621
622
623
624
625
626







-
+







	if (_wrmdir([path UTF16String]))
#endif
		@throw [OFDeleteDirectoryFailedException
		    exceptionWithClass: self
				  path: path];
}

#ifndef _WIN32
#ifdef OF_HAVE_LINK
+ (void)linkFileAtPath: (OFString*)source
		toPath: (OFString*)destination
{
	void *pool = objc_autoreleasePoolPush();

	if ([self directoryExistsAtPath: destination]) {
		OFString *filename = [source lastPathComponent];
632
633
634
635
636
637
638
639

640
641
642
643
644
645
646
634
635
636
637
638
639
640

641
642
643
644
645
646
647
648







-
+







						      sourcePath: source
						 destinationPath: destination];

	objc_autoreleasePoolPop(pool);
}
#endif

#if !defined(_WIN32) && !defined(_PSP)
#ifdef OF_HAVE_SYMLINK
+ (void)symlinkFileAtPath: (OFString*)source
		   toPath: (OFString*)destination
{
	void *pool = objc_autoreleasePoolPush();

	if ([self directoryExistsAtPath: destination]) {
		OFString *filename = [source lastPathComponent];

Modified src/OFThread.m from [64480ed795] to [cdfc8ccff6].

14
15
16
17
18
19
20

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







+







 * file.
 */

#include "config.h"

#define OF_THREAD_M

#define _POSIX_TIMERS
#define __NO_EXT_QNX

#include <stdlib.h>
#include <math.h>
#include <time.h>

#ifndef _WIN32

Modified src/objfw-defs.h.in from [aa207557bf] to [3af4f4e1ad].

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
24





+
+



+









+



#undef OF_APPLE_RUNTIME
#undef OF_BIG_ENDIAN
#undef OF_FLOAT_BIG_ENDIAN
#undef OF_HAVE_ASPRINTF
#undef OF_HAVE_ATOMIC_OPS
#undef OF_HAVE_CHMOD
#undef OF_HAVE_CHOWN
#undef OF_HAVE_COMPILER_TLS
#undef OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR
#undef OF_HAVE_GCC_ATOMIC_OPS
#undef OF_HAVE_LINK
#undef OF_HAVE_OSATOMIC
#undef OF_HAVE_OSATOMIC_64
#undef OF_HAVE_PTHREADS
#undef OF_HAVE_PLUGINS
#undef OF_HAVE_PROCESSES
#undef OF_HAVE_PTHREAD_SPINLOCKS
#undef OF_HAVE_RECURSIVE_PTHREAD_MUTEXES
#undef OF_HAVE_SCHED_YIELD
#undef OF_HAVE_SOCKETS
#undef OF_HAVE_SYMLINK
#undef OF_HAVE_THREADS
#undef OF_OBJFW_RUNTIME
#undef SIZE_MAX