Difference between revisions of "Truxton file seek"

From truxwiki.com
Jump to navigation Jump to search
(Created page with "This allows you to alter the offset into the opened file where the next read will take place. =Syntax= <syntaxhighlight lang="C"> int64_t truxton_file_seek( uint64_t file_han...")
 
 
(5 intermediate revisions by the same user not shown)
Line 2: Line 2:
  
 
=Syntax=
 
=Syntax=
<syntaxhighlight lang="C">
+
<source lang="C">
int64_t truxton_file_seek( uint64_t file_handle, int64_t distance, int whence )
+
int64_t truxton_file_seek( uint64_t file_handle, int64_t distance, int whence );
</syntaxhighlight>
+
</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]] of [[truxton_file_open_md5]] call.
 
  
 
==<code>distance</code>==
 
==<code>distance</code>==
Line 16: Line 15:
 
==<code>whence</code>==
 
==<code>whence</code>==
 
Where to seek from.
 
Where to seek from.
# - the beginning of the file
+
* <code>SEEK_SET</code> - 0 - the beginning of the file
# - the current read offset
+
* <code>SEEK_CUR</code> - 1 - the current read offset
# - the end of the file
+
* <code>SEEK_END</code> - 2 - the end of the file
  
 
These values mimic standard C library's [https://www.ibm.com/support/knowledgecenter/en/ssw_ibm_i_72/apis/lseek.htm lseek()] whence values.
 
These values mimic standard C library's [https://www.ibm.com/support/knowledgecenter/en/ssw_ibm_i_72/apis/lseek.htm lseek()] whence values.
Line 26: Line 25:
  
 
=Sample=
 
=Sample=
 
+
<source lang="C" highlight="10">
<syntaxhighlight lang="C" highlight="10">
+
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 );
 
   }
 
   }
  
   truxton_file_seek(file, 42, 0 );
+
   truxton_file_seek( file, 42, SEEK_SET );
  
   int64_t read_position = truxton_file_tell(file);
+
   int64_t read_position = truxton_file_tell( file );
  
   truxton_file_close(file);
+
   truxton_file_close( file );
   truxton_file_free(file);
+
   truxton_file_free( file );
  
 
   if ( read_position == 42 )
 
   if ( read_position == 42 )
 
   {
 
   {
       return(1);
+
       return( 1 );
 
   }
 
   }
  
   return(0)
+
   return( 0 )
 
}
 
}
</syntaxhighlight>
+
</source>

Latest revision as of 17:34, 10 February 2021

This allows you to alter the offset into the opened file where the next read will take place.

Syntax

int64_t truxton_file_seek( uint64_t file_handle, int64_t distance, int whence );

Parameters

file_handle

The handle created by the truxton_file_open_id or truxton_file_open_md5 call.

distance

The number of bytes to move from whence

whence

Where to seek from.

  • SEEK_SET - 0 - the beginning of the file
  • SEEK_CUR - 1 - the current read offset
  • SEEK_END - 2 - the end of the file

These values mimic standard C library's lseek() whence values.

Return value

The offset into the file where the next byte will be read from.

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

   truxton_file_seek( file, 42, SEEK_SET );

   int64_t read_position = truxton_file_tell( file );

   truxton_file_close( file );
   truxton_file_free( file );

   if ( read_position == 42 )
   {
      return( 1 );
   }

   return( 0 )
}