ObjFW  Check-in [70874cf3c5]

Overview
Comment:Remove writeWideCString as that's a bad idea.

Endianess, size etc. may differ from system to system. While this might
be ok when writing files that are only read local again, this is
definitely not ok with sockets. So it's better to remove it from the
OFStream protocol.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 70874cf3c5542b71c172fae2d27f2112cf97289704c19f785c8887e118da9039
User & Date: js on 2008-12-07 03:06:33
Other Links: manifest | tags
Context
2008-12-07
10:24
OFSocket -> OFTCPSocket. check-in: d1a5065e69 user: js tags: trunk
03:06
Remove writeWideCString as that's a bad idea. check-in: 70874cf3c5 user: js tags: trunk
02:59
glibc is broken once again. I guess no other libc is that broken... check-in: 6d069e2a83 user: js tags: trunk
Changes

Modified src/OFFile.h from [38c6717cee] to [4108e927d0].

168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/**
 * Writes a C string into the file, without the trailing zero.
 *
 * \param str The C string from which the data is written to the file
 * \return The number of bytes written
 */
- (size_t)writeCString: (const char*)str;

/**
 * Writes a C string into the file, without the trailing zero.
 *
 * \param str The wide C string from which the data is written to the file
 * \return The number of bytes written
 */
- (size_t)writeWideCString: (const wchar_t*)str;
@end







<
<
<
<
<
<
<
<

168
169
170
171
172
173
174








175
/**
 * Writes a C string into the file, without the trailing zero.
 *
 * \param str The C string from which the data is written to the file
 * \return The number of bytes written
 */
- (size_t)writeCString: (const char*)str;








@end

Modified src/OFFile.m from [9d35a4ce1a] to [44934e3ad8].

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 */

#import "config.h"

#import <stdio.h>
#import <string.h>
#import <unistd.h>
#include <wchar.h>  /* include due to glibc brokenness */

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

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








<







10
11
12
13
14
15
16

17
18
19
20
21
22
23
 */

#import "config.h"

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


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

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

159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
		      fromBuffer: buf];
}

- (size_t)writeCString: (const char*)str
{
	return [self writeNItems: strlen(str)
			  ofSize: 1
		      fromBuffer: (const uint8_t*)str];
}

- (size_t)writeWideCString: (const wchar_t*)str
{
	return [self writeNItems: wcslen(str)
			  ofSize: sizeof(wchar_t)
		      fromBuffer: (const uint8_t*)str];
}
@end







<
<
<
<
<
<
<



158
159
160
161
162
163
164







165
166
167
		      fromBuffer: buf];
}

- (size_t)writeCString: (const char*)str
{
	return [self writeNItems: strlen(str)
			  ofSize: 1







		      fromBuffer: (const uint8_t*)str];
}
@end

Modified src/OFSocket.h from [896e2569bc] to [e31807ae92].

107
108
109
110
111
112
113








114
 *
 * \param buf The buffer from which the data is written to the file
 * \param size The size of the data that should be written
 * \return The number of bytes written
 */
- (size_t)writeNBytes: (size_t)size
	   fromBuffer: (const uint8_t*)buf;








@end







>
>
>
>
>
>
>
>

107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
 *
 * \param buf The buffer from which the data is written to the file
 * \param size The size of the data that should be written
 * \return The number of bytes written
 */
- (size_t)writeNBytes: (size_t)size
	   fromBuffer: (const uint8_t*)buf;

/**
 * Sends a C string, without the trailing zero.
 *
 * \param str The C string from which the data is sent
 * \return The number of bytes written
 */
- (size_t)writeCString: (const char*)str;
@end

Modified src/OFSocket.m from [8a25c414b4] to [9c27c4838b].

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

#import "config.h"

#import <stdio.h>
#import <stdlib.h>
#import <string.h>
#import <unistd.h>
#include <wchar.h>  /* include due to glibc brokenness */

#import "OFSocket.h"
#import "OFExceptions.h"

@implementation OFSocketAddress
+ newWithHost: (const char*)host
      andPort: (uint16_t)port







<







11
12
13
14
15
16
17

18
19
20
21
22
23
24

#import "config.h"

#import <stdio.h>
#import <stdlib.h>
#import <string.h>
#import <unistd.h>


#import "OFSocket.h"
#import "OFExceptions.h"

@implementation OFSocketAddress
+ newWithHost: (const char*)host
      andPort: (uint16_t)port
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
}

- (size_t)writeCString: (const char*)str
{
	return [self writeNBytes: strlen(str)
		      fromBuffer: (const uint8_t*)str];
}

- (size_t)writeWideCString: (const wchar_t*)str
{
	size_t len = wcslen(str);

	if (len > SIZE_MAX / sizeof(wchar_t))
		[[OFOutOfRangeException newWithObject: self] raise];

	return [self writeNBytes: len * sizeof(wchar_t)
		      fromBuffer: (const uint8_t*)str];
}
@end







<
<
<
<
<
<
<
<
<
<
<

166
167
168
169
170
171
172











173
}

- (size_t)writeCString: (const char*)str
{
	return [self writeNBytes: strlen(str)
		      fromBuffer: (const uint8_t*)str];
}











@end

Modified src/OFStream.h from [6335fea124] to [1921fa4c55].

46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
 * Writes a C string into the stream, without the trailing zero.
 *
 * \param str The C string from which the data is written to the stream
 * \return The number of bytes written
 */
- (size_t)writeCString: (const char*)str;

/**
 * Writes a C string into the stream, without the trailing zero.
 *
 * \param str The wide C string from which the data is written to the stream
 * \return The number of bytes written
 */
- (size_t)writeWideCString: (const wchar_t*)str;
@end







<
<
<
<
<
<
<
<

46
47
48
49
50
51
52








53
/**
 * Writes a C string into the stream, without the trailing zero.
 *
 * \param str The C string from which the data is written to the stream
 * \return The number of bytes written
 */
- (size_t)writeCString: (const char*)str;








@end