ObjFW  Check-in [085bfc12a0]

Overview
Comment:Add OFStdIOStream.

This is used for of_std{in,out,err} now instead of OFFile.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 085bfc12a0ac96f0d660e616a8f749122f244e75403859989194901daf715dba
User & Date: js on 2013-04-27 01:26:35
Other Links: manifest | tags
Context
2013-04-27
02:22
Initial Wii port. check-in: 2713b481a1 user: js tags: trunk
01:26
Add OFStdIOStream. check-in: 085bfc12a0 user: js tags: trunk
2013-04-26
22:32
Check for sysconf(). check-in: 3f7dee97e8 user: js tags: trunk
Changes

Modified ObjFW.xcodeproj/project.pbxproj from [12af806c8e] to [102bb9bbac].

29
30
31
32
33
34
35


36
37
38
39
40
41
42
			);
			name = configure;
			productName = configure;
		};
/* End PBXAggregateTarget section */

/* Begin PBXBuildFile section */


		4B11005C14329B9A003A45D8 /* OFXMLNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B11005A14329B9A003A45D8 /* OFXMLNode.h */; settings = {ATTRIBUTES = (Public, ); }; };
		4B11005D14329B9A003A45D8 /* OFXMLNode.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B11005B14329B9A003A45D8 /* OFXMLNode.m */; };
		4B141BA415FCDF74000C21A8 /* OFSortedList.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B141BA215FCDF74000C21A8 /* OFSortedList.h */; settings = {ATTRIBUTES = (Public, ); }; };
		4B141BA515FCDF74000C21A8 /* OFSortedList.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B141BA315FCDF74000C21A8 /* OFSortedList.m */; };
		4B17FF73133A2A76003E6DCD /* OFException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B17FF71133A28FC003E6DCD /* OFException.m */; };
		4B17FF74133A2AAB003E6DCD /* OFException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B17FF70133A28FC003E6DCD /* OFException.h */; settings = {ATTRIBUTES = (Public, ); }; };
		4B17FF77133A2B18003E6DCD /* OFNotImplementedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B17FF75133A2B18003E6DCD /* OFNotImplementedException.h */; settings = {ATTRIBUTES = (Public, ); }; };







>
>







29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
			);
			name = configure;
			productName = configure;
		};
/* End PBXAggregateTarget section */

/* Begin PBXBuildFile section */
		4B0256E4172B60400062B5F1 /* OFStdIOStream.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B0256E2172B60400062B5F1 /* OFStdIOStream.h */; settings = {ATTRIBUTES = (Public, ); }; };
		4B0256E5172B60400062B5F1 /* OFStdIOStream.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B0256E3172B60400062B5F1 /* OFStdIOStream.m */; };
		4B11005C14329B9A003A45D8 /* OFXMLNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B11005A14329B9A003A45D8 /* OFXMLNode.h */; settings = {ATTRIBUTES = (Public, ); }; };
		4B11005D14329B9A003A45D8 /* OFXMLNode.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B11005B14329B9A003A45D8 /* OFXMLNode.m */; };
		4B141BA415FCDF74000C21A8 /* OFSortedList.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B141BA215FCDF74000C21A8 /* OFSortedList.h */; settings = {ATTRIBUTES = (Public, ); }; };
		4B141BA515FCDF74000C21A8 /* OFSortedList.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B141BA315FCDF74000C21A8 /* OFSortedList.m */; };
		4B17FF73133A2A76003E6DCD /* OFException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B17FF71133A28FC003E6DCD /* OFException.m */; };
		4B17FF74133A2AAB003E6DCD /* OFException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B17FF70133A28FC003E6DCD /* OFException.h */; settings = {ATTRIBUTES = (Public, ); }; };
		4B17FF77133A2B18003E6DCD /* OFNotImplementedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B17FF75133A2B18003E6DCD /* OFNotImplementedException.h */; settings = {ATTRIBUTES = (Public, ); }; };
453
454
455
456
457
458
459


460
461
462
463
464
465
466
			runOnlyForDeploymentPostprocessing = 0;
		};
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
		4B0108C910EB8C9300631877 /* OFEnumerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFEnumerator.h; path = src/OFEnumerator.h; sourceTree = "<group>"; };
		4B0108CA10EB8C9300631877 /* OFEnumerator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFEnumerator.m; path = src/OFEnumerator.m; sourceTree = "<group>"; };


		4B0D249411DFAA3D00ED6FFC /* OFXMLElementBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFXMLElementBuilder.h; path = src/OFXMLElementBuilder.h; sourceTree = "<group>"; };
		4B0D249511DFAA3D00ED6FFC /* OFXMLElementBuilder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFXMLElementBuilder.m; path = src/OFXMLElementBuilder.m; sourceTree = "<group>"; };
		4B11005A14329B9A003A45D8 /* OFXMLNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFXMLNode.h; path = src/OFXMLNode.h; sourceTree = "<group>"; };
		4B11005B14329B9A003A45D8 /* OFXMLNode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFXMLNode.m; path = src/OFXMLNode.m; sourceTree = "<group>"; };
		4B141BA215FCDF74000C21A8 /* OFSortedList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFSortedList.h; path = src/OFSortedList.h; sourceTree = "<group>"; };
		4B141BA315FCDF74000C21A8 /* OFSortedList.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFSortedList.m; path = src/OFSortedList.m; sourceTree = "<group>"; };
		4B175C1D116D130B003C99CB /* OFApplication.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFApplication.h; path = src/OFApplication.h; sourceTree = "<group>"; };







>
>







455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
			runOnlyForDeploymentPostprocessing = 0;
		};
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
		4B0108C910EB8C9300631877 /* OFEnumerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFEnumerator.h; path = src/OFEnumerator.h; sourceTree = "<group>"; };
		4B0108CA10EB8C9300631877 /* OFEnumerator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFEnumerator.m; path = src/OFEnumerator.m; sourceTree = "<group>"; };
		4B0256E2172B60400062B5F1 /* OFStdIOStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFStdIOStream.h; path = src/OFStdIOStream.h; sourceTree = "<group>"; };
		4B0256E3172B60400062B5F1 /* OFStdIOStream.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFStdIOStream.m; path = src/OFStdIOStream.m; sourceTree = "<group>"; };
		4B0D249411DFAA3D00ED6FFC /* OFXMLElementBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFXMLElementBuilder.h; path = src/OFXMLElementBuilder.h; sourceTree = "<group>"; };
		4B0D249511DFAA3D00ED6FFC /* OFXMLElementBuilder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFXMLElementBuilder.m; path = src/OFXMLElementBuilder.m; sourceTree = "<group>"; };
		4B11005A14329B9A003A45D8 /* OFXMLNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFXMLNode.h; path = src/OFXMLNode.h; sourceTree = "<group>"; };
		4B11005B14329B9A003A45D8 /* OFXMLNode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFXMLNode.m; path = src/OFXMLNode.m; sourceTree = "<group>"; };
		4B141BA215FCDF74000C21A8 /* OFSortedList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFSortedList.h; path = src/OFSortedList.h; sourceTree = "<group>"; };
		4B141BA315FCDF74000C21A8 /* OFSortedList.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFSortedList.m; path = src/OFSortedList.m; sourceTree = "<group>"; };
		4B175C1D116D130B003C99CB /* OFApplication.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFApplication.h; path = src/OFApplication.h; sourceTree = "<group>"; };
1163
1164
1165
1166
1167
1168
1169


1170
1171
1172
1173
1174
1175
1176
				4B39844113D3A24600E6F825 /* OFSet.m */,
				4BA85BC8140ECCE800E91D51 /* OFSet_hashtable.h */,
				4BA85BC9140ECCE800E91D51 /* OFSet_hashtable.m */,
				4BF1BCC411C9663F0025511F /* OFSHA1Hash.h */,
				4BF1BCC511C9663F0025511F /* OFSHA1Hash.m */,
				4B141BA215FCDF74000C21A8 /* OFSortedList.h */,
				4B141BA315FCDF74000C21A8 /* OFSortedList.m */,


				4B67997D1099E7C50041064A /* OFStream.h */,
				4B67997E1099E7C50041064A /* OFStream.m */,
				4BAF5F47123460C900F4E111 /* OFStreamObserver.h */,
				4BAF5F48123460C900F4E111 /* OFStreamObserver.m */,
				4B83F0F2142FDEFD00E4A821 /* OFStreamObserver_kqueue.h */,
				4B83F0F3142FDEFD00E4A821 /* OFStreamObserver_kqueue.m */,
				4B64D6EB1425381E007BDFB1 /* OFStreamObserver_poll.h */,







>
>







1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
				4B39844113D3A24600E6F825 /* OFSet.m */,
				4BA85BC8140ECCE800E91D51 /* OFSet_hashtable.h */,
				4BA85BC9140ECCE800E91D51 /* OFSet_hashtable.m */,
				4BF1BCC411C9663F0025511F /* OFSHA1Hash.h */,
				4BF1BCC511C9663F0025511F /* OFSHA1Hash.m */,
				4B141BA215FCDF74000C21A8 /* OFSortedList.h */,
				4B141BA315FCDF74000C21A8 /* OFSortedList.m */,
				4B0256E2172B60400062B5F1 /* OFStdIOStream.h */,
				4B0256E3172B60400062B5F1 /* OFStdIOStream.m */,
				4B67997D1099E7C50041064A /* OFStream.h */,
				4B67997E1099E7C50041064A /* OFStream.m */,
				4BAF5F47123460C900F4E111 /* OFStreamObserver.h */,
				4BAF5F48123460C900F4E111 /* OFStreamObserver.m */,
				4B83F0F2142FDEFD00E4A821 /* OFStreamObserver_kqueue.h */,
				4B83F0F3142FDEFD00E4A821 /* OFStreamObserver_kqueue.m */,
				4B64D6EB1425381E007BDFB1 /* OFStreamObserver_poll.h */,
1408
1409
1410
1411
1412
1413
1414

1415
1416
1417
1418
1419
1420
1421
				4B674405163C395900EB1E59 /* OFRecursiveMutex.h in Headers */,
				4B325EDD1605F3A0007836CA /* OFRunLoop.h in Headers */,
				4B3D23D31337FCB000DD29B8 /* OFSeekableStream.h in Headers */,
				4B989C2F13771A3700109A30 /* OFSerialization.h in Headers */,
				4B39844213D3A24600E6F825 /* OFSet.h in Headers */,
				4B3D23D41337FCB000DD29B8 /* OFSHA1Hash.h in Headers */,
				4B141BA415FCDF74000C21A8 /* OFSortedList.h in Headers */,

				4B3D23D51337FCB000DD29B8 /* OFStream.h in Headers */,
				4B3D23D61337FCB000DD29B8 /* OFStreamObserver.h in Headers */,
				4B3D23D71337FCB000DD29B8 /* OFStreamSocket.h in Headers */,
				4B3D23D81337FCB000DD29B8 /* OFString.h in Headers */,
				4B3D23D91337FCB000DD29B8 /* OFString+Hashing.h in Headers */,
				4B5CF8F914940BD2007AA324 /* OFString+JSONValue.h in Headers */,
				4BB25E8A139C388A00F574EA /* OFString+Serialization.h in Headers */,







>







1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
				4B674405163C395900EB1E59 /* OFRecursiveMutex.h in Headers */,
				4B325EDD1605F3A0007836CA /* OFRunLoop.h in Headers */,
				4B3D23D31337FCB000DD29B8 /* OFSeekableStream.h in Headers */,
				4B989C2F13771A3700109A30 /* OFSerialization.h in Headers */,
				4B39844213D3A24600E6F825 /* OFSet.h in Headers */,
				4B3D23D41337FCB000DD29B8 /* OFSHA1Hash.h in Headers */,
				4B141BA415FCDF74000C21A8 /* OFSortedList.h in Headers */,
				4B0256E4172B60400062B5F1 /* OFStdIOStream.h in Headers */,
				4B3D23D51337FCB000DD29B8 /* OFStream.h in Headers */,
				4B3D23D61337FCB000DD29B8 /* OFStreamObserver.h in Headers */,
				4B3D23D71337FCB000DD29B8 /* OFStreamSocket.h in Headers */,
				4B3D23D81337FCB000DD29B8 /* OFString.h in Headers */,
				4B3D23D91337FCB000DD29B8 /* OFString+Hashing.h in Headers */,
				4B5CF8F914940BD2007AA324 /* OFString+JSONValue.h in Headers */,
				4BB25E8A139C388A00F574EA /* OFString+Serialization.h in Headers */,
1759
1760
1761
1762
1763
1764
1765

1766
1767
1768
1769
1770
1771
1772
				4B674406163C395900EB1E59 /* OFRecursiveMutex.m in Sources */,
				4B325EDE1605F3A0007836CA /* OFRunLoop.m in Sources */,
				4B3D23A11337FC0D00DD29B8 /* OFSeekableStream.m in Sources */,
				4B39844313D3A24600E6F825 /* OFSet.m in Sources */,
				4BA85BCF140ECCE800E91D51 /* OFSet_hashtable.m in Sources */,
				4B3D23A21337FC0D00DD29B8 /* OFSHA1Hash.m in Sources */,
				4B141BA515FCDF74000C21A8 /* OFSortedList.m in Sources */,

				4B3D23A31337FC0D00DD29B8 /* OFStream.m in Sources */,
				4B3D23A41337FC0D00DD29B8 /* OFStreamObserver.m in Sources */,
				4B83F0F5142FDEFD00E4A821 /* OFStreamObserver_kqueue.m in Sources */,
				4B64D6F01425381E007BDFB1 /* OFStreamObserver_poll.m in Sources */,
				4B64D6F21425381E007BDFB1 /* OFStreamObserver_select.m in Sources */,
				4B3D23A51337FC0D00DD29B8 /* OFStreamSocket.m in Sources */,
				4B3D23A61337FC0D00DD29B8 /* OFString.m in Sources */,







>







1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
				4B674406163C395900EB1E59 /* OFRecursiveMutex.m in Sources */,
				4B325EDE1605F3A0007836CA /* OFRunLoop.m in Sources */,
				4B3D23A11337FC0D00DD29B8 /* OFSeekableStream.m in Sources */,
				4B39844313D3A24600E6F825 /* OFSet.m in Sources */,
				4BA85BCF140ECCE800E91D51 /* OFSet_hashtable.m in Sources */,
				4B3D23A21337FC0D00DD29B8 /* OFSHA1Hash.m in Sources */,
				4B141BA515FCDF74000C21A8 /* OFSortedList.m in Sources */,
				4B0256E5172B60400062B5F1 /* OFStdIOStream.m in Sources */,
				4B3D23A31337FC0D00DD29B8 /* OFStream.m in Sources */,
				4B3D23A41337FC0D00DD29B8 /* OFStreamObserver.m in Sources */,
				4B83F0F5142FDEFD00E4A821 /* OFStreamObserver_kqueue.m in Sources */,
				4B64D6F01425381E007BDFB1 /* OFStreamObserver_poll.m in Sources */,
				4B64D6F21425381E007BDFB1 /* OFStreamObserver_select.m in Sources */,
				4B3D23A51337FC0D00DD29B8 /* OFStreamSocket.m in Sources */,
				4B3D23A61337FC0D00DD29B8 /* OFString.m in Sources */,

Modified src/Makefile from [7ad86b5b2c] to [b5530e929b].

35
36
37
38
39
40
41

42
43
44
45
46
47
48
       OFObject+Serialization.m		\
       ${OFPROCESS_M}			\
       OFRunLoop.m			\
       OFSeekableStream.m		\
       OFSet.m				\
       OFSHA1Hash.m			\
       OFSortedList.m			\

       OFStream.m			\
       OFString.m			\
       OFString+Hashing.m		\
       OFString+JSONValue.m		\
       OFString+Serialization.m		\
       OFString+URLEncoding.m		\
       OFString+XMLEscaping.m		\







>







35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
       OFObject+Serialization.m		\
       ${OFPROCESS_M}			\
       OFRunLoop.m			\
       OFSeekableStream.m		\
       OFSet.m				\
       OFSHA1Hash.m			\
       OFSortedList.m			\
       OFStdIOStream.m			\
       OFStream.m			\
       OFString.m			\
       OFString+Hashing.m		\
       OFString+JSONValue.m		\
       OFString+Serialization.m		\
       OFString+URLEncoding.m		\
       OFString+XMLEscaping.m		\

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

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
#include <sys/types.h>

#import "OFSeekableStream.h"

@class OFArray;
@class OFDate;

#ifdef __cplusplus
extern "C" {
#endif
extern void of_log(OFConstantString*, ...);
#ifdef __cplusplus
}
#endif

/*!
 * @brief A class which provides functions to read, write and manipulate files.
 */
@interface OFFile: OFSeekableStream
{
	int  _fd;
	bool _closable;
	bool _atEndOfStream;
}

/*!
 * @brief Creates a new OFFile with the specified path and mode.
 *
 * @param path The path to the file to open as a string







<
<
<
<
<
<
<
<






<







24
25
26
27
28
29
30








31
32
33
34
35
36

37
38
39
40
41
42
43
#include <sys/types.h>

#import "OFSeekableStream.h"

@class OFArray;
@class OFDate;









/*!
 * @brief A class which provides functions to read, write and manipulate files.
 */
@interface OFFile: OFSeekableStream
{
	int  _fd;

	bool _atEndOfStream;
}

/*!
 * @brief Creates a new OFFile with the specified path and mode.
 *
 * @param path The path to the file to open as a string
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
 * @brief Initializes an already allocated OFFile.
 *
 * @param fd A file descriptor, returned from for example open().
 *	     It is not closed when the OFFile object is deallocated!
 */
- initWithFileDescriptor: (int)fd;
@end

#ifdef __cplusplus
extern "C" {
#endif
/*! @file */

/*!
 * @brief The standard input stream as an OFStream instance.
 */
extern OFStream *of_stdin;

/*!
 * @brief The standard output stream as an OFStream instance.
 */
extern OFStream *of_stdout;

/*!
 * @brief The standard error stream as an OFStream instance.
 */
extern OFStream *of_stderr;
#ifdef __cplusplus
}
#endif







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
256
257
258
259
260
261
262























 * @brief Initializes an already allocated OFFile.
 *
 * @param fd A file descriptor, returned from for example open().
 *	     It is not closed when the OFFile object is deallocated!
 */
- initWithFileDescriptor: (int)fd;
@end























Modified src/OFFile.m from [526afc5ebd] to [8a99cd99a6].

45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#import "OFFile.h"
#import "OFString.h"
#import "OFArray.h"
#ifdef OF_HAVE_THREADS
# import "threading.h"
#endif
#import "OFDate.h"
#import "OFApplication.h"
#import "OFSystemInfo.h"

#import "OFChangeDirectoryFailedException.h"
#import "OFChangeFileModeFailedException.h"
#import "OFChangeFileOwnerFailedException.h"
#import "OFCreateDirectoryFailedException.h"
#import "OFDeleteDirectoryFailedException.h"







<







45
46
47
48
49
50
51

52
53
54
55
56
57
58
#import "OFFile.h"
#import "OFString.h"
#import "OFArray.h"
#ifdef OF_HAVE_THREADS
# import "threading.h"
#endif
#import "OFDate.h"

#import "OFSystemInfo.h"

#import "OFChangeDirectoryFailedException.h"
#import "OFChangeFileModeFailedException.h"
#import "OFChangeFileOwnerFailedException.h"
#import "OFCreateDirectoryFailedException.h"
#import "OFDeleteDirectoryFailedException.h"
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#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

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

#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"))







<
<
<
<







94
95
96
97
98
99
100




101
102
103
104
105
106
107
#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





#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"))
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
		return O_RDWR | O_CREAT | O_APPEND;
	if (!strcmp(mode, "ab+") || !strcmp(mode, "a+b"))
		return O_RDWR | O_CREAT | O_APPEND | O_BINARY;

	return -1;
}

void
of_log(OFConstantString *format, ...)
{
	void *pool = objc_autoreleasePoolPush();
	OFDate *date;
	OFString *dateString, *me, *msg;
	va_list arguments;

	date = [OFDate date];
	dateString = [date localDateStringWithFormat: @"%Y-%m-%d %H:%M:%S"];
	me = [[OFApplication programName] lastPathComponent];

	va_start(arguments, format);
	msg = [[[OFString alloc] initWithFormat: format
				      arguments: arguments] autorelease];
	va_end(arguments);

	[of_stderr writeFormat: @"[%@.%03d %@(%d)] %@\n", dateString,
				[date microsecond] / 1000, me, getpid(), msg];

	objc_autoreleasePoolPop(pool);
}

@interface OFFileSingleton: OFFile
@end

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








<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







128
129
130
131
132
133
134


























135
136
137
138
139
140
141
		return O_RDWR | O_CREAT | O_APPEND;
	if (!strcmp(mode, "ab+") || !strcmp(mode, "a+b"))
		return O_RDWR | O_CREAT | O_APPEND | O_BINARY;

	return -1;
}



























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

693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
		if ((_fd = _wopen([path UTF16String], flags,
		    DEFAULT_MODE)) == -1)
#endif
			@throw [OFOpenFileFailedException
			    exceptionWithClass: [self class]
					  path: path
					  mode: mode];

		_closable = true;
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}







<
<







662
663
664
665
666
667
668


669
670
671
672
673
674
675
		if ((_fd = _wopen([path UTF16String], flags,
		    DEFAULT_MODE)) == -1)
#endif
			@throw [OFOpenFileFailedException
			    exceptionWithClass: [self class]
					  path: path
					  mode: mode];


	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
		close(_fd);

	_fd = -1;
}

- (void)dealloc
{
	if (_closable && _fd != -1)
		close(_fd);

	[super dealloc];
}
@end

@implementation OFFileSingleton
+ (void)load
{
	of_stdin = [[OFFileSingleton alloc] initWithFileDescriptor: 0];
	of_stdout = [[OFFileSingleton alloc] initWithFileDescriptor: 1];
	of_stderr = [[OFFileSingleton alloc] initWithFileDescriptor: 2];
}

- initWithPath: (OFString*)path
	  mode: (OFString*)mode
{
	@try {
		[self doesNotRecognizeSelector: _cmd];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	abort();
}

- autorelease
{
	return self;
}

- retain
{
	return self;
}

- (void)release
{
}

- (unsigned int)retainCount
{
	return OF_RETAIN_COUNT_MAX;
}

- (void)dealloc
{
	[self doesNotRecognizeSelector: _cmd];
	abort();

	/* Get rid of stupid warning */
	[super dealloc];
}

- (void)lowlevelSeekToOffset: (off_t)offset
		      whence: (int)whence
{
	[self doesNotRecognizeSelector: _cmd];
	abort();
}
@end







|





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

























































		close(_fd);

	_fd = -1;
}

- (void)dealloc
{
	if (_fd != -1)
		close(_fd);

	[super dealloc];
}
@end

























































Added src/OFStdIOStream.h version [a177a89d97].













































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
45
46
47
48
49
50
51
52
53
54
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013
 *   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.QPL included in
 * the packaging of this file.
 *
 * Alternatively, it may be distributed under the terms of the GNU General
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#import "OFStream.h"

/*!
 * @brief A class for providing standard input, output and error as OFStream.
 */
@interface OFStdIOStream: OFStream
{
	int  _fd;
	bool _atEndOfStream;
}

- OF_initWithFileDescriptor: (int)fd;
@end

#ifdef __cplusplus
extern "C" {
#endif
/*! @file */

/*!
 * @brief The standard input as an OFStream.
 */
extern OFStdIOStream *of_stdin;

/*!
 * @brief The standard output as an OFStream.
 */
extern OFStdIOStream *of_stdout;

/*!
 * @brief The standard error as an OFStream.
 */
extern OFStdIOStream *of_stderr;

extern void of_log(OFConstantString*, ...);
#ifdef __cplusplus
}
#endif

Added src/OFStdIOStream.m version [f5689e7f1a].













































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
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
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
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013
 *   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.QPL included in
 * the packaging of this file.
 *
 * Alternatively, it may be distributed under the terms of the GNU General
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#include <stdlib.h>
#include <unistd.h>

#import "OFStdIOStream.h"
#import "OFDate.h"
#import "OFApplication.h"

#import "OFReadFailedException.h"
#import "OFWriteFailedException.h"

#import "autorelease.h"

OFStdIOStream *of_stdin = nil;
OFStdIOStream *of_stdout = nil;
OFStdIOStream *of_stderr = nil;

void
of_log(OFConstantString *format, ...)
{
	void *pool = objc_autoreleasePoolPush();
	OFDate *date;
	OFString *dateString, *me, *msg;
	va_list arguments;

	date = [OFDate date];
	dateString = [date localDateStringWithFormat: @"%Y-%m-%d %H:%M:%S"];
	me = [[OFApplication programName] lastPathComponent];

	va_start(arguments, format);
	msg = [[[OFString alloc] initWithFormat: format
				      arguments: arguments] autorelease];
	va_end(arguments);

	[of_stderr writeFormat: @"[%@.%03d %@(%d)] %@\n", dateString,
				[date microsecond] / 1000, me, getpid(), msg];

	objc_autoreleasePoolPop(pool);
}

@implementation OFStdIOStream
+ (void)load
{
	of_stdin = [[OFStdIOStream alloc] OF_initWithFileDescriptor: 0];
	of_stdout = [[OFStdIOStream alloc] OF_initWithFileDescriptor: 1];
	of_stderr = [[OFStdIOStream alloc] OF_initWithFileDescriptor: 2];
}

- init
{
	@try {
		[self doesNotRecognizeSelector: _cmd];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	abort();
}

- OF_initWithFileDescriptor: (int)fd
{
	self = [super init];

	_fd = fd;

	return self;
}

- (bool)lowlevelIsAtEndOfStream
{
	if (_fd == -1)
		return true;

	return _atEndOfStream;
}

- (size_t)lowlevelReadIntoBuffer: (void*)buffer
			  length: (size_t)length
{
	ssize_t ret;

	if (_fd == -1 || _atEndOfStream ||
	    (ret = read(_fd, buffer, length)) < 0)
		@throw [OFReadFailedException exceptionWithClass: [self class]
							  stream: self
						 requestedLength: length];

	if (ret == 0)
		_atEndOfStream = true;

	return ret;
}

- (void)lowlevelWriteBuffer: (const void*)buffer
		     length: (size_t)length
{
	if (_fd == -1 || _atEndOfStream || write(_fd, buffer, length) < length)
		@throw [OFWriteFailedException exceptionWithClass: [self class]
							   stream: self
						  requestedLength: length];
}

- (int)fileDescriptorForReading
{
	return _fd;
}

- (int)fileDescriptorForWriting
{
	return _fd;
}

- (void)close
{
	if (_fd != -1)
		close(_fd);

	_fd = -1;
}

- autorelease
{
	return self;
}

- retain
{
	return self;
}

- (void)release
{
}

- (unsigned int)retainCount
{
	return OF_RETAIN_COUNT_MAX;
}

- (void)dealloc
{
	[self doesNotRecognizeSelector: _cmd];
	abort();

	/* Get rid of stupid warning */
	[super dealloc];
}
@end

Modified src/ObjFW.h from [58cac27b30] to [a29c563823].

41
42
43
44
45
46
47

48
49
50
51
52
53
54
#import "OFIntrospection.h"

#import "OFNumber.h"
#import "OFDate.h"
#import "OFURL.h"

#import "OFStream.h"

#import "OFFile.h"
#ifdef OF_HAVE_SOCKETS
# import "OFStreamSocket.h"
# import "OFTCPSocket.h"
# import "OFTLSSocket.h"
# import "OFStreamObserver.h"








>







41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#import "OFIntrospection.h"

#import "OFNumber.h"
#import "OFDate.h"
#import "OFURL.h"

#import "OFStream.h"
#import "OFStdIOStream.h"
#import "OFFile.h"
#ifdef OF_HAVE_SOCKETS
# import "OFStreamSocket.h"
# import "OFTCPSocket.h"
# import "OFTLSSocket.h"
# import "OFStreamObserver.h"

Modified tests/TestsAppDelegate.m from [f5a2a05389] to [67d2f603dc].

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

#include "config.h"

#include <stdlib.h>

#import "OFString.h"
#import "OFFile.h"
#import "OFAutoreleasePool.h"

#import "TestsAppDelegate.h"

#ifdef _PSP
# include <pspmoduleinfo.h>
# include <pspkernel.h>







|







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

#include "config.h"

#include <stdlib.h>

#import "OFString.h"
#import "OFStdIOStream.h"
#import "OFAutoreleasePool.h"

#import "TestsAppDelegate.h"

#ifdef _PSP
# include <pspmoduleinfo.h>
# include <pspkernel.h>