ObjFW  Check-in [66b3f09fc0]

Overview
Comment:Win32 compatibility for the new file operations.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 66b3f09fc0229b445edeec6eaf3c427e35454080b0965bb156702dda139f87dd
User & Date: js on 2010-05-02 16:16:17
Other Links: manifest | tags
Context
2010-05-04
12:25
Only allow subclasses for +[replace*Method:with*MethodFromClass:]. check-in: 252833ad30 user: js tags: trunk
2010-05-02
16:16
Win32 compatibility for the new file operations. check-in: 66b3f09fc0 user: js tags: trunk
2010-04-30
14:19
Bump version to 0.4-dev. check-in: 0a92d8b607 user: js tags: trunk
Changes

Modified src/OFFile.m from [963472770a] to [bf7134d6ef].

37
38
39
40
41
42
43






44
45
46
47
48
49
50

#ifndef S_IRGRP
# define S_IRGRP 0
#endif
#ifndef S_IROTH
# define S_IROTH 0
#endif







#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

OFFile *of_stdin = nil;
OFFile *of_stdout = nil;
OFFile *of_stderr = nil;







>
>
>
>
>
>







37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56

#ifndef S_IRGRP
# define S_IRGRP 0
#endif
#ifndef S_IROTH
# define S_IROTH 0
#endif
#ifndef S_IWGRP
# define S_IWGRP 0
#endif
#ifndef S_IWOTH
# define S_IWOTH 0
#endif

#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

OFFile *of_stdin = nil;
OFFile *of_stdout = nil;
OFFile *of_stderr = nil;
112
113
114
115
116
117
118

119



120
121
122

123



124
125
126
127
128
129
130
	const char *path_c = [path cString];
	size_t path_len = [path cStringLength];
	ssize_t i;

	if (path_len == 0)
		return @"";


	if (path_c[path_len - 1] == OF_PATH_DELIM)



		path_len--;

	for (i = path_len - 1; i >= 0; i--) {

		if (path_c[i] == OF_PATH_DELIM) {



			i++;
			break;
		}
	}

	/*
	 * Only one component, but the trailing delimiter might have been







>

>
>
>



>

>
>
>







118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
	const char *path_c = [path cString];
	size_t path_len = [path cStringLength];
	ssize_t i;

	if (path_len == 0)
		return @"";

#ifndef _WIN32
	if (path_c[path_len - 1] == OF_PATH_DELIM)
#else
	if (path_c[path_len - 1] == '/' || path_c[path_len - 1] == '\\')
#endif
		path_len--;

	for (i = path_len - 1; i >= 0; i--) {
#ifndef _WIN32
		if (path_c[i] == OF_PATH_DELIM) {
#else
		if (path_c[i] == '/' || path_c[i] == '\\') {
#endif
			i++;
			break;
		}
	}

	/*
	 * Only one component, but the trailing delimiter might have been
314
315
316
317
318
319
320

321
322
323
324
325
326

327
328
329
330
331
332
333
		while (![src atEndOfStream]) {
			size_t len = [src readNBytes: 4096
					  intoBuffer: buf];
			[dest writeNBytes: len
			       fromBuffer: buf];
		}


		if (!override) {
			struct stat s;

			if (fstat(src->fd, &s) == 0)
				fchmod(dest->fd, s.st_mode);
		}

	} @finally {
		[src close];
		[dest close];
	}

	[pool release];
}







>






>







328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
		while (![src atEndOfStream]) {
			size_t len = [src readNBytes: 4096
					  intoBuffer: buf];
			[dest writeNBytes: len
			       fromBuffer: buf];
		}

#ifndef _WIN32
		if (!override) {
			struct stat s;

			if (fstat(src->fd, &s) == 0)
				fchmod(dest->fd, s.st_mode);
		}
#endif
	} @finally {
		[src close];
		[dest close];
	}

	[pool release];
}

Modified tests/OFFileTests.m from [d67d57f93a] to [b9b8be5676].

25
26
27
28
29
30
31
32
33
34
35
36
37
38
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];

	TEST(@"+[lastComponentOfPath",
	    [[OFFile lastComponentOfPath: @"/tmp"] isEqual: @"tmp"] &&
	    [[OFFile lastComponentOfPath: @"/tmp/"] isEqual: @"tmp"] &&
	    [[OFFile lastComponentOfPath: @"/"] isEqual: @""] &&
	    [[OFFile lastComponentOfPath: @"foo"] isEqual: @"foo"] /* &&
	    [[OFFile lastComponentOfPath: @"foo/bar"] isEqual: @"bar"] &&
	    [[OFFile lastComponentOfPath: @"foo/bar/baz/"] isEqual: @"baz"]*/)

	[pool drain];
}
@end







|

|




25
26
27
28
29
30
31
32
33
34
35
36
37
38
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];

	TEST(@"+[lastComponentOfPath",
	    [[OFFile lastComponentOfPath: @"/tmp"] isEqual: @"tmp"] &&
	    [[OFFile lastComponentOfPath: @"/tmp/"] isEqual: @"tmp"] &&
	    [[OFFile lastComponentOfPath: @"/"] isEqual: @""] &&
	    [[OFFile lastComponentOfPath: @"foo"] isEqual: @"foo"] &&
	    [[OFFile lastComponentOfPath: @"foo/bar"] isEqual: @"bar"] &&
	    [[OFFile lastComponentOfPath: @"foo/bar/baz/"] isEqual: @"baz"])

	[pool drain];
}
@end