epanet-plus 0.2.1__cp311-cp311-macosx_11_0_arm64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- docs/conf.py +67 -0
- epanet-msx-src/dispersion.h +27 -0
- epanet-msx-src/hash.c +107 -0
- epanet-msx-src/hash.h +28 -0
- epanet-msx-src/include/epanetmsx.h +104 -0
- epanet-msx-src/include/epanetmsx_export.h +42 -0
- epanet-msx-src/mathexpr.c +937 -0
- epanet-msx-src/mathexpr.h +39 -0
- epanet-msx-src/mempool.c +204 -0
- epanet-msx-src/mempool.h +24 -0
- epanet-msx-src/msxchem.c +1285 -0
- epanet-msx-src/msxcompiler.c +368 -0
- epanet-msx-src/msxdict.h +42 -0
- epanet-msx-src/msxdispersion.c +586 -0
- epanet-msx-src/msxerr.c +116 -0
- epanet-msx-src/msxfile.c +260 -0
- epanet-msx-src/msxfuncs.c +175 -0
- epanet-msx-src/msxfuncs.h +35 -0
- epanet-msx-src/msxinp.c +1504 -0
- epanet-msx-src/msxout.c +398 -0
- epanet-msx-src/msxproj.c +791 -0
- epanet-msx-src/msxqual.c +2011 -0
- epanet-msx-src/msxrpt.c +400 -0
- epanet-msx-src/msxtank.c +422 -0
- epanet-msx-src/msxtoolkit.c +1164 -0
- epanet-msx-src/msxtypes.h +551 -0
- epanet-msx-src/msxutils.c +524 -0
- epanet-msx-src/msxutils.h +56 -0
- epanet-msx-src/newton.c +158 -0
- epanet-msx-src/newton.h +34 -0
- epanet-msx-src/rk5.c +287 -0
- epanet-msx-src/rk5.h +39 -0
- epanet-msx-src/ros2.c +293 -0
- epanet-msx-src/ros2.h +35 -0
- epanet-msx-src/smatrix.c +816 -0
- epanet-msx-src/smatrix.h +29 -0
- epanet-src/AUTHORS +60 -0
- epanet-src/LICENSE +21 -0
- epanet-src/enumstxt.h +151 -0
- epanet-src/epanet.c +5937 -0
- epanet-src/epanet2.c +961 -0
- epanet-src/epanet2.def +131 -0
- epanet-src/errors.dat +79 -0
- epanet-src/flowbalance.c +186 -0
- epanet-src/funcs.h +219 -0
- epanet-src/genmmd.c +1000 -0
- epanet-src/hash.c +177 -0
- epanet-src/hash.h +28 -0
- epanet-src/hydcoeffs.c +1303 -0
- epanet-src/hydraul.c +1164 -0
- epanet-src/hydsolver.c +781 -0
- epanet-src/hydstatus.c +442 -0
- epanet-src/include/epanet2.h +466 -0
- epanet-src/include/epanet2_2.h +1962 -0
- epanet-src/include/epanet2_enums.h +518 -0
- epanet-src/inpfile.c +884 -0
- epanet-src/input1.c +672 -0
- epanet-src/input2.c +970 -0
- epanet-src/input3.c +2265 -0
- epanet-src/leakage.c +527 -0
- epanet-src/mempool.c +146 -0
- epanet-src/mempool.h +24 -0
- epanet-src/output.c +853 -0
- epanet-src/project.c +1691 -0
- epanet-src/quality.c +695 -0
- epanet-src/qualreact.c +800 -0
- epanet-src/qualroute.c +696 -0
- epanet-src/report.c +1559 -0
- epanet-src/rules.c +1500 -0
- epanet-src/smatrix.c +871 -0
- epanet-src/text.h +508 -0
- epanet-src/types.h +928 -0
- epanet-src/util/cstr_helper.c +59 -0
- epanet-src/util/cstr_helper.h +38 -0
- epanet-src/util/errormanager.c +92 -0
- epanet-src/util/errormanager.h +39 -0
- epanet-src/util/filemanager.c +212 -0
- epanet-src/util/filemanager.h +81 -0
- epanet-src/validate.c +408 -0
- epanet.cpython-311-darwin.so +0 -0
- epanet_plus/VERSION +1 -0
- epanet_plus/__init__.py +8 -0
- epanet_plus/epanet_plus.c +118 -0
- epanet_plus/epanet_toolkit.py +2833 -0
- epanet_plus/epanet_wrapper.py +2434 -0
- epanet_plus/include/epanet_plus.h +9 -0
- epanet_plus-0.2.1.dist-info/METADATA +157 -0
- epanet_plus-0.2.1.dist-info/RECORD +106 -0
- epanet_plus-0.2.1.dist-info/WHEEL +6 -0
- epanet_plus-0.2.1.dist-info/licenses/LICENSE +21 -0
- epanet_plus-0.2.1.dist-info/top_level.txt +11 -0
- examples/basic_usage.py +35 -0
- examples/epanet_msx.py +35 -0
- python-extension/ext.c +344 -0
- python-extension/pyepanet.c +2771 -0
- python-extension/pyepanet.h +144 -0
- python-extension/pyepanet2.c +2453 -0
- python-extension/pyepanet2.h +142 -0
- python-extension/pyepanet_plus.c +43 -0
- python-extension/pyepanet_plus.h +4 -0
- python-extension/pyepanetmsx.c +524 -0
- python-extension/pyepanetmsx.h +35 -0
- tests/test_epanet.py +18 -0
- tests/test_epanetmsx.py +38 -0
- tests/test_epyt.py +115 -0
- tests/test_load_inp_from_buffer.py +59 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/*
|
|
2
|
+
******************************************************************************
|
|
3
|
+
Project: OWA EPANET
|
|
4
|
+
Version: 2.3
|
|
5
|
+
Module: util/cstr_helper.c
|
|
6
|
+
Description: Provides C string helper functions
|
|
7
|
+
Authors: see AUTHORS
|
|
8
|
+
Copyright: see AUTHORS
|
|
9
|
+
License: see LICENSE
|
|
10
|
+
Last Updated: 04/02/2019
|
|
11
|
+
******************************************************************************
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
#include <stdlib.h>
|
|
15
|
+
#include <string.h>
|
|
16
|
+
|
|
17
|
+
#include "cstr_helper.h"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
int cstr_duplicate(char **dest, const char *source)
|
|
21
|
+
// Duplicates source string
|
|
22
|
+
{
|
|
23
|
+
size_t size = 1 + strlen(source);
|
|
24
|
+
*dest = (char *) calloc(size, sizeof(char));
|
|
25
|
+
|
|
26
|
+
if (*dest == NULL)
|
|
27
|
+
return -1;
|
|
28
|
+
else {
|
|
29
|
+
#ifdef _MSC_VER
|
|
30
|
+
strncpy_s(*dest, size, source, size);
|
|
31
|
+
#else
|
|
32
|
+
strncpy(*dest, source, size);
|
|
33
|
+
#endif
|
|
34
|
+
}
|
|
35
|
+
return 0;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
bool cstr_isvalid(const char *element_id)
|
|
40
|
+
// Determines if invalid characters are present in an element id string
|
|
41
|
+
{
|
|
42
|
+
const char *invalid_chars = " \";";
|
|
43
|
+
|
|
44
|
+
// if invalid char is present a pointer to it is returned else NULL
|
|
45
|
+
if (strpbrk(element_id, invalid_chars))
|
|
46
|
+
return false;
|
|
47
|
+
else
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
bool cstr_isnullterm(const char *source)
|
|
53
|
+
// Determines if the string passed is null terminated or not
|
|
54
|
+
{
|
|
55
|
+
if (strchr(source, '\0'))
|
|
56
|
+
return true;
|
|
57
|
+
else
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/*
|
|
2
|
+
******************************************************************************
|
|
3
|
+
Project: OWA EPANET
|
|
4
|
+
Version: 2.3
|
|
5
|
+
Module: util/cstr_helper.h
|
|
6
|
+
Description: Provides C string helper functions
|
|
7
|
+
Authors: see AUTHORS
|
|
8
|
+
Copyright: see AUTHORS
|
|
9
|
+
License: see LICENSE
|
|
10
|
+
Last Updated: 04/02/2019
|
|
11
|
+
******************************************************************************
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
#ifndef CSTR_HELPER_H_
|
|
15
|
+
#define CSTR_HELPER_H_
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
#include <stdbool.h>
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
#if defined(__cplusplus)
|
|
22
|
+
extern "C" {
|
|
23
|
+
#endif
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
int cstr_duplicate(char **dest, const char *source);
|
|
27
|
+
|
|
28
|
+
bool cstr_isvalid(const char *element_id);
|
|
29
|
+
|
|
30
|
+
bool cstr_isnullterm(const char *source);
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
#if defined(__cplusplus)
|
|
34
|
+
}
|
|
35
|
+
#endif
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
#endif /* CSTR_HELPER_H_ */
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/*
|
|
2
|
+
******************************************************************************
|
|
3
|
+
Project: OWA EPANET
|
|
4
|
+
Version: 2.3
|
|
5
|
+
Module: util/errormanager.c
|
|
6
|
+
Description: Provides a simple interface for managing errors
|
|
7
|
+
Authors: see AUTHORS
|
|
8
|
+
Copyright: see AUTHORS
|
|
9
|
+
License: see LICENSE
|
|
10
|
+
Last Updated: 08/02/2023
|
|
11
|
+
******************************************************************************
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
//#ifdef _WIN32
|
|
15
|
+
//#define _CRTDBG_MAP_ALLOC
|
|
16
|
+
//#include <stdlib.h>
|
|
17
|
+
//#include <crtdbg.h>
|
|
18
|
+
//#else
|
|
19
|
+
#include <stdlib.h>
|
|
20
|
+
//#endif
|
|
21
|
+
#include <string.h>
|
|
22
|
+
|
|
23
|
+
#include "errormanager.h"
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
typedef struct error_s {
|
|
27
|
+
int error_status;
|
|
28
|
+
void (*p_msg_lookup)(int, char*, int);
|
|
29
|
+
} error_handle_t;
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
error_handle_t *create_error_manager(void (*p_error_message)(int, char*, int))
|
|
33
|
+
//
|
|
34
|
+
// Purpose: Constructs a new error handle.
|
|
35
|
+
//
|
|
36
|
+
{
|
|
37
|
+
error_handle_t *error_handle;
|
|
38
|
+
error_handle = (error_handle_t*)calloc(1, sizeof(error_handle_t));
|
|
39
|
+
if (error_handle == NULL) return NULL;
|
|
40
|
+
|
|
41
|
+
error_handle->p_msg_lookup = p_error_message;
|
|
42
|
+
|
|
43
|
+
return error_handle;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
void delete_error_manager(error_handle_t *error_handle)
|
|
47
|
+
//
|
|
48
|
+
// Purpose: Destroys the error handle.
|
|
49
|
+
//
|
|
50
|
+
{
|
|
51
|
+
free(error_handle);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
int set_error(error_handle_t *error_handle, int error_code)
|
|
55
|
+
//
|
|
56
|
+
// Purpose: Sets an error code in the handle.
|
|
57
|
+
//
|
|
58
|
+
{
|
|
59
|
+
// If the error code is 0 no action is taken and 0 is returned.
|
|
60
|
+
// This is a feature not a bug.
|
|
61
|
+
if (error_code)
|
|
62
|
+
error_handle->error_status = error_code;
|
|
63
|
+
|
|
64
|
+
return error_code;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
int check_error(error_handle_t *error_handle, char **error_message)
|
|
68
|
+
//
|
|
69
|
+
// Purpose: Returns the error message or NULL.
|
|
70
|
+
//
|
|
71
|
+
// Note: Caller must free memory allocated by check_error
|
|
72
|
+
//
|
|
73
|
+
{ int error_code = error_handle->error_status;
|
|
74
|
+
char *temp = NULL;
|
|
75
|
+
|
|
76
|
+
if (error_code != 0) {
|
|
77
|
+
temp = (char*) calloc(ERR_MAXMSG + 1, sizeof(char));
|
|
78
|
+
|
|
79
|
+
if (temp)
|
|
80
|
+
error_handle->p_msg_lookup(error_code, temp, ERR_MAXMSG);
|
|
81
|
+
}
|
|
82
|
+
*error_message = temp;
|
|
83
|
+
return error_code;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
void clear_error(error_handle_t *error_handle)
|
|
87
|
+
//
|
|
88
|
+
// Purpose: Clears the error from the handle.
|
|
89
|
+
//
|
|
90
|
+
{
|
|
91
|
+
error_handle->error_status = 0;
|
|
92
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/*
|
|
2
|
+
******************************************************************************
|
|
3
|
+
Project: OWA EPANET
|
|
4
|
+
Version: 2.3
|
|
5
|
+
Module: util/errormanager.h
|
|
6
|
+
Description: Provides a simple interface for managing errors
|
|
7
|
+
Authors: see AUTHORS
|
|
8
|
+
Copyright: see AUTHORS
|
|
9
|
+
License: see LICENSE
|
|
10
|
+
Last Updated: 04/02/2019
|
|
11
|
+
******************************************************************************
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
#ifndef ERRORMANAGER_H_
|
|
15
|
+
#define ERRORMANAGER_H_
|
|
16
|
+
|
|
17
|
+
#define ERR_MAXMSG 256
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
#if defined(__cplusplus)
|
|
21
|
+
extern "C" {
|
|
22
|
+
#endif
|
|
23
|
+
|
|
24
|
+
// Forward declaration
|
|
25
|
+
typedef struct error_s error_handle_t;
|
|
26
|
+
|
|
27
|
+
error_handle_t* create_error_manager(void (*p_error_message)(int, char*, int));
|
|
28
|
+
void delete_error_manager(error_handle_t* error_handle);
|
|
29
|
+
|
|
30
|
+
int set_error(error_handle_t* error_handle, int error_code);
|
|
31
|
+
int check_error(error_handle_t* error_handle, char **error_message);
|
|
32
|
+
void clear_error(error_handle_t* error_handle);
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
#if defined(__cplusplus)
|
|
36
|
+
}
|
|
37
|
+
#endif
|
|
38
|
+
|
|
39
|
+
#endif /* ERRORMANAGER_H_ */
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/*
|
|
2
|
+
******************************************************************************
|
|
3
|
+
Project: OWA EPANET
|
|
4
|
+
Version: 2.3
|
|
5
|
+
Module: util/filemanager.c
|
|
6
|
+
Description: Provides a simple interface for managing files
|
|
7
|
+
Authors: see AUTHORS
|
|
8
|
+
Copyright: see AUTHORS
|
|
9
|
+
License: see LICENSE
|
|
10
|
+
Last Updated: 08/02/2023
|
|
11
|
+
******************************************************************************
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
// MSVC ONLY
|
|
16
|
+
#ifdef _DEBUG
|
|
17
|
+
#define _CRTDBG_MAP_ALLOC
|
|
18
|
+
#include <stdlib.h>
|
|
19
|
+
#include <crtdbg.h>
|
|
20
|
+
#else
|
|
21
|
+
#include <stdlib.h>
|
|
22
|
+
#endif
|
|
23
|
+
|
|
24
|
+
#include <stdarg.h>
|
|
25
|
+
|
|
26
|
+
#include "filemanager.h"
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
typedef struct file_s {
|
|
30
|
+
char *filename; // Assumes this is a null terminated string
|
|
31
|
+
FILE *file;
|
|
32
|
+
} file_handle_t;
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
// local (private) functions
|
|
36
|
+
int _fopen(FILE **f, const char *name, const char *mode);
|
|
37
|
+
int _get_temp_filename(char **tempname);
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
file_handle_t *create_file_manager() {
|
|
41
|
+
|
|
42
|
+
file_handle_t *file_handle;
|
|
43
|
+
file_handle = (file_handle_t *)calloc(1, sizeof(file_handle_t));
|
|
44
|
+
if (file_handle == NULL) return NULL;
|
|
45
|
+
|
|
46
|
+
file_handle->filename = NULL;
|
|
47
|
+
file_handle->file = NULL;
|
|
48
|
+
|
|
49
|
+
return file_handle;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
void delete_file_manager(file_handle_t *file_handle) {
|
|
53
|
+
|
|
54
|
+
if (file_handle->file != NULL)
|
|
55
|
+
close_file(file_handle);
|
|
56
|
+
|
|
57
|
+
free(file_handle->filename);
|
|
58
|
+
free(file_handle);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
int get_filename(file_handle_t *file_handle, char **filename)
|
|
63
|
+
//
|
|
64
|
+
// BE AWARE: The memory allocated here must be freed by the caller
|
|
65
|
+
//
|
|
66
|
+
{
|
|
67
|
+
return cstr_duplicate(filename, file_handle->filename);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
int open_file(file_handle_t *file_handle, const char *filename, const char *file_mode) {
|
|
72
|
+
int error = 0;
|
|
73
|
+
|
|
74
|
+
if (filename == NULL)
|
|
75
|
+
_get_temp_filename(&(file_handle->filename));
|
|
76
|
+
else
|
|
77
|
+
cstr_duplicate(&(file_handle->filename), filename);
|
|
78
|
+
|
|
79
|
+
if (file_mode == NULL)
|
|
80
|
+
error = -1;
|
|
81
|
+
else {
|
|
82
|
+
error = _fopen(&(file_handle->file), file_handle->filename, file_mode);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return error;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
int seek_file(file_handle_t *file_handle, F_OFF offset, int whence)
|
|
89
|
+
{
|
|
90
|
+
#ifdef _MSC_VER // Windows (32-bit and 64-bit)
|
|
91
|
+
#define FSEEK64 _fseeki64
|
|
92
|
+
#else // Other platforms
|
|
93
|
+
#define FSEEK64 fseeko
|
|
94
|
+
#endif
|
|
95
|
+
|
|
96
|
+
return FSEEK64(file_handle->file, offset, whence);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
F_OFF tell_file(file_handle_t *file_handle)
|
|
100
|
+
{
|
|
101
|
+
#ifdef _MSC_VER // Windows (32-bit and 64-bit)
|
|
102
|
+
#define FTELL64 _ftelli64
|
|
103
|
+
#else // Other platforms
|
|
104
|
+
#define FTELL64 ftello
|
|
105
|
+
#endif
|
|
106
|
+
|
|
107
|
+
return FTELL64(file_handle->file);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Read and write to a binary file
|
|
111
|
+
size_t read_file(void *ptr, size_t size, size_t nmemb, file_handle_t *file_handle)
|
|
112
|
+
{
|
|
113
|
+
return fread(ptr, size, nmemb, file_handle->file);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
size_t write_file(const void * ptr, size_t size, size_t count, file_handle_t *file_handle)
|
|
117
|
+
{
|
|
118
|
+
return fwrite(ptr, size, count, file_handle->file);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
// print and get from a text file
|
|
123
|
+
int printf_file(file_handle_t *file_handle, const char *format, ... )
|
|
124
|
+
{
|
|
125
|
+
int error = 0;
|
|
126
|
+
va_list args;
|
|
127
|
+
|
|
128
|
+
va_start(args, format);
|
|
129
|
+
error = vfprintf(file_handle->file, format, args);
|
|
130
|
+
va_end(args);
|
|
131
|
+
|
|
132
|
+
return error;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
int gets_file(char *str, int num, file_handle_t *file_handle)
|
|
136
|
+
{
|
|
137
|
+
fgets(str, num, file_handle->file);
|
|
138
|
+
return 0;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
int close_file(file_handle_t *file_handle) {
|
|
143
|
+
int error = 0;
|
|
144
|
+
|
|
145
|
+
if (file_handle->file != NULL) {
|
|
146
|
+
error = fclose(file_handle->file);
|
|
147
|
+
file_handle->file = NULL;
|
|
148
|
+
}
|
|
149
|
+
return error;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
int remove_file(file_handle_t *file_handle) {
|
|
153
|
+
return remove(file_handle->filename);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
bool is_valid(file_handle_t *file_handle)
|
|
158
|
+
{
|
|
159
|
+
if ((file_handle->filename == NULL && file_handle->file == NULL) ||
|
|
160
|
+
(cstr_isnullterm(file_handle->filename) && file_handle != NULL))
|
|
161
|
+
return true;
|
|
162
|
+
else
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
int _fopen(FILE **f, const char *name, const char *mode)
|
|
168
|
+
//
|
|
169
|
+
// Purpose: Substitute for fopen_s on platforms where it doesn't exist
|
|
170
|
+
// Note: fopen_s is part of C++11 standard
|
|
171
|
+
//
|
|
172
|
+
{
|
|
173
|
+
int ret = 0;
|
|
174
|
+
|
|
175
|
+
#ifdef _MSC_VER
|
|
176
|
+
ret = (int)fopen_s(f, name, mode);
|
|
177
|
+
#else
|
|
178
|
+
*f = fopen(name, mode);
|
|
179
|
+
if (!*f)
|
|
180
|
+
ret = -1;
|
|
181
|
+
#endif
|
|
182
|
+
return ret;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
int _get_temp_filename(char **tempname)
|
|
186
|
+
{
|
|
187
|
+
int error = 0;
|
|
188
|
+
|
|
189
|
+
#ifdef _MSC_VER
|
|
190
|
+
char *name = NULL;
|
|
191
|
+
|
|
192
|
+
// --- use Windows _tempnam function to get a pointer to an
|
|
193
|
+
// unused file name that begins with "en"
|
|
194
|
+
if ((name = _tempnam(name, "en")) == NULL) {
|
|
195
|
+
error = -1;
|
|
196
|
+
return error;
|
|
197
|
+
}
|
|
198
|
+
else
|
|
199
|
+
cstr_duplicate(tempname, name);
|
|
200
|
+
|
|
201
|
+
// --- free the pointer returned by _tempnam
|
|
202
|
+
if (name)
|
|
203
|
+
free(name);
|
|
204
|
+
|
|
205
|
+
// --- for non-Windows systems:
|
|
206
|
+
#else
|
|
207
|
+
// --- use system function mkstemp() to create a temporary file name
|
|
208
|
+
cstr_duplicate(tempname, "enXXXXXX");
|
|
209
|
+
error = mkstemp(*tempname);
|
|
210
|
+
#endif
|
|
211
|
+
return error;
|
|
212
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/*
|
|
2
|
+
******************************************************************************
|
|
3
|
+
Project: OWA EPANET
|
|
4
|
+
Version: 2.3
|
|
5
|
+
Module: util/filemanager.h
|
|
6
|
+
Description: Provides a simple interface for managing files
|
|
7
|
+
Authors: see AUTHORS
|
|
8
|
+
Copyright: see AUTHORS
|
|
9
|
+
License: see LICENSE
|
|
10
|
+
Last Updated: 04/01/2019
|
|
11
|
+
******************************************************************************
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
#ifndef FILEMANAGER_H_
|
|
15
|
+
#define FILEMANAGER_H_
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
#include <stdio.h>
|
|
19
|
+
#include <stdarg.h>
|
|
20
|
+
|
|
21
|
+
#include "cstr_helper.h"
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
// F_OFF Must be a 8 byte / 64 bit integer for large file support
|
|
25
|
+
#ifdef _MSC_VER // Windows (32-bit and 64-bit)
|
|
26
|
+
#define F_OFF __int64
|
|
27
|
+
#else // Other platforms
|
|
28
|
+
#define F_OFF off_t
|
|
29
|
+
#endif
|
|
30
|
+
|
|
31
|
+
#define FILE_MAXNAME 259
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
#if defined(__cplusplus)
|
|
35
|
+
extern "C" {
|
|
36
|
+
#endif
|
|
37
|
+
|
|
38
|
+
// Forward declariation of file_handle_t
|
|
39
|
+
typedef struct file_s file_handle_t;
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
file_handle_t *create_file_manager();
|
|
43
|
+
|
|
44
|
+
void delete_file_manager(file_handle_t *file_handle);
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
int get_filename(file_handle_t *file_handle, char **filename);
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
int open_file(file_handle_t *file_handle, const char *filename, const char *file_mode);
|
|
51
|
+
|
|
52
|
+
int seek_file(file_handle_t *file_handle, F_OFF offset, int whence);
|
|
53
|
+
|
|
54
|
+
F_OFF tell_file(file_handle_t *file_handle);
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
// Functions for working with binary files
|
|
58
|
+
size_t read_file(void *ptr, size_t size, size_t nmemb, file_handle_t *file_handle);
|
|
59
|
+
|
|
60
|
+
size_t write_file(const void *ptr, size_t size, size_t count, file_handle_t *file_handle);
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
// Functions for working with text files
|
|
64
|
+
int printf_file(file_handle_t *file_handle, const char *format, ... );
|
|
65
|
+
|
|
66
|
+
int gets_file(char *str, int num, file_handle_t *file_handle);
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
int close_file(file_handle_t *file_handle);
|
|
70
|
+
|
|
71
|
+
int remove_file(file_handle_t *file_handle);
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
bool is_valid(file_handle_t *file_handle);
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
#if defined(__cplusplus)
|
|
78
|
+
}
|
|
79
|
+
#endif
|
|
80
|
+
|
|
81
|
+
#endif /* FILEMANAGER_H_ */
|