LCOV - code coverage report
Current view: top level - src - print.c (source / functions) Coverage Total Hit
Test: report.info Lines: 100.0 % 30 30
Test Date: 2025-02-11 09:58:02 Functions: 100.0 % 6 6

            Line data    Source code
       1              : #include "print.h"
       2              : 
       3              : bool is_verbose_mode = false;
       4              : 
       5          530 : void _print_generic(int fd, const char *format, va_list args)
       6              : {
       7              :     char buffer[BUFFER_SIZE];
       8          530 :     vsnprintf(buffer, sizeof(buffer), format, args);
       9          530 :     write(fd, buffer, strlen(buffer));
      10          530 : }
      11              : 
      12          501 : void print_generic(int fd, const char *format, ...)
      13              : {
      14              :     va_list args;
      15              : 
      16          501 :     va_start(args, format);
      17              : 
      18          501 :     _print_generic(fd, format, args);
      19              : 
      20          501 :     va_end(args);
      21          501 : }
      22              : 
      23           59 : void print(const char *format, ...)
      24              : {
      25           59 :     if (!get_verbose_mode())
      26              :     {
      27           53 :         return;
      28              :     }
      29              : 
      30              :     va_list args;
      31              : 
      32            6 :     va_start(args, format);
      33              : 
      34            6 :     _print_generic(STDOUT_FILENO, format, args);
      35              : 
      36            6 :     va_end(args);
      37              : }
      38              : 
      39           23 : void print_error(const char *format, ...)
      40              : {
      41              :     va_list args;
      42              : 
      43           23 :     va_start(args, format);
      44              : 
      45              :     // Red color
      46           23 :     print_generic(STDERR_FILENO, RED_COLOR);
      47              : 
      48           23 :     _print_generic(STDERR_FILENO, format, args);
      49           23 :     if (strlen(format) > 0)
      50              :     {
      51           23 :         print_generic(STDERR_FILENO, ": ");
      52              :     }
      53           23 :     print_generic(STDERR_FILENO, "%s\n", strerror(errno));
      54              : 
      55              :     // Reset color
      56           23 :     print_generic(STDERR_FILENO, RESET_COLOR);
      57              : 
      58           23 :     va_end(args);
      59           23 : }
      60              : 
      61            7 : void set_verbose_mode(bool mode)
      62              : {
      63            7 :     is_verbose_mode = mode;
      64            7 : }
      65              : 
      66           63 : bool get_verbose_mode()
      67              : {
      68           63 :     return is_verbose_mode;
      69              : }
        

Generated by: LCOV version 2.0-1