LCOV - code coverage report
Current view: top level - util - fd_version.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 27 33 81.8 %
Date: 2026-09-17 04:28:31 Functions: 4 4 100.0 %

          Line data    Source code
       1             : #include "fd_version.h"
       2             : #include "cstr/fd_cstr.h"
       3             : #include "fd_version_generated.h"
       4             : 
       5             : /* Firedancer version */
       6             : __attribute__((weak)) ulong const fd_major_version = FD_VERSION_MAJOR;
       7             : __attribute__((weak)) ulong const fd_minor_version = FD_VERSION_MINOR;
       8             : __attribute__((weak)) ulong const fd_patch_version = FD_VERSION_PATCH;
       9             : char const * fd_version_cstr = ""; /* set on boot */
      10             : 
      11             : /* Commit information */
      12             : __attribute__((weak)) char const fd_commit_ref_private[] = FIREDANCER_COMMIT_REF_CSTR;
      13             : char const * fd_commit_ref_cstr = ""; /* cstr */
      14             : uint         fd_commit_ref_u32  = 0;  /* set on boot */
      15             : 
      16             : static inline int
      17       21176 : unhex( int c ) {
      18       21176 :   if( c>='0' && c<='9' ) return c-'0';
      19       10588 :   if( c>='a' && c<='f' ) return c-'a'+0xa;
      20           0 :   if( c>='A' && c<='F' ) return c-'A'+0xa;
      21           0 :   return -1;
      22           0 : }
      23             : 
      24             : char *
      25             : fd_version_cstr_format( char * buf,
      26             :                         ulong  bufsz,
      27             :                         ulong  major,
      28             :                         ulong  minor,
      29        2656 :                         ulong  patch ) {
      30        2656 :   fd_cstr_printf( buf, bufsz, NULL, major>=26UL ? "%lu.%02lu.%lu" : "%lu.%lu.%lu", major, minor, patch );
      31        2656 :   return buf;
      32        2656 : }
      33             : 
      34             : void
      35        2647 : fd_version_private_commit_ref_init( void ) {
      36        2647 :   char const * str = fd_commit_ref_private;
      37        2647 :   fd_commit_ref_cstr = str;
      38        2647 :   uint ref = 0;
      39        2647 :   char tmp[9] = {0}; fd_cstr_ncpy( tmp, str, 9 );
      40       13235 :   for( ulong i=0UL; i<8UL; i+=2 ) {
      41       10588 :     int hi = unhex( tmp[ i   ] );
      42       10588 :     int lo = unhex( tmp[ i+1 ] );
      43       10588 :     if( FD_UNLIKELY( hi<0 || lo<0 ) ) {
      44           0 :       ref = 0;
      45           0 :       break;
      46           0 :     }
      47       10588 :     ref <<= 8;
      48       10588 :     ref |= (uint)( (hi<<4) | lo );
      49       10588 :   }
      50        2647 :   fd_commit_ref_u32 = ref;
      51        2647 : }
      52             : 
      53             : __attribute__((weak)) void
      54             : fd_version_private_boot( int *    pargc,
      55        2647 :                          char *** pargv ) {
      56        2647 :   (void)pargc; (void)pargv;
      57        2647 :   static char ver_cstr[ 512 ];
      58        2647 :   fd_version_cstr = fd_version_cstr_format( ver_cstr, sizeof(ver_cstr), fd_major_version, fd_minor_version, fd_patch_version );
      59        2647 :   fd_version_private_commit_ref_init();
      60        2647 : }

Generated by: LCOV version 1.14