Difference between revisions of "Truxton file get size"
Jump to navigation
Jump to search
(→Sample) |
|||
| (2 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
This retrieves the size of the file as reported by the filesystem of the file. | This retrieves the size of the file as reported by the filesystem of the file. | ||
| − | It corresponds to the <code>OSLength</code> column of the <code>[[File Table | File]]</code> table. | + | It corresponds to the <code>[OSLength]</code> column of the <code><nowiki>[</nowiki>[[File Table|File]]<nowiki>]</nowiki></code> table. |
=Syntax= | =Syntax= | ||
| − | < | + | <source lang="C"> |
uint64_t truxton_file_get_size( uint64_t file_handle ); | uint64_t truxton_file_get_size( uint64_t file_handle ); | ||
| − | </ | + | </source> |
=Parameters= | =Parameters= | ||
| Line 16: | Line 16: | ||
=Sample= | =Sample= | ||
| − | + | <source lang="C" highlight="10"> | |
| − | < | + | void print_it( uint64_t truxton ) |
| − | |||
{ | { | ||
| − | uint64_t file = truxton_file_open_md5(truxton, "9ec8fb6095c35eff2b236863b7caaf10"); | + | uint64_t file = truxton_file_open_md5( truxton, "9ec8fb6095c35eff2b236863b7caaf10" ); |
if ( file != 0 ) | if ( file != 0 ) | ||
{ | { | ||
| − | return | + | return; |
} | } | ||
| Line 33: | Line 32: | ||
truxton_file_free( file ); | truxton_file_free( file ); | ||
} | } | ||
| − | </ | + | </source> |
Note, the <code>PRIu64</code> in the sample code above is the new standard way of [https://en.wikipedia.org/wiki/C_data_types#Printf_and_scanf_format_specifiers formatting] a 64-bit integer in C. | Note, the <code>PRIu64</code> in the sample code above is the new standard way of [https://en.wikipedia.org/wiki/C_data_types#Printf_and_scanf_format_specifiers formatting] a 64-bit integer in C. | ||
Over the years, different compilers on different operating systems used different format specifiers for things, these <code>PRI</code> macros, along with some tricky string concatenation the compilers perform for you, allow you to maintain a single code base without a bunch of macro magic. | Over the years, different compilers on different operating systems used different format specifiers for things, these <code>PRI</code> macros, along with some tricky string concatenation the compilers perform for you, allow you to maintain a single code base without a bunch of macro magic. | ||
Latest revision as of 04:46, 13 February 2021
This retrieves the size of the file as reported by the filesystem of the file.
It corresponds to the [OSLength] column of the [File] table.
Syntax
uint64_t truxton_file_get_size( uint64_t file_handle );
Parameters
file_handle
The handle created by the truxton_file_open_id or truxton_file_open_md5 call.
Return value
The size of the file as reported by the operating system. This can differ from the number of bytes written to the depot.
Sample
void print_it( uint64_t truxton )
{
uint64_t file = truxton_file_open_md5( truxton, "9ec8fb6095c35eff2b236863b7caaf10" );
if ( file != 0 )
{
return;
}
uint64_t file_size = truxton_file_get_size( file );
printf( "Size is %" PRIu64 "\n", file_size );
truxton_file_free( file );
}
Note, the PRIu64 in the sample code above is the new standard way of formatting a 64-bit integer in C.
Over the years, different compilers on different operating systems used different format specifiers for things, these PRI macros, along with some tricky string concatenation the compilers perform for you, allow you to maintain a single code base without a bunch of macro magic.