Differences From Artifact [d95eac9ee4]:
- File src/OFFile.m — part of check-in [d533c864ab] at 2011-10-05 22:39:21 on branch trunk — Fix error checking on reading in OFFile. (user: js, size: 17262) [annotate] [blame] [check-ins using]
To Artifact [ec14d28310]:
- File
src/OFFile.m
— part of check-in
[36434923ad]
at
2011-10-07 11:19:58
on branch trunk
— Don't depend on OFMutex in OFFile.
+[load] creates 3 instances of OFFile and thus +[initialize] is also
called. This causes problems if OFMutex has not been registered with
the runtime yet. It had been fixed by changing the order of .o files,
but this is too fragile and thus it has been changed to use of_mutex_t. (user: js, size: 17671) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
35 36 37 38 39 40 41 | # include <grp.h> #endif #import "OFFile.h" #import "OFString.h" #import "OFArray.h" #ifdef OF_THREADS | | > > > | 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | # include <grp.h> #endif #import "OFFile.h" #import "OFString.h" #import "OFArray.h" #ifdef OF_THREADS # import "threading.h" #endif #import "OFDate.h" #import "OFApplication.h" #import "OFAutoreleasePool.h" #import "OFChangeDirectoryFailedException.h" #import "OFChangeFileModeFailedException.h" #import "OFChangeFileOwnerFailedException.h" #import "OFCreateDirectoryFailedException.h" #import "OFDeleteDirectoryFailedException.h" #import "OFDeleteFileFailedException.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFLinkFailedException.h" #import "OFMutexLockFailedException.h" #import "OFMutexUnlockFailedException.h" #import "OFNotImplementedException.h" #import "OFOpenFileFailedException.h" #import "OFOutOfMemoryException.h" #import "OFReadFailedException.h" #import "OFRenameFileFailedException.h" #import "OFSeekFailedException.h" #import "OFSymlinkFailedException.h" |
︙ | ︙ | |||
89 90 91 92 93 94 95 | #define DIR_MODE DEFAULT_MODE | S_IXUSR | S_IXGRP | S_IXOTH OFStream *of_stdin = nil; OFStream *of_stdout = nil; OFStream *of_stderr = nil; #if defined(OF_THREADS) && !defined(_WIN32) | | | 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | #define DIR_MODE DEFAULT_MODE | S_IXUSR | S_IXGRP | S_IXOTH OFStream *of_stdin = nil; OFStream *of_stdout = nil; OFStream *of_stderr = nil; #if defined(OF_THREADS) && !defined(_WIN32) static of_mutex_t mutex; #endif static int parse_mode(const char *mode) { if (!strcmp(mode, "r")) return O_RDONLY; if (!strcmp(mode, "rb")) |
︙ | ︙ | |||
159 160 161 162 163 164 165 | of_stdout = [[OFFileSingleton alloc] initWithFileDescriptor: 1]; of_stderr = [[OFFileSingleton alloc] initWithFileDescriptor: 2]; } #if defined(OF_THREADS) && !defined(_WIN32) + (void)initialize { | | > | > > > | 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | of_stdout = [[OFFileSingleton alloc] initWithFileDescriptor: 1]; of_stderr = [[OFFileSingleton alloc] initWithFileDescriptor: 2]; } #if defined(OF_THREADS) && !defined(_WIN32) + (void)initialize { if (self != [OFFile class]) return; if (!of_mutex_new(&mutex)) @throw [OFInitializationFailedException exceptionWithClass: self]; } #endif + fileWithPath: (OFString*)path mode: (OFString*)mode { return [[[self alloc] initWithPath: path |
︙ | ︙ | |||
385 386 387 388 389 390 391 | gid_t gid = -1; if (owner == nil && group == nil) @throw [OFInvalidArgumentException exceptionWithClass: self selector: _cmd]; # ifdef OF_THREADS | > > | | 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 | gid_t gid = -1; if (owner == nil && group == nil) @throw [OFInvalidArgumentException exceptionWithClass: self selector: _cmd]; # ifdef OF_THREADS if (!of_mutex_lock(&mutex)) @throw [OFMutexLockFailedException exceptionWithClass: self mutex: nil]; @try { # endif if (owner != nil) { struct passwd *passwd; if ((passwd = getpwnam([owner cStringWithEncoding: |
︙ | ︙ | |||
418 419 420 421 422 423 424 | owner: owner group: group]; gid = group_->gr_gid; } # ifdef OF_THREADS } @finally { | > > > | | 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 | owner: owner group: group]; gid = group_->gr_gid; } # ifdef OF_THREADS } @finally { if (!of_mutex_unlock(&mutex)) @throw [OFMutexUnlockFailedException exceptionWithClass: self mutex: nil]; } # endif if (chown([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE], uid, gid)) @throw [OFChangeFileOwnerFailedException exceptionWithClass: self |
︙ | ︙ |