Difference between revisions of "Truxton file readline"

From truxwiki.com
Jump to navigation Jump to search
Line 3: Line 3:
 
=Syntax=
 
=Syntax=
 
<syntaxhighlight lang="C">
 
<syntaxhighlight 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 );
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Line 24: Line 24:
  
 
=Sample=
 
=Sample=
 
 
<syntaxhighlight lang="C" highlight="14">
 
<syntaxhighlight lang="C" highlight="14">
 
void print_line(uint64_t truxton)
 
void print_line(uint64_t truxton)

Revision as of 06:57, 10 June 2020

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);
}