LCOV - code coverage report
Current view: top level - libs/testitall/src - construct_path.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 78.3 % 23 18
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 Constructs full file path by combining TMPDIR environment variable with filename
       5              :  *
       6              :  * @param[in]  filename  Name of the file to append to TMPDIR path
       7              :  * @param[out] full_path Managed memory buffer that will be resized to hold the constructed path
       8              :  * @return Return Status of the operation
       9              :  */
      10            7 : Return construct_path(
      11              :         const char *filename,
      12              :         memory     *full_path)
      13              : {
      14            7 :         Return status = SUCCESS;
      15            7 :         const char *tmp_dir = NULL;
      16            7 :         size_t path_len = 0;
      17              : 
      18            7 :         if(SUCCESS == status)
      19              :         {
      20            7 :                 if((filename == NULL) || (full_path == NULL))
      21              :                 {
      22            0 :                         status = FAILURE;
      23              :                 }
      24              :         }
      25              : 
      26            7 :         if(SUCCESS == status)
      27              :         {
      28            7 :                 tmp_dir = getenv("TMPDIR");
      29              : 
      30            7 :                 if(NULL == tmp_dir)
      31              :                 {
      32            0 :                         status = FAILURE;
      33              :                 }
      34              :         }
      35              : 
      36            7 :         if(SUCCESS == status)
      37              :         {
      38            7 :                 path_len = strlen(tmp_dir) + strlen(filename) + 2;   // +2 for '/' and '\0'
      39            7 :                 status = resize(full_path,path_len);
      40              :         }
      41              : 
      42            7 :         if(SUCCESS == status)
      43              :         {
      44            7 :                 char *path_data = getstring(full_path);
      45              : 
      46            7 :                 if(path_data == NULL)
      47              :                 {
      48            0 :                         status = FAILURE;
      49              :                 } else {
      50            7 :                         int print_result = snprintf(path_data,path_len,"%s/%s",tmp_dir,filename);
      51              : 
      52            7 :                         if(print_result < 0 || (size_t)print_result >= path_len)
      53              :                         {
      54            0 :                                 status = FAILURE;
      55            0 :                                 path_data[0] = '\0';
      56              :                         }
      57              :                 }
      58              :         }
      59              : 
      60            7 :         return(status);
      61              : }
        

Generated by: LCOV version 2.0-1