Truxton file readline

From truxwiki.com
Revision as of 17:35, 10 February 2021 by Sam (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This will read a single line from the file 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 );
}