Linux GNU 11.4.0 Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 0.0% 0 / 0 / 22
Functions: 0.0% 0 / 0 / 3
Branches: 0.0% 0 / 0 / 2

OMCompiler/SimulationRuntime/c/util/write_csv.c
Line Branch Exec Source
1 /*
2 * This file belongs to the OpenModelica Run-Time System
3 *
4 * Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC), c/o Linköpings
5 * universitet, Department of Computer and Information Science, SE-58183 Linköping, Sweden. All rights
6 * reserved.
7 *
8 * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF THE BSD NEW LICENSE OR THE
9 * AGPL VERSION 3 LICENSE OR THE OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.8. ANY
10 * USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES RECIPIENT'S
11 * ACCEPTANCE OF THE BSD NEW LICENSE OR THE OSMC PUBLIC LICENSE OR THE AGPL
12 * VERSION 3, ACCORDING TO RECIPIENTS CHOICE.
13 *
14 * The OpenModelica software and the OSMC (Open Source Modelica Consortium) Public License
15 * (OSMC-PL) are obtained from OSMC, either from the above address, from the URLs:
16 * http://www.openmodelica.org or https://github.com/OpenModelica/ or
17 * http://www.ida.liu.se/projects/OpenModelica, and in the OpenModelica distribution. GNU
18 * AGPL version 3 is obtained from: https://www.gnu.org/licenses/licenses.html#GPL. The BSD NEW
19 * License is obtained from: http://www.opensource.org/licenses/BSD-3-Clause.
20 *
21 * This program is distributed WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY
23 * SET FORTH IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF
24 * OSMC-PL.
25 *
26 */
27
28 #include <stdio.h>
29 #include <string.h>
30
31 #include "libcsv.h"
32 #include "omc_file.h"
33 #include "write_csv.h"
34
35 #define CSV_BUFFER_SIZE 1024
36
37 ✗ OMC_WRITE_CSV* omc_write_csv_init(char filename[], char seperator, char quote){
38 int i;
39 ✗ size_t n = strlen(filename);
40
41 ✗ OMC_WRITE_CSV* csvData = (OMC_WRITE_CSV*) malloc(sizeof(OMC_WRITE_CSV));
42 ✗ csvData->filename = (char*) malloc((n+1)*sizeof(char));
43
44 strncpy(csvData->filename, filename, n);
45 ✗ csvData->filename[n] = '\0';
46 ✗ csvData->seperator = seperator;
47 ✗ csvData->quote = '"';
48
49 ✗ csvData->handle = omc_fopen(csvData->filename,"w");
50
51 ✗ return csvData;
52 }
53
54
55 ✗ int omc_write_csv_free(OMC_WRITE_CSV* csvData){
56
57 int i;
58
59 ✗ free(csvData->filename);
60 ✗ fclose(csvData->handle);
61
62 ✗ return 0;
63 }
64
65 ✗ int omc_write_csv(OMC_WRITE_CSV* csvData, const void* csvLine){
66
67 size_t dest_size;
68 ✗ unsigned char buffer[CSV_BUFFER_SIZE] = "";
69
70 ✗ dest_size = csv_write(&buffer, CSV_BUFFER_SIZE, csvLine, strlen(csvLine));
71 ✗ if (dest_size > CSV_BUFFER_SIZE){
72 ✗ unsigned char* newbuffer = (unsigned char*) malloc(dest_size*sizeof(unsigned char));
73 ✗ dest_size = csv_write(&newbuffer, dest_size, csvLine, strlen(csvLine));
74 ✗ fprintf(csvData->handle, "%s", newbuffer);
75 }else{
76 ✗ fprintf(csvData->handle, "%s", buffer);
77 }
78
79 ✗ return 0;
80 }
81