Skip to content

Commit e18800b

Browse files
committed
rtlib: FileSetEof, rename truncate internals to seteof
1 parent 7c59d07 commit e18800b

File tree

7 files changed

+29
-25
lines changed

7 files changed

+29
-25
lines changed

Diff for: inc/file.bi

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ declare function FileDateTime alias "fb_FileDateTime" ( byval filename as zstrin
3939
#endif
4040

4141
declare function FileFlush alias "fb_FileFlush" ( byval filenumber as long = -1, byval systembuffer as long = 0 ) as long
42-
declare function FileTruncate alias "fb_FileTruncate" ( byval filenumber as long ) as long
42+
declare function FileSetEof alias "fb_FileSetEof" ( byval filenumber as long ) as long
4343

4444
#endif

Diff for: src/rtlib/dos/file_hseteof.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
/* low-level truncate file */
1+
/* low-level truncate / set end of file */
22

33
#include "../fb.h"
44
#include <unistd.h>
55

6-
int fb_hFileTruncateEx( FILE *f )
6+
int fb_hFileSetEofEx( FILE *f )
77
{
88
fb_off_t pos;
99

Diff for: src/rtlib/fb_file.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,9 @@ FBCALL int fb_FileGetArrayLargeIOB( int fnum, long long pos, FBARRAY *d
247247

248248
FBCALL int fb_FileEof ( int fnum );
249249
int fb_FileEofEx ( FB_FILE *handle );
250-
FBCALL int fb_FileTruncate ( int fnum );
251-
int fb_FileTruncateEx ( FB_FILE *handle );
252-
int fb_hFileTruncateEx ( FILE *f );
250+
FBCALL int fb_FileSetEof ( int fnum );
251+
int fb_FileSetEofEx ( FB_FILE *handle );
252+
int fb_hFileSetEofEx ( FILE *f );
253253
FBCALL int fb_FileFlush ( int fnum, int systembuffers );
254254
int fb_FileFlushEx ( FB_FILE *handle, int systembuffers );
255255
FBCALL void fb_FileFlushAll ( int systembuffers );

Diff for: src/rtlib/file_seteof.c

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* truncate file */
1+
/* truncate / set end of file */
22

33
#include "fb.h"
44

@@ -15,9 +15,13 @@
1515
For BINARY, OUTPUT, and APPEND files the current position is the byte.
1616
1717
For RANDOM files, the current position is the record.
18+
19+
If the position less than current length of file, then the file is
20+
shortened. If the position is after the current length of file, then
21+
the file is lengthened.
1822
*/
1923

20-
int fb_FileTruncateEx( FB_FILE *handle )
24+
int fb_FileSetEofEx( FB_FILE *handle )
2125
{
2226
int res;
2327

@@ -47,15 +51,15 @@ int fb_FileTruncateEx( FB_FILE *handle )
4751

4852
/* call the platform specifc implementation */
4953
if( res == FB_RTERROR_OK )
50-
res = fb_hFileTruncateEx( (FILE*)handle->opaque );
54+
res = fb_hFileSetEofEx( (FILE*)handle->opaque );
5155

5256
FB_UNLOCK();
5357

5458
return res;
5559
}
5660

5761
/*:::::*/
58-
FBCALL int fb_FileTruncate( int fnum )
62+
FBCALL int fb_FileSetEof( int fnum )
5963
{
60-
return fb_FileTruncateEx(FB_FILE_TO_HANDLE(fnum));
64+
return fb_FileSetEofEx(FB_FILE_TO_HANDLE(fnum));
6165
}

Diff for: src/rtlib/unix/file_hseteof.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
/* low-level truncate file */
1+
/* low-level truncate / set end of file */
22

33
#include "../fb.h"
44
#include <unistd.h>
55

6-
int fb_hFileTruncateEx( FILE *f )
6+
int fb_hFileSetEofEx( FILE *f )
77
{
88
fb_off_t pos;
99

Diff for: src/rtlib/win32/file_hseteof.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* low-level truncate file */
1+
/* low-level truncate / set end of file */
22

33
#include "../fb.h"
44
#include <unistd.h>
@@ -17,7 +17,7 @@
1717
our current setup
1818
*/
1919

20-
int fb_hFileTruncateEx( FILE *f )
20+
int fb_hFileSetEofEx( FILE *f )
2121
{
2222

2323
#if defined( FTRUNCATE_DEFINED )

Diff for: tests/file/file-seteof.bas

+10-10
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
#include "file.bi"
44

5-
SUITE( fbc_tests.file_.file_truncate )
5+
SUITE( fbc_tests.file_.file_seteof )
66

7-
const filename = "./file/truncate.tmp"
7+
const filename = "./file/seteof.tmp"
88

9-
TEST( truncatebinary )
9+
TEST( seteofbinary )
1010

11-
#macro chkTruncate( i )
11+
#macro chkSetEof( i )
1212
seek #1, i+1
1313
CU_ASSERT( seek(1) = (i+1) )
14-
FileTruncate( 1 )
14+
FileSetEof( 1 )
1515
CU_ASSERT( lof(1) = i )
1616
CU_ASSERT( seek(1) = (i+1) )
1717
#endmacro
@@ -20,24 +20,24 @@ SUITE( fbc_tests.file_.file_truncate )
2020
close #1
2121
if( open( filename for binary as #1 ) = 0 ) then
2222

23-
'' truncate can be used to increase file size
23+
'' FileSetEof can be used to increase file size
2424
for i as integer = 0 to 10000 step 1000
25-
chkTruncate( 1 )
25+
chkSetEof( 1 )
2626
next
2727

2828
'' or decrease file size
2929
for i as integer = 10000 to 0 step -1000
30-
chkTruncate( 1 )
30+
chkSetEof( 1 )
3131
next
3232

3333
close #1
3434

3535
kill filename
3636
else
37-
CU_FAIL( "truncatebinary: failed" )
37+
CU_FAIL( "seteofbinary: failed" )
3838
end if
3939
else
40-
CU_FAIL( "truncatebinary: failed" )
40+
CU_FAIL( "seteofbinary: failed" )
4141
end if
4242
END_TEST
4343

0 commit comments

Comments
 (0)