mirror of
https://github.com/darlinghq/darling-cocotron.git
synced 2025-02-12 07:10:28 +00:00
- NSFileHandle_win32 fix by Tobias Platen
This commit is contained in:
parent
258c1e630b
commit
9567075ce6
@ -152,15 +152,83 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
return result;
|
||||
}
|
||||
|
||||
-(NSData *)readDataToEndOfFile {
|
||||
NSUnimplementedMethod();
|
||||
return nil;
|
||||
- (NSData *)readDataToEndOfFile {
|
||||
#define B 4096
|
||||
NSMutableData *result=[NSMutableData dataWithLength:B];
|
||||
DWORD readLength=0;
|
||||
DWORD sum=0;
|
||||
DWORD error;
|
||||
LPVOID lpMsgBuf;
|
||||
|
||||
|
||||
while(GetLastError()!=ERROR_BROKEN_PIPE &&
|
||||
ReadFile(_handle,[result mutableBytes]+sum,B,&readLength,NULL))
|
||||
{
|
||||
//[result appendBytes:buffer length:readLength];
|
||||
sum+=readLength;
|
||||
[result increaseLengthBy:B];
|
||||
}
|
||||
[result setLength:sum];
|
||||
#undef B
|
||||
|
||||
error=GetLastError();
|
||||
if(error!=ERROR_BROKEN_PIPE)
|
||||
{
|
||||
FormatMessage(
|
||||
FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||
FORMAT_MESSAGE_FROM_SYSTEM |
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL,
|
||||
error,
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
(LPTSTR) &lpMsgBuf,
|
||||
0, NULL );
|
||||
NSRaiseException(NSFileHandleOperationException, self, _cmd,
|
||||
@"read(%d) %s", _handle,lpMsgBuf);
|
||||
return nil;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
- (NSData *)availableData {
|
||||
NSMutableData *mutableData = [NSMutableData dataWithLength:4096];
|
||||
DWORD count;
|
||||
BOOL success;
|
||||
DWORD error;
|
||||
LPVOID lpMsgBuf;
|
||||
|
||||
OVERLAPPED ov;
|
||||
memset(&ov,0,sizeof(ov));
|
||||
ReadFile(_handle, [mutableData mutableBytes], 4096,NULL,&ov);
|
||||
success=GetOverlappedResult(_handle,&ov,&count,TRUE);
|
||||
|
||||
|
||||
if (!success) {
|
||||
error=GetLastError();
|
||||
if(error!=ERROR_BROKEN_PIPE)
|
||||
{
|
||||
FormatMessage(
|
||||
FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||
FORMAT_MESSAGE_FROM_SYSTEM |
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL,
|
||||
error,
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
(LPTSTR) &lpMsgBuf,
|
||||
0, NULL );
|
||||
NSRaiseException(NSFileHandleOperationException, self, _cmd,
|
||||
@"read(%d) %s", _handle,lpMsgBuf);
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
|
||||
[mutableData setLength:count];
|
||||
|
||||
return mutableData;
|
||||
}
|
||||
|
||||
-(NSData *)availableData {
|
||||
NSUnimplementedMethod();
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
||||
|
||||
-(void)writeData:(NSData *)data {
|
||||
DWORD bytesWritten=0;
|
||||
|
@ -8,6 +8,9 @@
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
8D5B49B0048680CD000E48DA /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C167DFE841241C02AAC07 /* InfoPlist.strings */; };
|
||||
998CA8490E6C3741009B2664 /* FileHandle.m in Sources */ = {isa = PBXBuildFile; fileRef = 998CA8480E6C3741009B2664 /* FileHandle.m */; };
|
||||
998CA84A0E6C3741009B2664 /* FileHandle.m in Sources */ = {isa = PBXBuildFile; fileRef = 998CA8480E6C3741009B2664 /* FileHandle.m */; };
|
||||
998CA84B0E6C3741009B2664 /* FileHandle.m in Sources */ = {isa = PBXBuildFile; fileRef = 998CA8480E6C3741009B2664 /* FileHandle.m */; };
|
||||
C80F9AE60E58BD7E00ECD487 /* MessageBenchmark.m in Sources */ = {isa = PBXBuildFile; fileRef = C80F9AE50E58BD7E00ECD487 /* MessageBenchmark.m */; settings = {COMPILER_FLAGS = "-fno-objc-msgsend"; }; };
|
||||
C80F9B7B0E58C93800ECD487 /* MessageSend.m in Sources */ = {isa = PBXBuildFile; fileRef = C80F9B7A0E58C93800ECD487 /* MessageSend.m */; settings = {COMPILER_FLAGS = "-fobjc-msgsend"; }; };
|
||||
C80F9D170E59E45100ECD487 /* CrashCatcher.m in Sources */ = {isa = PBXBuildFile; fileRef = C80F9D160E59E45100ECD487 /* CrashCatcher.m */; };
|
||||
@ -104,6 +107,8 @@
|
||||
32DBCF630370AF2F00C91783 /* UnitTests_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UnitTests_Prefix.pch; sourceTree = "<group>"; };
|
||||
8D5B49B6048680CD000E48DA /* UnitTests.octest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = UnitTests.octest; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
8D5B49B7048680CD000E48DA /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
998CA8470E6C3741009B2664 /* FileHandle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FileHandle.h; sourceTree = "<group>"; };
|
||||
998CA8480E6C3741009B2664 /* FileHandle.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FileHandle.m; sourceTree = "<group>"; };
|
||||
C80F9AE40E58BD7E00ECD487 /* MessageBenchmark.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MessageBenchmark.h; sourceTree = "<group>"; };
|
||||
C80F9AE50E58BD7E00ECD487 /* MessageBenchmark.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MessageBenchmark.m; sourceTree = "<group>"; };
|
||||
C80F9B7A0E58C93800ECD487 /* MessageSend.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MessageSend.m; sourceTree = "<group>"; };
|
||||
@ -207,6 +212,8 @@
|
||||
08FB77AFFE84173DC02AAC07 /* Classes */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
998CA8470E6C3741009B2664 /* FileHandle.h */,
|
||||
998CA8480E6C3741009B2664 /* FileHandle.m */,
|
||||
C8C8027F0DB51FEF0089C0D7 /* KVC.h */,
|
||||
C8C802800DB51FEF0089C0D7 /* KVC.m */,
|
||||
C827EB390DB63FFA00360D99 /* Properties.h */,
|
||||
@ -463,6 +470,7 @@
|
||||
C80F9AE60E58BD7E00ECD487 /* MessageBenchmark.m in Sources */,
|
||||
C80F9B7B0E58C93800ECD487 /* MessageSend.m in Sources */,
|
||||
C80F9D170E59E45100ECD487 /* CrashCatcher.m in Sources */,
|
||||
998CA8490E6C3741009B2664 /* FileHandle.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@ -481,6 +489,7 @@
|
||||
C84F02C50E1F8F17000C03D6 /* ObjCXXExceptions.mm in Sources */,
|
||||
C8A393200E48B72300A9C289 /* PropertyListUnarchiving.m in Sources */,
|
||||
C80F9D180E59E45100ECD487 /* CrashCatcher.m in Sources */,
|
||||
998CA84B0E6C3741009B2664 /* FileHandle.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@ -499,6 +508,7 @@
|
||||
C80F9D190E59E45100ECD487 /* CrashCatcher.m in Sources */,
|
||||
C8F971D10E6AD503007CBB04 /* MessageBenchmark.m in Sources */,
|
||||
C8F971D20E6AD503007CBB04 /* MessageSend.m in Sources */,
|
||||
998CA84A0E6C3741009B2664 /* FileHandle.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user