ObjFW  Check-in [baeaca9124]

Overview
Comment:mbstowcs/wcstombs returns the size of bytes exluding \0, thus add 1.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: baeaca91249c2f18673abc095918bbf7ebcfae0f8f72d4c8e4f66e217e8b8b79
User & Date: js on 2008-11-26 21:12:39
Other Links: manifest | tags
Context
2008-11-26
21:35
glibc breaks when trying to use stdio.h and wchar.h.
This is stupid, as it's possible you don't ever output a wchar_t and
just need wcscmp, but this forces us to always use wprintf when we need
a wchar_t somewhere in the file. glibc really is a nightmare.
check-in: 0889c2fc55 user: js tags: trunk
21:12
mbstowcs/wcstombs returns the size of bytes exluding \0, thus add 1. check-in: baeaca9124 user: js tags: trunk
14:40
Support for wide C strings for OFXMLFactory. check-in: cd99b982ac user: js tags: trunk
Changes

Modified src/OFString.m from [cffef7d468] to [441ab9ee19].

56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
				[super free];
				return nil;
			}

			string = [self getMemForNItems: length + 1
						ofSize: sizeof(wchar_t)];

			if (mbstowcs(string, str, length) != length) {
				[super free];
				return nil;
			}
		}
	}

	return self;







|







56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
				[super free];
				return nil;
			}

			string = [self getMemForNItems: length + 1
						ofSize: sizeof(wchar_t)];

			if (mbstowcs(string, str, length + 1) != length) {
				[super free];
				return nil;
			}
		}
	}

	return self;
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
	size_t len;

	if ((len = wcstombs(NULL, string, 0)) == (size_t)-1) {
		/* FIXME: Throw exception */
		return NULL;
	}

	str = [self getMemWithSize: len];

	if (wcstombs(str, string, len) != len) {
		/* FIXME: Throw exception */
		[self freeMem: str];
		return NULL;
	}

	return str;
}







|

|







93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
	size_t len;

	if ((len = wcstombs(NULL, string, 0)) == (size_t)-1) {
		/* FIXME: Throw exception */
		return NULL;
	}

	str = [self getMemWithSize: len + 1];

	if (wcstombs(str, string, len + 1) != len) {
		/* FIXME: Throw exception */
		[self freeMem: str];
		return NULL;
	}

	return str;
}