LCOV - code coverage report
Current view: top level - src/bindings/intercept/env/examples - getenv.c (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 0 18 0.0 %
Date: 2022-05-21 16:19:22 Functions: 0 1 0.0 %

          Line data    Source code
       1             : /**
       2             :  * @file
       3             :  *
       4             :  * @brief
       5             :  *
       6             :  * @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
       7             :  */
       8             : 
       9             : #include <stdio.h>
      10             : #include <stdlib.h>
      11             : #include <string.h>
      12             : 
      13           0 : int main (int argc, char ** argv, char ** environ)
      14             : {
      15           0 :         if (argc == 1)
      16             :         {
      17             :                 char ** env;
      18           0 :                 for (env = environ; *env != 0; env++)
      19           0 :                 {
      20           0 :                         const size_t len = strcspn (*env, "=");
      21           0 :                         char name[len + 1];
      22           0 :                         strncpy (name, *env, len);
      23           0 :                         name[len] = 0;
      24           0 :                         const char * c = getenv (name);
      25           0 :                         printf ("getenv(\"%s\") -> ", name);
      26           0 :                         if (!c)
      27             :                         {
      28           0 :                                 printf ("<null>\n");
      29             :                         }
      30             :                         else
      31             :                         {
      32           0 :                                 printf ("%s\n", c);
      33             :                         }
      34             :                 }
      35             :         }
      36             :         else
      37             :         {
      38           0 :                 for (int i = 1; i < argc; ++i)
      39             :                 {
      40           0 :                         const char * name = argv[i];
      41           0 :                         const char * c = getenv (name);
      42           0 :                         if (!c) return 1;
      43           0 :                         printf ("%s\n", c);
      44             :                 }
      45             :         }
      46             :         return 0;
      47             : }

Generated by: LCOV version 1.13