LCOV - code coverage report
Current view: top level - libs/testitall/src - set_environment_variable.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 63.6 % 11 7
Test Date: 2026-01-12 05:34:38 Functions: 100.0 % 1 1

            Line data    Source code
       1              : #include "testitall.h"
       2              : 
       3              : /**
       4              :  * @brief Sets an environment variable with error handling
       5              :  *
       6              :  * @param variable Name of the environment variable to set
       7              :  * @param value Value to assign to the environment variable
       8              :  *
       9              :  * @return Return Status code indicating operation result:
      10              :  *         - SUCCESS: Variable was set successfully
      11              :  *         - FAILURE: Failed to set variable (null parameters or setenv error)
      12              :  *
      13              :  * @details This function safely sets an environment variable with proper error checking
      14              :  *          and reporting. It validates input parameters and uses setenv() with
      15              :  *          overwrite enabled.
      16              :  */
      17          129 : Return set_environment_variable(
      18              :         const char *variable,
      19              :         const char *value)
      20              : {
      21              :         /// The status that will be passed to return() before exiting.
      22              :         /// By default, the function worked without errors.
      23          129 :         Return status = SUCCESS;
      24              : 
      25              :         /* Validate input parameters */
      26          129 :         if(!variable || !value)
      27              :         {
      28            0 :                 status = FAILURE;
      29              :         }
      30              : 
      31          129 :         if(SUCCESS == status)
      32              :         {
      33              :                 /* Attempt to set environment variable
      34              :                  * Third parameter (1) allows overwriting existing values */
      35          129 :                 if(setenv(variable,value,1) != 0)
      36              :                 {
      37              :                         /* Log error if setenv fails */
      38            0 :                         echo(STDERR,"Failed to set environment variable %s",variable);
      39            0 :                         status = FAILURE;
      40              :                 }
      41              :         }
      42              : 
      43              :         /* Output error message on failure */
      44          129 :         if(SUCCESS != status)
      45              :         {
      46            0 :                 echo(STDERR,"ERROR: Failed to set environment variable\n");
      47              :         }
      48              : 
      49          129 :         return(status);
      50              : }
        

Generated by: LCOV version 2.0-1