From 9c5107ed90643fb445bd6bbdb79750233b4b8e61 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Sat, 7 Sep 2024 17:49:04 -0400 Subject: [PATCH] Add getOffset:error: implementation to base --- Headers/Foundation/NSFileHandle.h | 3 +++ Source/GSFileHandle.m | 1 - Source/NSFileHandle.m | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Headers/Foundation/NSFileHandle.h b/Headers/Foundation/NSFileHandle.h index b09cfef2f8..683409769c 100644 --- a/Headers/Foundation/NSFileHandle.h +++ b/Headers/Foundation/NSFileHandle.h @@ -76,6 +76,9 @@ GS_EXPORT_CLASS - (NSData*) readDataToEndOfFile; - (NSData*) readDataOfLength: (unsigned int)len; - (void) writeData: (NSData*)item; +#if OS_API_VERSION(MAC_OS_X_VERSION_10_15, GS_API_LATEST) +- (BOOL) getOffset: (unsigned long long *)offsetInFile error: (NSError **)error; +#endif // Asynchronous I/O operations diff --git a/Source/GSFileHandle.m b/Source/GSFileHandle.m index 13a9c29b75..cdd74c18bc 100644 --- a/Source/GSFileHandle.m +++ b/Source/GSFileHandle.m @@ -1439,7 +1439,6 @@ - (void) writeData: (NSData*)item } } - // Asynchronous I/O operations - (void) acceptConnectionInBackgroundAndNotifyForModes: (NSArray*)modes diff --git a/Source/NSFileHandle.m b/Source/NSFileHandle.m index 29a7715ddf..bbeab0a3ed 100644 --- a/Source/NSFileHandle.m +++ b/Source/NSFileHandle.m @@ -320,6 +320,25 @@ - (void) writeData: (NSData*)item [self subclassResponsibility: _cmd]; } +/** + * Get the current position in the file. + */ +- (BOOL) getOffset: (unsigned long long *)offsetInFile error: (NSError **)error +{ + BOOL result = YES; + + // We can do the concrete implementation here since the method relies on + // offsetInFile to get the offset. + *error = nil; + *offsetInFile = [self offsetInFile]; + if (*offsetInFile == -1) + { + *offsetInFile = 0; + result = NO; + } + + return result; +} // Asynchronous I/O operations