Difference between revisions of "Truxton option get integer"

From truxwiki.com
Jump to navigation Jump to search
 
(One intermediate revision by the same user not shown)
Line 19: Line 19:
 
=Sample=
 
=Sample=
 
<source lang="C" highlight="5">
 
<source lang="C" highlight="5">
void print_starting_MFT(void)
+
void print_starting_MFT( void )
 
{
 
{
 
   uint64_t options = truxton_options_create();
 
   uint64_t options = truxton_options_create();
Line 27: Line 27:
 
   printf( "Will start processing the NTFS volume beginning at MFT %" PRId64 "\n" );
 
   printf( "Will start processing the NTFS volume beginning at MFT %" PRId64 "\n" );
  
   truxton_options_destroy(options);
+
   truxton_options_destroy( options );
 
}
 
}
 
</source>
 
</source>
 +
 +
The <code>PRId64</code> in the sample code above is a standard way of [https://en.wikipedia.org/wiki/C_data_types#Printf_and_scanf_format_specifiers formatting] a 64-bit signed integer in C.
 +
Over the years, different compilers on different operating systems used different format specifiers for things, these <code>PRI</code> macros, along with some tricky string concatenation the compilers perform for you, allow you to maintain a single code base without a bunch of macro magic.

Latest revision as of 14:08, 9 February 2021

Reads an integer setting.

Syntax

int64_t truxton_options_get_integer( uint64_t options_handle, char const * name );

Parameters

options_handle

The handle to the options object created by calling the truxton_options_create function.

name

The name of the option to read.

Return value

The value of the setting if specified. If the option name is not found, zero is returned.

Sample

void print_starting_MFT( void )
{
   uint64_t options = truxton_options_create();

   int64_t mft = truxton_options_get_integer( options, "startatmft" );

   printf( "Will start processing the NTFS volume beginning at MFT %" PRId64 "\n" );

   truxton_options_destroy( options );
}

The PRId64 in the sample code above is a standard way of formatting a 64-bit signed integer in C. Over the years, different compilers on different operating systems used different format specifiers for things, these PRI macros, along with some tricky string concatenation the compilers perform for you, allow you to maintain a single code base without a bunch of macro magic.