Overview
Comment: | Add +[OFString nativeOSEncoding].
This replaces OF_STRING_ENCODING_NATIVE, as a define was not flexible |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
e54c8c0368a419ee2e7dc4545e40aa52 |
User & Date: | js on 2014-01-16 23:38:42 |
Other Links: | manifest | tags |
Context
2014-01-17
| ||
03:12 | Add -[OFString lossyCStringWithEncoding:]. check-in: 1b0a5cf829 user: js tags: trunk | |
2014-01-16
| ||
23:38 | Add +[OFString nativeOSEncoding]. check-in: e54c8c0368 user: js tags: trunk | |
23:09 | Add of_time_interval_t. check-in: dc31ce3d34 user: js tags: trunk | |
Changes
Modified src/OFApplication.m from [b49c0bcc2e] to [ce308c71b7].
︙ | ︙ | |||
227 228 229 230 231 232 233 | FreeEnvironmentStringsW(env); #elif !defined(OF_IOS) if (env != NULL) { for (; *env != NULL; env++) { OFString *key, *value; char *sep; const of_string_encoding_t encoding = | | | 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | FreeEnvironmentStringsW(env); #elif !defined(OF_IOS) if (env != NULL) { for (; *env != NULL; env++) { OFString *key, *value; char *sep; const of_string_encoding_t encoding = [OFString nativeOSEncoding]; pool = objc_autoreleasePoolPush(); if ((sep = strchr(*env, '=')) == NULL) { fprintf(stderr, "Warning: Invalid " "environment variable: %s\n", *env); continue; |
︙ | ︙ | |||
324 325 326 327 328 329 330 331 332 333 334 | - (void)OF_setArgumentCount: (int*)argc andArgumentValues: (char***)argv { #ifndef _WIN32 void *pool = objc_autoreleasePoolPush(); OFMutableArray *arguments; int i; _argc = argc; _argv = argv; | > > | | | < | | | 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 | - (void)OF_setArgumentCount: (int*)argc andArgumentValues: (char***)argv { #ifndef _WIN32 void *pool = objc_autoreleasePoolPush(); OFMutableArray *arguments; int i; of_string_encoding_t encoding; _argc = argc; _argv = argv; encoding = [OFString nativeOSEncoding]; _programName = [[OFString alloc] initWithCString: (*argv)[0] encoding: encoding]; arguments = [[OFMutableArray alloc] init]; for (i = 1; i < *argc; i++) [arguments addObject: [OFString stringWithCString: (*argv)[i] encoding: encoding]]; [arguments makeImmutable]; _arguments = arguments; objc_autoreleasePoolPop(pool); #else _argc = argc; |
︙ | ︙ |
Modified src/OFFile.m from [39f8827d12] to [71494b29e0].
︙ | ︙ | |||
108 109 110 111 112 113 114 | int of_stat(OFString *path, of_stat_t *buffer) { #ifdef _WIN32 return _wstat([path UTF16String], buffer); #else | | | | | 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 | int of_stat(OFString *path, of_stat_t *buffer) { #ifdef _WIN32 return _wstat([path UTF16String], buffer); #else return stat([path cStringWithEncoding: [OFString nativeOSEncoding]], buffer); #endif } int of_lstat(OFString *path, of_stat_t *buffer) { #if defined(_WIN32) return _wstat([path UTF16String], buffer); #elif defined(HAVE_LSTAT) return lstat([path cStringWithEncoding: [OFString nativeOSEncoding]], buffer); #else return stat([path cStringWithEncoding: [OFString nativeOSEncoding]], buffer); #endif } static int parseMode(const char *mode) { |
︙ | ︙ | |||
202 203 204 205 206 207 208 | #else wchar_t *buffer = _wgetcwd(NULL, 0); #endif @try { #ifndef _WIN32 ret = [OFString stringWithCString: buffer | | | 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | #else wchar_t *buffer = _wgetcwd(NULL, 0); #endif @try { #ifndef _WIN32 ret = [OFString stringWithCString: buffer encoding: [OFString nativeOSEncoding]]; #else ret = [OFString stringWithUTF16String: buffer]; #endif } @finally { free(buffer); } |
︙ | ︙ | |||
269 270 271 272 273 274 275 | + (void)createDirectoryAtPath: (OFString*)path { if (path == nil) @throw [OFInvalidArgumentException exception]; #ifndef _WIN32 | | | 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 | + (void)createDirectoryAtPath: (OFString*)path { if (path == nil) @throw [OFInvalidArgumentException exception]; #ifndef _WIN32 if (mkdir([path cStringWithEncoding: [OFString nativeOSEncoding]], DIR_MODE)) #else if (_wmkdir([path UTF16String])) #endif @throw [OFCreateDirectoryFailedException exceptionWithPath: path]; } |
︙ | ︙ | |||
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 | objc_autoreleasePoolPop(pool); } + (OFArray*)contentsOfDirectoryAtPath: (OFString*)path { OFMutableArray *files; if (path == nil) @throw [OFInvalidArgumentException exception]; files = [OFMutableArray array]; #ifndef _WIN32 DIR *dir; struct dirent *dirent; | > > | < < | | | 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 | objc_autoreleasePoolPop(pool); } + (OFArray*)contentsOfDirectoryAtPath: (OFString*)path { OFMutableArray *files; of_string_encoding_t encoding; if (path == nil) @throw [OFInvalidArgumentException exception]; files = [OFMutableArray array]; encoding = [OFString nativeOSEncoding]; #ifndef _WIN32 DIR *dir; struct dirent *dirent; if ((dir = opendir([path cStringWithEncoding: encoding])) == NULL) @throw [OFOpenFileFailedException exceptionWithPath: path mode: @"r"]; @try { while ((dirent = readdir(dir)) != NULL) { void *pool = objc_autoreleasePoolPush(); OFString *file; if (!strcmp(dirent->d_name, ".") || !strcmp(dirent->d_name, "..")) continue; file = [OFString stringWithCString: dirent->d_name encoding: encoding]; [files addObject: file]; objc_autoreleasePoolPop(pool); } } @finally { closedir(dir); } |
︙ | ︙ | |||
402 403 404 405 406 407 408 | + (void)changeCurrentDirectoryPath: (OFString*)path { if (path == nil) @throw [OFInvalidArgumentException exception]; #ifndef _WIN32 | | | 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 | + (void)changeCurrentDirectoryPath: (OFString*)path { if (path == nil) @throw [OFInvalidArgumentException exception]; #ifndef _WIN32 if (chdir([path cStringWithEncoding: [OFString nativeOSEncoding]])) #else if (_wchdir([path UTF16String])) #endif @throw [OFChangeCurrentDirectoryPathFailedException exceptionWithPath: path]; } |
︙ | ︙ | |||
450 451 452 453 454 455 456 | + (void)changePermissionsOfItemAtPath: (OFString*)path permissions: (mode_t)permissions { if (path == nil) @throw [OFInvalidArgumentException exception]; # ifndef _WIN32 | | > > > | | | | | < | 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 | + (void)changePermissionsOfItemAtPath: (OFString*)path permissions: (mode_t)permissions { if (path == nil) @throw [OFInvalidArgumentException exception]; # ifndef _WIN32 if (chmod([path cStringWithEncoding: [OFString nativeOSEncoding]], permissions)) # else if (_wchmod([path UTF16String], permissions)) # endif @throw [OFChangePermissionsFailedException exceptionWithPath: path permissions: permissions]; } #endif #ifdef OF_HAVE_CHOWN + (void)changeOwnerOfItemAtPath: (OFString*)path owner: (OFString*)owner group: (OFString*)group { uid_t uid = -1; gid_t gid = -1; of_string_encoding_t encoding; if (path == nil || (owner == nil && group == nil)) @throw [OFInvalidArgumentException exception]; encoding = [OFString nativeOSEncoding]; # ifdef OF_HAVE_THREADS if (!of_mutex_lock(&mutex)) @throw [OFLockFailedException exception]; @try { # endif if (owner != nil) { struct passwd *passwd; if ((passwd = getpwnam([owner cStringWithEncoding: encoding])) == NULL) @throw [OFChangeOwnerFailedException exceptionWithPath: path owner: owner group: group]; uid = passwd->pw_uid; } if (group != nil) { struct group *group_; if ((group_ = getgrnam([group cStringWithEncoding: encoding])) == NULL) @throw [OFChangeOwnerFailedException exceptionWithPath: path owner: owner group: group]; gid = group_->gr_gid; } # ifdef OF_HAVE_THREADS } @finally { if (!of_mutex_unlock(&mutex)) @throw [OFUnlockFailedException exception]; } # endif if (chown([path cStringWithEncoding: encoding], uid, gid)) @throw [OFChangeOwnerFailedException exceptionWithPath: path owner: owner group: group]; } #endif + (void)copyItemAtPath: (OFString*)source |
︙ | ︙ | |||
640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 | } + (void)moveItemAtPath: (OFString*)source toPath: (OFString*)destination { void *pool; of_stat_t s; if (source == nil || destination == nil) @throw [OFInvalidArgumentException exception]; pool = objc_autoreleasePoolPush(); if (of_lstat(destination, &s) == 0) { errno = EEXIST; @throw [OFCopyItemFailedException exceptionWithSourcePath: source destinationPath: destination]; } #ifndef _WIN32 | > > > | | | 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 | } + (void)moveItemAtPath: (OFString*)source toPath: (OFString*)destination { void *pool; of_stat_t s; of_string_encoding_t encoding; if (source == nil || destination == nil) @throw [OFInvalidArgumentException exception]; pool = objc_autoreleasePoolPush(); if (of_lstat(destination, &s) == 0) { errno = EEXIST; @throw [OFCopyItemFailedException exceptionWithSourcePath: source destinationPath: destination]; } encoding = [OFString nativeOSEncoding]; #ifndef _WIN32 if (rename([source cStringWithEncoding: encoding], [destination cStringWithEncoding: encoding])) { #else if (_wrename([source UTF16String], [destination UTF16String])) { #endif if (errno != EXDEV) @throw [OFMoveItemFailedException exceptionWithSourcePath: source destinationPath: destination]; |
︙ | ︙ | |||
723 724 725 726 727 728 729 | [path stringByAppendingPathComponent: item]]; objc_autoreleasePoolPop(pool2); } } #ifndef _WIN32 | | > > | | > > | | > > | | | 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 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 | [path stringByAppendingPathComponent: item]]; objc_autoreleasePoolPop(pool2); } } #ifndef _WIN32 if (remove([path cStringWithEncoding: [OFString nativeOSEncoding]])) #else if (_wremove([path UTF16String])) #endif @throw [OFRemoveItemFailedException exceptionWithPath: path]; objc_autoreleasePoolPop(pool); } #ifdef OF_HAVE_LINK + (void)linkItemAtPath: (OFString*)source toPath: (OFString*)destination { void *pool; of_string_encoding_t encoding; if (source == nil || destination == nil) @throw [OFInvalidArgumentException exception]; pool = objc_autoreleasePoolPush(); encoding = [OFString nativeOSEncoding]; if (link([source cStringWithEncoding: encoding], [destination cStringWithEncoding: encoding]) != 0) @throw [OFLinkFailedException exceptionWithSourcePath: source destinationPath: destination]; objc_autoreleasePoolPop(pool); } #endif #ifdef OF_HAVE_SYMLINK + (void)createSymbolicLinkAtPath: (OFString*)destination withDestinationPath: (OFString*)source { void *pool; of_string_encoding_t encoding; if (source == nil || destination == nil) @throw [OFInvalidArgumentException exception]; pool = objc_autoreleasePoolPush(); encoding = [OFString nativeOSEncoding]; if (symlink([source cStringWithEncoding: encoding], [destination cStringWithEncoding: encoding]) != 0) @throw [OFCreateSymbolicLinkFailedException exceptionWithSourcePath: source destinationPath: destination]; objc_autoreleasePoolPop(pool); } + (OFString*)destinationOfSymbolicLinkAtPath: (OFString*)path { char destination[PATH_MAX]; ssize_t length; of_string_encoding_t encoding; if (path == nil) @throw [OFInvalidArgumentException exception]; encoding = [OFString nativeOSEncoding]; length = readlink([path cStringWithEncoding: encoding], destination, PATH_MAX); if (length < 0) @throw [OFOpenFileFailedException exceptionWithPath: path mode: @"r"]; return [OFString stringWithCString: destination encoding: encoding length: length]; } #endif - init { OF_INVALID_INIT_METHOD |
︙ | ︙ | |||
812 813 814 815 816 817 818 | int flags; if ((flags = parseMode([mode UTF8String])) == -1) @throw [OFInvalidArgumentException exception]; #ifndef _WIN32 if ((_fd = open([path cStringWithEncoding: | | | 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 | int flags; if ((flags = parseMode([mode UTF8String])) == -1) @throw [OFInvalidArgumentException exception]; #ifndef _WIN32 if ((_fd = open([path cStringWithEncoding: [OFString nativeOSEncoding]], flags, DEFAULT_MODE)) == -1) #else if ((_fd = _wopen([path UTF16String], flags, DEFAULT_MODE)) == -1) #endif @throw [OFOpenFileFailedException exceptionWithPath: path mode: mode]; |
︙ | ︙ |
Modified src/OFObject.m from [12e6e740e4] to [ca87b4ce10].
︙ | ︙ | |||
100 101 102 103 104 105 106 | static void uncaughtExceptionHandler(id exception) { OFString *description = [exception description]; OFArray *backtrace = nil; fprintf(stderr, "\nRuntime error: Unhandled exception:\n%s\n", | | | | 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | static void uncaughtExceptionHandler(id exception) { OFString *description = [exception description]; OFArray *backtrace = nil; fprintf(stderr, "\nRuntime error: Unhandled exception:\n%s\n", [description cStringWithEncoding: [OFString nativeOSEncoding]]); if ([exception respondsToSelector: @selector(backtrace)]) backtrace = [exception backtrace]; if (backtrace != nil) { OFString *s = [backtrace componentsJoinedByString: @"\n "]; fprintf(stderr, "\nBacktrace:\n %s\n\n", [s cStringWithEncoding: [OFString nativeOSEncoding]]); } abort(); } #endif static void |
︙ | ︙ | |||
201 202 203 204 205 206 207 | return instance; } const char* _NSPrintForDebugger(id object) { return [[object description] | | | 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | return instance; } const char* _NSPrintForDebugger(id object) { return [[object description] cStringWithEncoding: [OFString nativeOSEncoding]]; } /* References for static linking */ void _references_to_categories_of_OFObject(void) { _OFObject_Serialization_reference = 1; } |
︙ | ︙ |
Modified src/OFPlugin.m from [a9550de16c] to [28a68da273].
︙ | ︙ | |||
43 44 45 46 47 48 49 | OFPlugin *(*initPlugin)(void); OFPlugin *plugin; path = [path stringByAppendingString: @PLUGIN_SUFFIX]; #ifndef _WIN32 if ((handle = dlopen([path cStringWithEncoding: | | | 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | OFPlugin *(*initPlugin)(void); OFPlugin *plugin; path = [path stringByAppendingString: @PLUGIN_SUFFIX]; #ifndef _WIN32 if ((handle = dlopen([path cStringWithEncoding: [OFString nativeOSEncoding]], RTLD_LAZY)) == NULL) #else if ((handle = LoadLibraryW([path UTF16String])) == NULL) #endif @throw [OFInitializationFailedException exceptionWithClass: self]; objc_autoreleasePoolPop(pool); |
︙ | ︙ |
Modified src/OFProcess.m from [1aa806b8bb] to [8b087c9ef5].
︙ | ︙ | |||
136 137 138 139 140 141 142 143 144 145 146 | exceptionWithClass: [self class]]; switch ((_pid = fork())) { case 0:; OFString **objects = [arguments objects]; size_t i, count = [arguments count]; char **argv; argv = [self allocMemoryWithSize: sizeof(char*) count: count + 2]; | > > > | < > | < | < | 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 173 174 175 176 177 178 179 180 | exceptionWithClass: [self class]]; switch ((_pid = fork())) { case 0:; OFString **objects = [arguments objects]; size_t i, count = [arguments count]; char **argv; of_string_encoding_t encoding; argv = [self allocMemoryWithSize: sizeof(char*) count: count + 2]; encoding = [OFString nativeOSEncoding]; argv[0] = (char*)[programName cStringWithEncoding: encoding]; for (i = 0; i < count; i++) argv[i + 1] = (char*)[objects[i] cStringWithEncoding: encoding]; argv[i + 1] = NULL; if (environment != nil) { #ifdef __MACH__ *_NSGetEnviron() = [self OF_environmentForDictionary: environment]; #else environ = [self OF_environmentForDictionary: environment]; #endif } close(_readPipe[0]); close(_writePipe[1]); dup2(_writePipe[0], 0); dup2(_readPipe[1], 1); execvp([program cStringWithEncoding: encoding], argv); @throw [OFInitializationFailedException exceptionWithClass: [self class]]; case -1: @throw [OFInitializationFailedException exceptionWithClass: [self class]]; default: |
︙ | ︙ | |||
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 | #ifndef _WIN32 - (char**)OF_environmentForDictionary: (OFDictionary*)environment { OFEnumerator *keyEnumerator, *objectEnumerator; char **envp; size_t i, count; if (environment == nil) return NULL; count = [environment count]; envp = [self allocMemoryWithSize: sizeof(char*) count: count + 1]; keyEnumerator = [environment keyEnumerator]; objectEnumerator = [environment objectEnumerator]; for (i = 0; i < count; i++) { OFString *key; OFString *object; size_t keyLen, objectLen; key = [keyEnumerator nextObject]; object = [objectEnumerator nextObject]; | > > > | < | < | < | | | 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 | #ifndef _WIN32 - (char**)OF_environmentForDictionary: (OFDictionary*)environment { OFEnumerator *keyEnumerator, *objectEnumerator; char **envp; size_t i, count; of_string_encoding_t encoding; if (environment == nil) return NULL; encoding = [OFString nativeOSEncoding]; count = [environment count]; envp = [self allocMemoryWithSize: sizeof(char*) count: count + 1]; keyEnumerator = [environment keyEnumerator]; objectEnumerator = [environment objectEnumerator]; for (i = 0; i < count; i++) { OFString *key; OFString *object; size_t keyLen, objectLen; key = [keyEnumerator nextObject]; object = [objectEnumerator nextObject]; keyLen = [key cStringLengthWithEncoding: encoding]; objectLen = [object cStringLengthWithEncoding: encoding]; envp[i] = [self allocMemoryWithSize: keyLen + objectLen + 2]; memcpy(envp[i], [key cStringWithEncoding: encoding], keyLen); envp[i][keyLen] = '='; memcpy(envp[i] + keyLen + 1, [object cStringWithEncoding: encoding], objectLen); envp[i][keyLen + objectLen + 1] = '\0'; } envp[i] = NULL; return envp; } |
︙ | ︙ |
Modified src/OFString.h from [b61505c473] to [0173474bc3].
︙ | ︙ | |||
63 64 65 66 67 68 69 | } of_string_encoding_t; enum { OF_STRING_SEARCH_BACKWARDS = 1, OF_STRING_SKIP_EMPTY = 2 }; | < < < | 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | } of_string_encoding_t; enum { OF_STRING_SEARCH_BACKWARDS = 1, OF_STRING_SKIP_EMPTY = 2 }; #ifdef OF_HAVE_BLOCKS /*! * @brief A block for enumerating the lines of a string. * * @param line The current line * @param stop A pointer to a variable that can be set to true to stop the * enumeration |
︙ | ︙ | |||
323 324 325 326 327 328 329 330 331 332 333 334 335 336 | * @brief Creates a path from the specified path components. * * @param components An array of components for the path * @return A new autoreleased OFString */ + (OFString*)pathWithComponents: (OFArray*)components; /*! * @brief Initializes an already allocated OFString from a UTF-8 encoded C * string. * * @param UTF8String A UTF-8 encoded C string to initialize the OFString with * @return An initialized OFString */ | > > > > > > > > > > | 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 | * @brief Creates a path from the specified path components. * * @param components An array of components for the path * @return A new autoreleased OFString */ + (OFString*)pathWithComponents: (OFArray*)components; /*! * @brief Returns the string encoding native to the operating system. * * This is useful to encode strings correctly for passing them to operating * system calls. * * @return The string encoding native to the operating system */ + (of_string_encoding_t)nativeOSEncoding; /*! * @brief Initializes an already allocated OFString from a UTF-8 encoded C * string. * * @param UTF8String A UTF-8 encoded C string to initialize the OFString with * @return An initialized OFString */ |
︙ | ︙ |
Modified src/OFString.m from [699fa5f856] to [548eca2146].
︙ | ︙ | |||
645 646 647 648 649 650 651 652 653 654 655 656 657 658 | [ret appendString: component]; } objc_autoreleasePoolPop(pool); return ret; } - init { if (object_getClass(self) == [OFString class]) { @try { [self doesNotRecognizeSelector: _cmd]; } @catch (id e) { | > > > > > > | 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 | [ret appendString: component]; } objc_autoreleasePoolPop(pool); return ret; } + (of_string_encoding_t)nativeOSEncoding { /* FIXME */ return OF_STRING_ENCODING_UTF_8; } - init { if (object_getClass(self) == [OFString class]) { @try { [self doesNotRecognizeSelector: _cmd]; } @catch (id e) { |
︙ | ︙ | |||
804 805 806 807 808 809 810 | { char *tmp; struct stat st; @try { OFFile *file; | | | | 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 | { char *tmp; struct stat st; @try { OFFile *file; if (stat([path cStringWithEncoding: [OFString nativeOSEncoding]], &st) == -1) @throw [OFOpenFileFailedException exceptionWithPath: path mode: @"rb"]; if (st.st_size > SIZE_MAX) @throw [OFOutOfRangeException exception]; |
︙ | ︙ |
Modified src/OFTCPSocket.m from [5e012e3410] to [367b0cdd47].
︙ | ︙ | |||
361 362 363 364 365 366 367 | memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_NUMERICSERV; snprintf(portCString, 7, "%" PRIu16, port); | < | | 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 | memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_NUMERICSERV; snprintf(portCString, 7, "%" PRIu16, port); if (getaddrinfo([host UTF8String], portCString, &hints, &res0)) @throw [OFAddressTranslationFailedException exceptionWithHost: host socket: self]; for (res = res0; res != NULL; res = res->ai_next) { if ((_socket = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) == INVALID_SOCKET) |
︙ | ︙ | |||
395 396 397 398 399 400 401 | OFDataArray *addrlist; # endif memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_port = OF_BSWAP16_IF_LE(port); | | | | 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 | OFDataArray *addrlist; # endif memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_port = OF_BSWAP16_IF_LE(port); if ((addr.sin_addr.s_addr = inet_addr([host UTF8String])) != (in_addr_t)(-1)) { if ((_socket = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) { @throw [OFConnectionFailedException exceptionWithHost: host port: port socket: self]; } |
︙ | ︙ | |||
427 428 429 430 431 432 433 | } # ifdef OF_HAVE_THREADS addrlist = [[OFDataArray alloc] initWithItemSize: sizeof(char**)]; [mutex lock]; # endif | | < | 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 | } # ifdef OF_HAVE_THREADS addrlist = [[OFDataArray alloc] initWithItemSize: sizeof(char**)]; [mutex lock]; # endif if ((he = gethostbyname([host UTF8String])) == NULL) { # ifdef OF_HAVE_THREADS [addrlist release]; [mutex unlock]; # endif @throw [OFAddressTranslationFailedException exceptionWithHost: host socket: self]; |
︙ | ︙ | |||
572 573 574 575 576 577 578 | memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_NUMERICSERV | AI_PASSIVE; snprintf(portCString, 7, "%" PRIu16, port); | < | | 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 | memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_NUMERICSERV | AI_PASSIVE; snprintf(portCString, 7, "%" PRIu16, port); if (getaddrinfo([host UTF8String], portCString, &hints, &res)) @throw [OFAddressTranslationFailedException exceptionWithHost: host socket: self]; if ((_socket = socket(res->ai_family, SOCK_STREAM, 0)) == INVALID_SOCKET) @throw [OFBindFailedException exceptionWithHost: host |
︙ | ︙ | |||
603 604 605 606 607 608 609 | freeaddrinfo(res); #else memset(&addr, 0, sizeof(addr)); addr.in.sin_family = AF_INET; addr.in.sin_port = OF_BSWAP16_IF_LE(port); | | | | < | 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 | freeaddrinfo(res); #else memset(&addr, 0, sizeof(addr)); addr.in.sin_family = AF_INET; addr.in.sin_port = OF_BSWAP16_IF_LE(port); if ((addr.in.sin_addr.s_addr = inet_addr([host UTF8String])) == (in_addr_t)(-1)) { # ifdef OF_HAVE_THREADS [mutex lock]; @try { # endif struct hostent *he; if ((he = gethostbyname([host UTF8String])) == NULL) @throw [OFAddressTranslationFailedException exceptionWithHost: host socket: self]; if (he->h_addrtype != AF_INET || he->h_addr_list[0] == NULL) { @throw [OFAddressTranslationFailedException |
︙ | ︙ | |||
758 759 760 761 762 763 764 | @try { if (getnameinfo((struct sockaddr*)_sockAddr, _sockAddrLen, host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST | NI_NUMERICSERV)) @throw [OFAddressTranslationFailedException exceptionWithSocket: self]; | | < | < | 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 | @try { if (getnameinfo((struct sockaddr*)_sockAddr, _sockAddrLen, host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST | NI_NUMERICSERV)) @throw [OFAddressTranslationFailedException exceptionWithSocket: self]; return [OFString stringWithUTF8String: host]; } @finally { [self freeMemory: host]; } #else # ifdef OF_HAVE_THREADS [mutex lock]; @try { # endif host = inet_ntoa(((struct sockaddr_in*)_sockAddr)->sin_addr); if (host == NULL) @throw [OFAddressTranslationFailedException exceptionWithSocket: self]; return [OFString stringWithUTF8String: host]; # ifdef OF_HAVE_THREADS } @finally { [mutex unlock]; } # endif #endif |
︙ | ︙ |