@@ -12,12 +12,14 @@ #import "config.h" #import #import #import +#import #import "OFSocket.h" +#import "OFExceptions.h" @implementation OFSocketAddress + newWithHost: (const char*)host andPort: (uint16_t)port andFamily: (int)family @@ -148,11 +150,11 @@ return ret; } - (size_t)writeNBytes: (size_t)size - fromBuffer: (uint8_t*)buf + fromBuffer: (const uint8_t*)buf { ssize_t ret; if ((ret = send(sock, buf, size, 0)) < 0) { /* FIXME: Throw exception */ @@ -160,6 +162,23 @@ } /* This is safe, as we already checked < 0 */ return ret; } + +- (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