LCOV - code coverage report
Current view: top level - tests - utils.c (source / functions) Hit Total Coverage
Test: deployctl-0.3.15.2.96a2d Code Coverage Lines: 2 2 100.0 %
Date: 2018-06-22 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  utils.c
       3             :  Created by Danny Goossen, Gioxa Ltd on 2/5/17.
       4             : 
       5             :  MIT License
       6             : 
       7             :  Copyright (c) 2017 deployctl, Gioxa Ltd.
       8             : 
       9             :  Permission is hereby granted, free of charge, to any person obtaining a copy
      10             :  of this software and associated documentation files (the "Software"), to deal
      11             :  in the Software without restriction, including without limitation the rights
      12             :  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
      13             :  copies of the Software, and to permit persons to whom the Software is
      14             :  furnished to do so, subject to the following conditions:
      15             : 
      16             :  The above copyright notice and this permission notice shall be included in all
      17             :  copies or substantial portions of the Software.
      18             : 
      19             :  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      20             :  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      21             :  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
      22             :  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      23             :  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      24             :  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
      25             :  SOFTWARE.
      26             : 
      27             :  */
      28             : 
      29             : 
      30             : #include "utils.h"
      31             : #include "../src/deployd.h"
      32             : 
      33          26 : int write_test_file(const char * base,const char * sub,const char * file, const char * data)
      34             : {
      35             :   //LCOV_EXCL_START
      36             :    char filename[1024];
      37             :    sprintf((char *)filename,"%s%s/%s",base,sub,file);
      38             :     debug("write test file %s\n",filename);
      39             :    FILE *f = fopen(filename, "w");
      40             :    if (f == NULL){ debug("Error opening file : %s\n",strerror(errno));return -1;}
      41             :    /* print some text */
      42             :    int retvalue=0;
      43             :    int errvalue=0;
      44             :    do{ retvalue=fprintf(f, "%s",data);} while ( retvalue==-1 && (errvalue=errno)== EINTR );
      45             :    if (retvalue<0) { debug("Error io-command %s: %s\n", filename,strerror(errvalue)); return -1; }
      46             :    if (fclose(f) <0 ) { debug("Error io-command %s: %s\n", filename,strerror(errno));return -1;}
      47             :    return retvalue;
      48             :    //LCOV_EXCL_STOP
      49             : }
      50             : 
      51           3 : int write_test_file_n(const char * base,const char * sub,const char * file, const char * data, size_t n)
      52             : {
      53             :         //LCOV_EXCL_START
      54             :         char filename[1024];
      55             :         sprintf((char *)filename,"%s%s/%s",base,sub,file);
      56             :         debug("write test file %s\n",filename);
      57             :         FILE *f = fopen(filename, "wb");
      58             :         if (f == NULL){ debug("Error opening file : %s\n",strerror(errno));return -1;}
      59             :         /* print some text */
      60             :         size_t retvalue=0;
      61             :         int errvalue=0;
      62             :         retvalue=fwrite(data,1,n,f);//;} while ( retvalue==0 && (errvalue=ferror(<#FILE *#>))== EINTR );
      63             : 
      64             :         if (retvalue!=n) { debug("Error io-command %s: %s\n", filename,strerror(errvalue)); return -1; }
      65             :         if (fclose(f) <0 ) { debug("Error io-command %s: %s\n", filename,strerror(errno));return -1;}
      66             :         return (int)retvalue;
      67             :         //LCOV_EXCL_STOP
      68             : }

Generated by: LCOV version 1.10