ObjFW  Diff

Differences From Artifact [6e6ecd5f68]:

To Artifact [21ad1ce6b7]:


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
 * 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 "OFSeekableStream.h"

#if defined(OF_MORPHOS) && !defined(OF_IXEMUL)





# define BOOL EXEC_BOOL
# include <proto/dos.h>
# undef BOOL






#endif

OF_ASSUME_NONNULL_BEGIN

/*!
 * @class OFFile OFFile.h ObjFW/OFFile.h
 *
 * @brief A class which provides methods to read and write files.
 */
@interface OFFile: OFSeekableStream
{
#if !defined(OF_MORPHOS) || defined(OF_IXEMUL)
	int _fd;
#else
	BPTR _handle;
	bool _append;
#endif
	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







|
>
>
>
>
>



>
>
>
>
>
>











<
<
<
|
<
<







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
 * 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 "OFSeekableStream.h"

#if !defined(OF_MORPHOS) || defined(OF_IXEMUL)
# define OF_FILE_HANDLE_IS_FD
# define OF_INVALID_FILE_HANDLE (-1)
# define OF_FILE_HANDLE_IS_VALID(h) (h != -1)
typedef int of_file_handle_t;
#else
# define BOOL EXEC_BOOL
# include <proto/dos.h>
# undef BOOL
# define OF_INVALID_FILE_HANDLE ((of_file_handle_t){ 0, false })
# define OF_FILE_HANDLE_IS_VALID(h) (h.handle != 0)
typedef struct of_file_handle_t {
	BPTR handle;
	bool append;
} of_file_handle_t;
#endif

OF_ASSUME_NONNULL_BEGIN

/*!
 * @class OFFile OFFile.h ObjFW/OFFile.h
 *
 * @brief A class which provides methods to read and write files.
 */
@interface OFFile: OFSeekableStream
{



	of_file_handle_t _handle;


	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
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
 *	       `a+`           | read-write, create, append
 *	       `ab+` or `a+b` | read-write, create, append, binary
 * @return A new autoreleased OFFile
 */
+ (instancetype)fileWithPath: (OFString *)path
			mode: (OFString *)mode;

#if !defined(OF_MORPHOS) || defined(OF_IXEMUL)
/*!
 * @brief Creates a new OFFile with the specified file descriptor.
 *
 * @param fd A file descriptor, returned from for example open().
 *	     It is closed when the OFFile object is deallocated!
 * @return A new autoreleased OFFile
 */
+ (instancetype)fileWithFileDescriptor: (int)fd;
#else
/*!
 * @brief Creates a new OFFile with the specified handle.
 *
 * @param handle A handle, returned from for example Open().
 *		 It is closed when the OFFile object is deallocated!
 * @return A new autoreleased OFFile
 */
+ (instancetype)fileWithHandle: (BPTR)handle;
#endif

- init OF_UNAVAILABLE;

/*!
 * @brief Initializes an already allocated OFFile.
 *
 * @param path The path to the file to open as a string







<

|

|
|
<
<
<
<
<
<
<
<
|


|
<







67
68
69
70
71
72
73

74
75
76
77
78








79
80
81
82

83
84
85
86
87
88
89
 *	       `a+`           | read-write, create, append
 *	       `ab+` or `a+b` | read-write, create, append, binary
 * @return A new autoreleased OFFile
 */
+ (instancetype)fileWithPath: (OFString *)path
			mode: (OFString *)mode;


/*!
 * @brief Creates a new OFFile with the specified native file handle.
 *
 * @param handle A native file handle. If OF_FILE_HANDLE_IS_FD is defined, this
 *		 is a file descriptor. The handle is closed when the OFFile








 *		 object is deallocated!
 * @return A new autoreleased OFFile
 */
+ (instancetype)fileWithHandle: (of_file_handle_t)handle;


- init OF_UNAVAILABLE;

/*!
 * @brief Initializes an already allocated OFFile.
 *
 * @param path The path to the file to open as a string
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
 *	       `a+`           | read-write, create, append
 *	       `ab+` or `a+b` | read-write, create, append, binary
 * @return An initialized OFFile
 */
- initWithPath: (OFString *)path
	  mode: (OFString *)mode;

#if !defined(OF_MORPHOS) || defined(OF_IXEMUL)
/*!
 * @brief Initializes an already allocated OFFile.
 *
 * @param fd A file descriptor, returned from for example open().
 *	     It is closed when the OFFile object is deallocated!
 * @return An initialized OFFile
 */
- initWithFileDescriptor: (int)fd;
#else
/*!
 * @brief Initializes an already allocated OFFile.
 *
 * @param handle A handle, returned from for example Open().
 *		 It is closed when the OFFile object is deallocated!
 * @return An initialized OFFile
 */
- initWithHandle: (BPTR)handle;
#endif
@end

OF_ASSUME_NONNULL_END







<



|
|
<
<
<
<
<
<
<
<
|


|
<



104
105
106
107
108
109
110

111
112
113
114
115








116
117
118
119

120
121
122
 *	       `a+`           | read-write, create, append
 *	       `ab+` or `a+b` | read-write, create, append, binary
 * @return An initialized OFFile
 */
- initWithPath: (OFString *)path
	  mode: (OFString *)mode;


/*!
 * @brief Initializes an already allocated OFFile.
 *
 * @param handle A native file handle. If OF_FILE_HANDLE_IS_FD is defined, this
 *		 is a file descriptor. The handle is closed when the OFFile








 *		 object is deallocated!
 * @return An initialized OFFile
 */
- initWithHandle: (of_file_handle_t)handle OF_DESIGNATED_INITIALIZER;

@end

OF_ASSUME_NONNULL_END