ObjFW  Check-in [89c545c3e9]

Overview
Comment:Even more documentation.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 89c545c3e99fcb6661eeaa2651bcde1f689b50cbfbdffb17882886b018e67616
User & Date: js on 2008-11-06 16:06:06
Other Links: manifest | tags
Context
2008-11-07
14:29
Everything should be documented now. check-in: e8e45975df user: js tags: trunk
2008-11-06
16:06
Even more documentation. check-in: 89c545c3e9 user: js tags: trunk
2008-11-05
20:30
More documentation stuff. check-in: b5e28fc975 user: js tags: trunk
Changes

Modified src/OFExceptions.h from [809bee699f] to [af7a34fc33].

35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
 * Initializes an already allocated OFException.
 *
 * \param obj The object which caused the exception
 * \return An initialized OFException
 */
- initWithObject: (id)obj;

/**
 * Frees an OFException and the memory it allocated.
 */
- free;

/**
 * Raises an OFException and aborts execution if the exception is not caught.
 */

- raise;







<
<
<







35
36
37
38
39
40
41



42
43
44
45
46
47
48
 * Initializes an already allocated OFException.
 *
 * \param obj The object which caused the exception
 * \return An initialized OFException
 */
- initWithObject: (id)obj;




- free;

/**
 * Raises an OFException and aborts execution if the exception is not caught.
 */

- raise;
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
110



111
112
113
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



147
148
149
150
151
152








153
154
155









156
157
158




159




160
161
162



163



164
165
166



167



168
169
	andSize: (size_t)size;

/**
 * Initializes an already allocated no memory exception.
 *
 * \param obj The object which caused the exception
 * \param size The size of the memory that couldn't be allocated
 * \return An initialized new no memory exception
 */
- initWithObject: (id)obj
	 andSize: (size_t)size;

/**
 * \return An error message for the exception as a C String
 */
- (char*)cString;

/**
 * \return The size of the memoory that couldn't be allocated
 */
- (size_t)requestedSize;
@end




@interface OFNotImplementedException: OFException
{
	SEL selector;
}








+ newWithObject: (id)obj
    andSelector: (SEL)sel;








- initWithObject: (id)obj
     andSelector: (SEL)sel;




- (char*)cString;




- (SEL)selector;
@end




@interface OFMemNotPartOfObjException: OFException
{
	void *pointer;
}








+ newWithObject: (id)obj
     andPointer: (void*)ptr;








- initWithObject: (id)obj
      andPointer: (void*)ptr;




- (char*)cString;




- (void*)pointer;
@end




@interface OFOutOfRangeException: OFException






+ newWithObject: (id)obj;







- initWithObject: (id)obj;
@end




@interface OFOpenFileFailedException: OFException
{
	char *path;
	char *mode;
}









+ newWithObject: (id)obj
	andPath: (const char*)p
	andMode: (const char*)m;









- initWithObject: (id)obj
	 andPath: (const char*)p
	 andMode: (const char*)m;

- free;




- (char*)cString;




- (char*)path;




- (char*)mode;
@end




@interface OFReadOrWriteFailedException: OFException
{
	size_t req_size;
	size_t req_items;
}









+ newWithObject: (id)obj
	andSize: (size_t)size
      andNItems: (size_t)nitems;









- initWithObject: (id)obj
	 andSize: (size_t)size
       andNItems: (size_t)nitems;




- (size_t)requestedSize;




- (size_t)requestedItems;
@end




@interface OFReadFailedException: OFReadOrWriteFailedException



- (char*)cString;
@end




@interface OFWriteFailedException: OFReadOrWriteFailedException



- (char*)cString;
@end







|















>
>
>





>
>
>
>
>
>
>


>
>
>
>
>
>
>
>


>
>
>
>

>
>
>
>



>
>
>





>
>
>
>
>
>
>


>
>
>
>
>
>
>
>


>
>
>
>

>
>
>
>



>
>
>

>
>
>
>
>
>

>
>
>
>
>
>
>



>
>
>






>
>
>
>
>
>
>
>



>
>
>
>
>
>
>
>
>



>

>
>
>
>

>
>
>
>

>
>
>
>



>
>
>






>
>
>
>
>
>
>
>



>
>
>
>
>
>
>
>
>



>
>
>
>

>
>
>
>



>
>
>

>
>
>



>
>
>

>
>
>


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
110
111
112
113
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
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
	andSize: (size_t)size;

/**
 * Initializes an already allocated no memory exception.
 *
 * \param obj The object which caused the exception
 * \param size The size of the memory that couldn't be allocated
 * \return An initialized no memory exception
 */
- initWithObject: (id)obj
	 andSize: (size_t)size;

/**
 * \return An error message for the exception as a C String
 */
- (char*)cString;

/**
 * \return The size of the memoory that couldn't be allocated
 */
- (size_t)requestedSize;
@end

/**
 * An OFException indicating the requested selector is not implemented.
 */
@interface OFNotImplementedException: OFException
{
	SEL selector;
}

/**
 * Creates a new not impemented exception.
 *
 * \param obj The object which caused the exception
 * \param sel A selector for the function not implemented
 * \return A new not implemented exception
 */
+ newWithObject: (id)obj
    andSelector: (SEL)sel;

/**
 * Initializes an already allocated not implemented exception.
 *
 * \param obj The object which caused the exception
 * \param sel A selector for the function not implemented
 * \return An initialized not implemented exception
 */
- initWithObject: (id)obj
     andSelector: (SEL)sel;

/**
 * \return An error message for the exception as a C String
 */
- (char*)cString;

/**
 * \return The requested selector that is not implemented
 */
- (SEL)selector;
@end

/**
 * An OFException indicating the given memory is not part of the object.
 */
@interface OFMemNotPartOfObjException: OFException
{
	void *pointer;
}

/**
 * Creates a new memory not part of object exception.
 *
 * \param obj The object which caused the exception
 * \param ptr A pointer to the memory that is not part of the object
 * \return A new memory not part of object exception
 */
+ newWithObject: (id)obj
     andPointer: (void*)ptr;

/**
 * Initializes an already allocated memory not part of object exception.
 *
 * \param obj The object which caused the exception
 * \param ptr A pointer to the memory that is not part of the object
 * \return An initialized memory not part of object exception
 */
- initWithObject: (id)obj
      andPointer: (void*)ptr;

/**
 * \return An error message for the exception as a C String
 */
- (char*)cString;

/***
 * \return A pointer to the memory which is not part of the object
 */
- (void*)pointer;
@end

/**
 * An OFException indicating the given value is out of range. 
 */
@interface OFOutOfRangeException: OFException
/**
 * Creates a new out of range exception.
 *
 * \param obj The object which caused the exception
 * \return A new out of range exception
 */
+ newWithObject: (id)obj;

/**
 * Initializes an already allocated out of range exception.
 *
 * \param obj The object which caused the exception
 * \return An initialized out of range exception
 */
- initWithObject: (id)obj;
@end

/**
 * An OFException indicating the file couldn't be opened.
 */
@interface OFOpenFileFailedException: OFException
{
	char *path;
	char *mode;
}

/**
 * Creates a new open file failed exception.
 *
 * \param obj The object which caused the exception
 * \param p A C string of the path to the file tried to open
 * \param m A C string of the mode in which the file should have been opened
 * \return A new open file failed exception
 */
+ newWithObject: (id)obj
	andPath: (const char*)p
	andMode: (const char*)m;

/**
 * Initializes an already allocated open file failed exception.
 *
 * \param obj The object which caused the exception
 * \param p A C string of the path to the file which couldn't be opened
 * \param m A C string of the mode in which the file should have been opened
 * \return An initialized open file failed exception
 */
- initWithObject: (id)obj
	 andPath: (const char*)p
	 andMode: (const char*)m;

- free;

/**
 * \return An error message for the exception as a C String
 */
- (char*)cString;

/**
 * \return A C string of the path to the file which couldn't be opened
 */
- (char*)path;

/**
 * \return A C string of the mode in which the file should have been opened
 */
- (char*)mode;
@end

/**
 * An OFException indicating a read or write to the file failed.
 */
@interface OFReadOrWriteFailedException: OFException
{
	size_t req_size;
	size_t req_items;
}

/**
 * Creates a new read or write failed exception.
 *
 * \param obj The object which caused the exception
 * \param size The requested size of the data that couldn't be read / written
 * \param nitems The requested number of items that couldn't be read / written
 * \return A new open file failed exception
 */
+ newWithObject: (id)obj
	andSize: (size_t)size
      andNItems: (size_t)nitems;

/**
 * Initializes an already allocated read or write failed exception.
 *
 * \param obj The object which caused the exception
 * \param size The requested size of the data that couldn't be read / written
 * \param nitems The requested number of items that couldn't be read / written
 * \return A new open file failed exception
 */
- initWithObject: (id)obj
	 andSize: (size_t)size
       andNItems: (size_t)nitems;

/**
 * \return The requested size of the data that couldn't be read / written
 */
- (size_t)requestedSize;

/**
 * \return The requested number of items that coudln't be read / written
 */
- (size_t)requestedItems;
@end

/**
 * An OFException indicating a read to the file failed.
 */
@interface OFReadFailedException: OFReadOrWriteFailedException
/**
 * \return An error message for the exception as a C String
 */
- (char*)cString;
@end

/**
 * An OFException indicating a write to the file failed.
 */
@interface OFWriteFailedException: OFReadOrWriteFailedException
/**
 * \return An error message for the exception as a C String
 */
- (char*)cString;
@end

Modified src/OFFile.h from [90768e82ac] to [c20fa8faf0].

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
#import <stdio.h>
#import <stdint.h>

#import <sys/types.h>

#import "OFObject.h"




@interface OFFile: OFObject
{
	FILE *fp;
}






+ newWithPath: (const char*)path
      andMode: (const char*)mode;








+ (int)changeModeOfFile: (const char*)path
		 toMode: (mode_t)mode;










+ (int)changeOwnerOfFile: (const char*)path
		 toOwner: (uid_t)owner
		andGroup: (gid_t)group;







+ (int)delete: (const char*)path;








+ (int)link: (const char*)src
	 to: (const char*)dest;








+ (int)symlink: (const char*)src
	    to: (const char*)dest;








- initWithPath: (const char*)path
       andMode: (const char*)mode;

- free;




- (BOOL)atEndOfFile;











- (size_t)readIntoBuffer: (uint8_t*)buf
		withSize: (size_t)size
	       andNItems: (size_t)nItems;









- (uint8_t*)readWithSize: (size_t)size
	       andNItems: (size_t)nitems;









- (size_t)writeBuffer: (uint8_t*)buf
	     withSize: (size_t)size
	    andNItems: (size_t)nitems;
@end







>
>
>





>
>
>
>
>


>
>
>
>
>
>
>
>
|
|
>
>
>
>
>
>
>
>
>
>
|
|
|
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
|
|
>
>
>
>
>
>
>
>
|
|

>
>
>
>
>
>
>


>

>
>
>
>

>
>
>
>
>
>
>
>
>
>
>


|
>
>
>
>
>
>
>
>
>


>
>
>
>
>
>
>
>
>




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
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
110
111
112
113
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
#import <stdio.h>
#import <stdint.h>

#import <sys/types.h>

#import "OFObject.h"

/**
 * The OFFile class provides functions to read, write and manipulate files.
 */
@interface OFFile: OFObject
{
	FILE *fp;
}

/**
 * \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 A new OFFile
 */
+ newWithPath: (const char*)path
      andMode: (const char*)mode;
/**
 * Changes the mode of a file.
 *
 * \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
 */
+ (BOOL)changeModeOfFile: (const char*)path
		  toMode: (mode_t)mode;

/**
 * Changes the owner of a file.
 *
 * \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
 */
+ (BOOL)changeOwnerOfFile: (const char*)path
		  toOwner: (uid_t)owner
		 andGroup: (gid_t)group;

/**
 * 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.
 *
 * \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
 */
+ (BOOL)link: (const char*)src
	  to: (const char*)dest;

/**
 * Symlinks a file.
 *
 * \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
 */
+ (BOOL)symlink: (const char*)src
	     to: (const char*)dest;

/**
 * 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
 */
- initWithPath: (const char*)path
       andMode: (const char*)mode;

- free;

/**
 * \return A boolean whether the end of the file has been reached
 */
- (BOOL)atEndOfFile;

/**
 * Reads from the file into a buffer.
 *
 * \param buf The buffer into which the data is read
 * \param size The size of the data that should be read.
 *	  The buffer MUST be at least size * nitems big!
 * \param nitems nitem The number of items to read
 *	  The buffer MUST be at least size * nitems big!
 * \return The number of bytes read
 */
- (size_t)readIntoBuffer: (uint8_t*)buf
		withSize: (size_t)size
	       andNItems: (size_t)nitems;

/**
 * Reads from the file into a new buffer.
 *
 * \param size The size of the data that should be read
 * \param nitem The number of items to read
 * \return A new buffer with the data read.
 *	   It is part of the memory pool of the OFFile.
 */
- (uint8_t*)readWithSize: (size_t)size
	       andNItems: (size_t)nitems;

/**
 * Writes from a buffer into the file.
 *
 * \param buf The buffer from which the data is written to the file
 * \param size The size of the data that should be written
 * \param nitem The number of items to write
 * \return The number of bytes written
 */
- (size_t)writeBuffer: (uint8_t*)buf
	     withSize: (size_t)size
	    andNItems: (size_t)nitems;
@end

Modified src/OFFile.m from [6b6d44b5bf] to [c1131eae69].

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
+ newWithPath: (const char*)path
      andMode: (const char*)mode
{
	return [[OFFile alloc] initWithPath: path
				    andMode: mode];
}

+ (int)changeModeOfFile: (const char*)path
		 toMode: (mode_t)mode
{
	// FIXME: On error, throw exception
	return chmod(path, mode);
}

+ (int)changeOwnerOfFile: (const char*)path
		 toOwner: (uid_t)owner
		andGroup: (gid_t)group
{
	// FIXME: On error, throw exception
	return chown(path, owner, group);
}

+ (int)delete: (const char*)path
{
	// FIXME: On error, throw exception
	return unlink(path);
}

+ (int)link: (const char*)src
	 to: (const char*)dest
{
	// FIXME: On error, throw exception
	return link(src, dest);
}

+ (int)symlink: (const char*)src
	    to: (const char*)dest
{
	// FIXME: On error, throw exception
	return symlink(src, dest);
}

- initWithPath: (const char*)path
       andMode: (const char*)mode
{
	if ((self = [super init])) {
		if ((fp = fopen(path, mode)) == NULL)







|



|


|




|


|


|


|



|


|



|







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
+ newWithPath: (const char*)path
      andMode: (const char*)mode
{
	return [[OFFile alloc] initWithPath: path
				    andMode: mode];
}

+ (BOOL)changeModeOfFile: (const char*)path
		 toMode: (mode_t)mode
{
	// FIXME: On error, throw exception
	return (chmod(path, mode) == 0 ? YES : NO);
}

+ (BOOL)changeOwnerOfFile: (const char*)path
		 toOwner: (uid_t)owner
		andGroup: (gid_t)group
{
	// FIXME: On error, throw exception
	return (chown(path, owner, group) == 0 ? YES : NO);
}

+ (BOOL)delete: (const char*)path
{
	// FIXME: On error, throw exception
	return (unlink(path) == 0 ? YES : NO);
}

+ (BOOL)link: (const char*)src
	 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
{
	// FIXME: On error, throw exception
	return (symlink(src, dest) == 0 ? YES : NO);
}

- initWithPath: (const char*)path
       andMode: (const char*)mode
{
	if ((self = [super init])) {
		if ((fp = fopen(path, mode)) == NULL)