Difference between revisions of "Truxton file readline"
Jump to navigation
Jump to search
(Created page with "This will read a single line from the file contents. =Syntax= <syntaxhighlight lang="C"> int64_t truxton_file_readline( uint64_t file_handle, uint8_t * buffer, size_t buffer_...") |
|||
| (2 intermediate revisions by the same user not shown) | |||
| Line 2: | Line 2: | ||
=Syntax= | =Syntax= | ||
| − | < | + | <source lang="C"> |
| − | int64_t truxton_file_readline( uint64_t file_handle, uint8_t * buffer, size_t buffer_size, int64_t limit ) | + | int64_t truxton_file_readline( uint64_t file_handle, uint8_t * buffer, size_t buffer_size, int64_t limit ); |
| − | </ | + | </source> |
=Parameters= | =Parameters= | ||
==<code>file_handle</code>== | ==<code>file_handle</code>== | ||
| − | The handle created by the [[truxton_file_open_id]] | + | The handle created by the [[truxton_file_open_id]] or [[truxton_file_open_md5]] call. |
==<code>buffer</code>== | ==<code>buffer</code>== | ||
| Line 24: | Line 24: | ||
=Sample= | =Sample= | ||
| − | + | <source lang="C" highlight="14"> | |
| − | < | + | void print_line( uint64_t truxton ) |
| − | void print_line(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 45: | Line 44: | ||
} | } | ||
| − | truxton_file_free(file); | + | truxton_file_free( file ); |
} | } | ||
| − | </ | + | </source> |
Latest revision as of 17:35, 10 February 2021
This will read a single line from the file contents.
Contents
Syntax
int64_t truxton_file_readline( uint64_t file_handle, uint8_t * buffer, size_t buffer_size, int64_t limit );
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 that can be written to buffer.
limit
The maximum number of bytes to write to buffer.
Return value
The number of bytes written to buffer on success, -1 on error.
This can be less than buffer_size if the line read is smaller than buffer_size or if the limit parameter is less than buffer_size.
Sample
void print_line( uint64_t truxton )
{
uint64_t file = truxton_file_open_id( truxton, "5ed3aeb7-3da4-5f5c-8c8f-af5200000000" );
if ( file != 0 )
{
return( 0 );
}
char line_of_text[ 256 ];
memset( line_of_text, 0x00, sizeof( line_of_text ) );
if ( truxton_file_readline( file, line_of_text, sizeof( line_of_text ), sizeof( line_of_text ) - 1 ) >= 0 )
{
// We succeeded in reading a line of text
printf( "%s\n", line_of_text );
}
truxton_file_free( file );
}