mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 00:41:02 +00:00
check for a valid file and check for ftruncate() result and throw exception in case
This commit is contained in:
parent
e20b3d59fc
commit
72e8335bd9
1 changed files with 9 additions and 2 deletions
|
@ -1880,9 +1880,16 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
|
|||
|
||||
- (void) truncateFileAtOffset: (unsigned long long)pos
|
||||
{
|
||||
if (isStandardFile && descriptor >= 0)
|
||||
if (!(isStandardFile && descriptor >= 0))
|
||||
{
|
||||
(void)ftruncate(descriptor, pos);
|
||||
[NSException raise: NSFileHandleOperationException
|
||||
format: @"attempt to truncate invalid file"];
|
||||
|
||||
}
|
||||
if (ftruncate(descriptor, pos) < 0)
|
||||
{
|
||||
[NSException raise: NSFileHandleOperationException
|
||||
format: @"truncation failed"];
|
||||
}
|
||||
[self seekToFileOffset: pos];
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue