Difference between revisions of "Truxton file read"
Jump to navigation
Jump to search
(Created page with "This is how you read data from the file. =Syntax= <syntaxhighlight lang="C"> int64_t truxton_file_read( uint64_t file_handle, uint8_t * buffer, size_t buffer_size ) </syntaxh...") |
|||
| (2 intermediate revisions by the same user not shown) | |||
| Line 2: | Line 2: | ||
=Syntax= | =Syntax= | ||
| − | < | + | <source lang="C"> |
| − | int64_t truxton_file_read( uint64_t file_handle, uint8_t * buffer, size_t buffer_size ) | + | int64_t truxton_file_read( uint64_t file_handle, uint8_t * buffer, size_t buffer_size ); |
| − | </ | + | </source> |
=Parameters= | =Parameters= | ||
==<code>file_handle</code>== | ==<code>file_handle</code>== | ||
| − | + | The handle created by the [[truxton_file_open_id]] or [[truxton_file_open_md5]] call. | |
| − | The handle created by the [[truxton_file_open_id]] | ||
==<code>buffer</code>== | ==<code>buffer</code>== | ||
| Line 21: | Line 20: | ||
=Sample= | =Sample= | ||
| − | + | <source lang="C" highlight="16"> | |
| − | < | + | int does_file_have_deep_philosophical_meaning( uint64_t truxton ) |
| − | int does_file_have_deep_philosophical_meaning(uint64_t truxton) | ||
{ | { | ||
| − | uint64_t file = truxton_file_open_id(truxton, "5ed3aeb7-3da4-5f5c-8c8f-af5200000000"); | + | uint64_t file = truxton_file_open_id( truxton, "5ed3aeb7-3da4-5f5c-8c8f-af5200000000" ); |
if ( file != 0 ) | if ( file != 0 ) | ||
{ | { | ||
| − | return(0); | + | return( 0 ); |
} | } | ||
| Line 36: | Line 34: | ||
uint32_t integer_value = 0; | uint32_t integer_value = 0; | ||
| − | truxton_file_seek(file, 42, 0 ); | + | truxton_file_seek( file, 42, 0 ); |
if ( truxton_file_read( file, &integer_value, sizeof(integer_value) ) == sizeof(integer_value) ) | if ( truxton_file_read( file, &integer_value, sizeof(integer_value) ) == sizeof(integer_value) ) | ||
| Line 48: | Line 46: | ||
} | } | ||
| − | truxton_file_free(file); | + | truxton_file_free( file ); |
return( return_value ); | return( return_value ); | ||
} | } | ||
| − | </ | + | </source> |
Latest revision as of 17:36, 10 February 2021
This is how you read data from the file.
Syntax
int64_t truxton_file_read( uint64_t file_handle, uint8_t * buffer, size_t buffer_size );
Parameters
file_handle
The handle created by the truxton_file_open_id or truxton_file_open_md5 call.
buffer
The memory where the bytes will be written.
buffer_size
The number of bytes to read from the file and write to the buffer.
Return value
The number of bytes written to buffer.
Sample
int does_file_have_deep_philosophical_meaning( uint64_t truxton )
{
uint64_t file = truxton_file_open_id( truxton, "5ed3aeb7-3da4-5f5c-8c8f-af5200000000" );
if ( file != 0 )
{
return( 0 );
}
int return_value = 0;
uint32_t integer_value = 0;
truxton_file_seek( file, 42, 0 );
if ( truxton_file_read( file, &integer_value, sizeof(integer_value) ) == sizeof(integer_value) )
{
// We succeeded in reading all of the bytes in the integer
if ( integer_value == 42 )
{
return_value = 1;
}
}
truxton_file_free( file );
return( return_value );
}