ObjFW  Check-in [c9e9ea561c]

Overview
Comment:Don't define methods unavailable on Windows.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: c9e9ea561cd86feaf16e08d5517c70125f56fa2c184a353a307e73f0a4a203b7
User & Date: js on 2010-01-30 14:26:42
Other Links: manifest | tags
Context
2010-01-30
15:47
Make OFEnumerator more general, implement it for OFArray & OFDictionary. check-in: daae7ffbf3 user: js tags: trunk
14:26
Don't define methods unavailable on Windows. check-in: c9e9ea561c user: js tags: trunk
14:14
Fix missing includes and typos. check-in: 35f59c61c6 user: js tags: trunk
Changes

Modified src/OFExceptions.h from [da2deb8e90] to [84921b5752].

1
2
3
4
5
6
7
8
9
10
11

12
13
14
15
16
17
18
19
20
/*
 * Copyright (c) 2008 - 2009
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * All rights reserved.
 *
 * This file is part of ObjFW. 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 "OFObject.h"
#import "OFFile.h"

@class OFString;

/**
 * An exception indicating an object could not be allocated.
 *
 * This exception is preallocated, as if there's no memory, no exception can











>
|
|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
 * Copyright (c) 2008 - 2009
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * All rights reserved.
 *
 * This file is part of ObjFW. 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 <sys/stat.h>

#import "OFObject.h"

@class OFString;

/**
 * An exception indicating an object could not be allocated.
 *
 * This exception is preallocated, as if there's no memory, no exception can
374
375
376
377
378
379
380

381
382
383
384
385
386
387

/**
 * \return The new mode for the file
 */
- (mode_t)mode;
@end


/**
 * An OFException indicating that changing the owner of the file failed.
 */
@interface OFChangeFileOwnerFailedException: OFException
{
	OFString *path;
	uid_t owner;







>







375
376
377
378
379
380
381
382
383
384
385
386
387
388
389

/**
 * \return The new mode for the file
 */
- (mode_t)mode;
@end

#ifndef _WIN32
/**
 * An OFException indicating that changing the owner of the file failed.
 */
@interface OFChangeFileOwnerFailedException: OFException
{
	OFString *path;
	uid_t owner;
431
432
433
434
435
436
437

438
439
440
441
442
443
444
- (uid_t)owner;

/**
 * \return The new group for the file
 */
- (gid_t)group;
@end


/**
 * An OFException indicating that renaming a file failed.
 */
@interface OFRenameFileFailedException: OFException
{
	OFString *from;







>







433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
- (uid_t)owner;

/**
 * \return The new group for the file
 */
- (gid_t)group;
@end
#endif

/**
 * An OFException indicating that renaming a file failed.
 */
@interface OFRenameFileFailedException: OFException
{
	OFString *from;
518
519
520
521
522
523
524

525
526
527
528
529
530
531

/**
 * \return The path of the file
 */
- (OFString*)path;
@end


/**
 * An OFException indicating that creating a link failed.
 */
@interface OFLinkFailedException: OFException
{
	OFString *src;
	OFString *dest;







>







521
522
523
524
525
526
527
528
529
530
531
532
533
534
535

/**
 * \return The path of the file
 */
- (OFString*)path;
@end

#ifndef _WIN32
/**
 * An OFException indicating that creating a link failed.
 */
@interface OFLinkFailedException: OFException
{
	OFString *src;
	OFString *dest;
613
614
615
616
617
618
619

620
621
622
623
624
625
626
- (OFString*)source;

/**
 * \return A string of the destination for the symlink
 */
- (OFString*)destination;
@end


/**
 * An OFException indicating that setting an option failed.
 */
@interface OFSetOptionFailedException: OFException {}
@end








>







617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
- (OFString*)source;

/**
 * \return A string of the destination for the symlink
 */
- (OFString*)destination;
@end
#endif

/**
 * An OFException indicating that setting an option failed.
 */
@interface OFSetOptionFailedException: OFException {}
@end

Modified src/OFExceptions.m from [cfd5cb5ad9] to [ad416c1918].

547
548
549
550
551
552
553

554
555
556
557
558
559
560

- (mode_t)mode
{
	return mode;
}
@end


@implementation OFChangeFileOwnerFailedException
+ newWithClass: (Class)class__
	  path: (OFString*)path_
	 owner: (uid_t)owner_
	 group: (gid_t)group_
{
	return [[self alloc] initWithClass: class__







>







547
548
549
550
551
552
553
554
555
556
557
558
559
560
561

- (mode_t)mode
{
	return mode;
}
@end

#ifndef _WIN32
@implementation OFChangeFileOwnerFailedException
+ newWithClass: (Class)class__
	  path: (OFString*)path_
	 owner: (uid_t)owner_
	 group: (gid_t)group_
{
	return [[self alloc] initWithClass: class__
619
620
621
622
623
624
625

626
627
628
629
630
631
632
}

- (gid_t)group
{
	return group;
}
@end


@implementation OFRenameFileFailedException
+ newWithClass: (Class)class__
	  from: (OFString*)from_
	    to: (OFString*)to_
{
	return [[self alloc] initWithClass: class__







>







620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
}

- (gid_t)group
{
	return group;
}
@end
#endif

@implementation OFRenameFileFailedException
+ newWithClass: (Class)class__
	  from: (OFString*)from_
	    to: (OFString*)to_
{
	return [[self alloc] initWithClass: class__
740
741
742
743
744
745
746

747
748
749
750
751
752
753

- (OFString*)path
{
	return path;
}
@end


@implementation OFLinkFailedException
+ newWithClass: (Class)class__
	source: (OFString*)src_
   destination: (OFString*)dest_
{
	return [[self alloc] initWithClass: class__
				    source: src_







>







742
743
744
745
746
747
748
749
750
751
752
753
754
755
756

- (OFString*)path
{
	return path;
}
@end

#ifndef _WIN32
@implementation OFLinkFailedException
+ newWithClass: (Class)class__
	source: (OFString*)src_
   destination: (OFString*)dest_
{
	return [[self alloc] initWithClass: class__
				    source: src_
869
870
871
872
873
874
875

876
877
878
879
880
881
882
}

- (OFString*)destination
{
	return dest;
}
@end


@implementation OFSetOptionFailedException
- (OFString*)string
{
	if (string != nil)
		return string;








>







872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
}

- (OFString*)destination
{
	return dest;
}
@end
#endif

@implementation OFSetOptionFailedException
- (OFString*)string
{
	if (string != nil)
		return string;

Modified src/OFFile.h from [d8183f3c38] to [4c7924139a].

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
/*
 * Copyright (c) 2008 - 2009
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * All rights reserved.
 *
 * This file is part of ObjFW. 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 <stdio.h>

#ifndef _WIN32
#include <sys/types.h>
#else
typedef int uid_t;
typedef int gid_t;
#endif

#import "OFStream.h"

@class OFString;

/**
 * The OFFile class provides functions to read, write and manipulate files.













<

<
<
<
<







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

14




15
16
17
18
19
20
21
/*
 * Copyright (c) 2008 - 2009
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * All rights reserved.
 *
 * This file is part of ObjFW. 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 <stdio.h>


#include <sys/types.h>





#import "OFStream.h"

@class OFString;

/**
 * The OFFile class provides functions to read, write and manipulate files.
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
 * \return A new autoreleased OFFile
 */
+ fileWithFilePointer: (FILE*)fp;

/**
 * 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
 *	       string
 * \param mode The new mode for the file
 */
+ (void)changeModeOfFile: (OFString*)path
		  toMode: (mode_t)mode;


/**
 * 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
 * \param owner The new owner for the file
 * \param group The new group for the file
 */
+ (void)changeOwnerOfFile: (OFString*)path
		  toOwner: (uid_t)owner
		    group: (gid_t)group;


/**
 * Renames a file.
 *
 * \param from The file to rename
 * \param to The new name
 */
+ (void)rename: (OFString*)from
	    to: (OFString*)to;

/**
 * Deletes a file.
 *
 * \param path The path to the file of which should be deleted as a string
 */
+ (void)delete: (OFString*)path;


/**
 * Hardlinks a file.
 *
 * Not available on Windows.
 *
 * \param src The path to the file of which should be linked as a string
 * \param dest The path to where the file should be linked as a string







|








>













>

















>







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
 * \return A new autoreleased OFFile
 */
+ fileWithFilePointer: (FILE*)fp;

/**
 * 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)changeModeOfFile: (OFString*)path
		  toMode: (mode_t)mode;

#ifndef _WIN32
/**
 * 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
 * \param owner The new owner for the file
 * \param group The new group for the file
 */
+ (void)changeOwnerOfFile: (OFString*)path
		  toOwner: (uid_t)owner
		    group: (gid_t)group;
#endif

/**
 * Renames a file.
 *
 * \param from The file to rename
 * \param to The new name
 */
+ (void)rename: (OFString*)from
	    to: (OFString*)to;

/**
 * Deletes a file.
 *
 * \param path The path to the file of which should be deleted as a string
 */
+ (void)delete: (OFString*)path;

#ifndef _WIN32
/**
 * Hardlinks a file.
 *
 * Not available on Windows.
 *
 * \param src The path to the file of which should be linked as a string
 * \param dest The path to where the file should be linked as a string
105
106
107
108
109
110
111

112
113
114
115
116
117
118
 * Not available on Windows.
 *
 * \param src The path to the file of which should be symlinked as a string
 * \param dest The path to where the file should be symlinked as a string
 */
+ (void)symlink: (OFString*)src
	     to: (OFString*)dest;


/**
 * Initializes an already allocated OFFile.
 *
 * \param path The path to the file to open as a string
 * \param mode The mode in which the file should be opened as a string
 * \return An initialized OFFile







>







103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
 * Not available on Windows.
 *
 * \param src The path to the file of which should be symlinked as a string
 * \param dest The path to where the file should be symlinked as a string
 */
+ (void)symlink: (OFString*)src
	     to: (OFString*)dest;
#endif

/**
 * Initializes an already allocated OFFile.
 *
 * \param path The path to the file to open as a string
 * \param mode The mode in which the file should be opened as a string
 * \return An initialized OFFile

Modified src/OFFile.m from [cfa00f6d8b] to [95e5eb4c36].

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

#include "config.h"

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

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

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

#ifdef _WIN32
#import <windows.h>
#endif

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

@implementation OFFile







<


<






|







11
12
13
14
15
16
17

18
19

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

#include "config.h"

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


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


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

#ifdef _WIN32
# import <windows.h>
#endif

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

@implementation OFFile
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
	if (!SetFileAttributes([path cString], attrs))
		@throw [OFChangeFileModeFailedException newWithClass: self
								path: path
								mode: mode];
#endif
}


+ (void)changeOwnerOfFile: (OFString*)path
		  toOwner: (uid_t)owner
		    group: (gid_t)group
{
#ifndef _WIN32
	if (chown([path cString], owner, group))
		@throw [OFChangeFileOwnerFailedException newWithClass: self
								 path: path
								owner: owner
								group: group];
#else
	@throw [OFNotImplementedException newWithClass: self
					      selector: _cmd];
#endif
}


+ (void)rename: (OFString*)from
	    to: (OFString*)to
{
#ifndef _WIN32
	if (rename([from cString], [to cString]))
#else







>




<





<
<
<
<

>







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
	if (!SetFileAttributes([path cString], attrs))
		@throw [OFChangeFileModeFailedException newWithClass: self
								path: path
								mode: mode];
#endif
}

#ifndef _WIN32
+ (void)changeOwnerOfFile: (OFString*)path
		  toOwner: (uid_t)owner
		    group: (gid_t)group
{

	if (chown([path cString], owner, group))
		@throw [OFChangeFileOwnerFailedException newWithClass: self
								 path: path
								owner: owner
								group: group];




}
#endif

+ (void)rename: (OFString*)from
	    to: (OFString*)to
{
#ifndef _WIN32
	if (rename([from cString], [to cString]))
#else
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
145
146
147
148
149
150
151
152

153
154
155
156
157
158
159
#else
	if (!DeleteFile([path cString]))
#endif
		@throw [OFDeleteFileFailedException newWithClass: self
							    path: path];
}


+ (void)link: (OFString*)src
	  to: (OFString*)dest
{
#ifndef _WIN32
	if (link([src cString], [dest cString]) != 0)
		@throw [OFLinkFailedException newWithClass: self
						    source: src
					       destination: dest];
#else
	@throw [OFNotImplementedException newWithClass: self
					      selector: _cmd];
#endif
}

+ (void)symlink: (OFString*)src
	     to: (OFString*)dest
{
#ifndef _WIN32
	if (symlink([src cString], [dest cString]) != 0)
		@throw [OFSymlinkFailedException newWithClass: self
						       source: src
						  destination: dest];
#else
	@throw [OFNotImplementedException newWithClass: self
					      selector: _cmd];
#endif
}


- init
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
}








>



<




<
<
<
<





<




<
<
<
<

>







114
115
116
117
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
145
146
#else
	if (!DeleteFile([path cString]))
#endif
		@throw [OFDeleteFileFailedException newWithClass: self
							    path: path];
}

#ifndef _WIN32
+ (void)link: (OFString*)src
	  to: (OFString*)dest
{

	if (link([src cString], [dest cString]) != 0)
		@throw [OFLinkFailedException newWithClass: self
						    source: src
					       destination: dest];




}

+ (void)symlink: (OFString*)src
	     to: (OFString*)dest
{

	if (symlink([src cString], [dest cString]) != 0)
		@throw [OFSymlinkFailedException newWithClass: self
						       source: src
						  destination: dest];




}
#endif

- init
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
}