Data update
This commit is contained in:
parent
81fd053722
commit
52a6ef48dd
10248 changed files with 63654 additions and 6775 deletions
43
Task/Truncate-a-file/FutureBasic/truncate-a-file.basic
Normal file
43
Task/Truncate-a-file/FutureBasic/truncate-a-file.basic
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
include "NSLog.incl"
|
||||
|
||||
void local fn ShowFileContents( fileURL as CFURLRef )
|
||||
CFStringRef string = fn StringWithContentsOfURL( fileURL, NSUTF8StringEncoding, NULL )
|
||||
NSLog(@"%@",string)
|
||||
end fn
|
||||
|
||||
void local fn TruncateFile( fileURL as CFURLRef, length as UInt64 )
|
||||
ErrorRef err = NULL
|
||||
FileHandleRef fh = fn FileHandleForUpdatingURL( fileURL, @err )
|
||||
if ( !fh )
|
||||
NSLog(@"%@",err)
|
||||
return
|
||||
end if
|
||||
|
||||
UInt64 offset
|
||||
fn FileHandleSeekToEnd( fh, @offset, NULL )
|
||||
if ( length >= offset )
|
||||
NSLog(@"Error: Truncate length is not less than file length.")
|
||||
return
|
||||
end if
|
||||
|
||||
if ( fn FileHandleTruncateAtOffset( fh, length, @err ) )
|
||||
fn ShowFileContents( fileURL )
|
||||
else
|
||||
NSLog(@"%@",err)
|
||||
end if
|
||||
end fn
|
||||
|
||||
void local fn Doit
|
||||
// create
|
||||
CFURLRef desktopURL = fn FileManagerURLForDirectory( NSDesktopDirectory, NSUserDomainMask )
|
||||
CFURLRef fileURL = fn URLByAppendingPathComponent( desktopURL, @"MyFile.txt" )
|
||||
fn StringWriteToURL( @"abcdefghijklmnopqrstuvwxyz", fileURL, YES, NSUTF8StringEncoding, NULL )
|
||||
fn ShowFileContents( fileURL )
|
||||
|
||||
// truncate
|
||||
fn TruncateFile( fileURL, 13 )
|
||||
end fn
|
||||
|
||||
fn DoIt
|
||||
|
||||
HandleEvents
|
||||
Loading…
Add table
Add a link
Reference in a new issue