8
8
9
9
10
10
const char * ENV_VAR_DEBUG_OUTPUT = "ENOPT_ENABLE_DEBUG_OUTPUT" ;
11
- const char * ENV_VAR_INIT_COUNTER = "ENOPT_INIT_COUNT" ;
12
11
13
12
14
13
void debug_printf (const char * format , ...) {
@@ -20,46 +19,3 @@ void debug_printf(const char* format, ...) {
20
19
vfprintf (stderr , format , ap );
21
20
va_end (ap );
22
21
}
23
-
24
-
25
- int read_count () {
26
- const char * countStr = getenv (ENV_VAR_INIT_COUNTER );
27
- return countStr ? strtol (countStr , NULL , 10 ) : 0 ;
28
- }
29
-
30
-
31
- void write_count (int count ) {
32
- char str [16 ];
33
- sprintf (str , "%d" , count );
34
- setenv (ENV_VAR_INIT_COUNTER , str , 1 );
35
- }
36
-
37
-
38
- int init_enopt_wrapper () {
39
- int count = read_count ();
40
- int result = (count == 0 ) ? enopt_init () : 0 ;
41
- write_count (++ count );
42
- debug_printf ("NOTE: After increasing, the new init count is: %i\n" , count );
43
-
44
- return result ;
45
- }
46
-
47
-
48
- int finalize_enopt_wrapper () {
49
- int count = read_count ();
50
- if ( count <= 0 ) {
51
- printf ("ERROR: Finalize called more often than initialize!\n" );
52
- abort ();
53
- }
54
-
55
- int result = 0 ;
56
- if ( count == 1 ) {
57
- debug_printf ("NOTE: Init count is going to 0, finalizing Enopt...\n" );
58
- result = enopt_finalize ();
59
- }
60
-
61
- write_count (-- count );
62
- debug_printf ("NOTE: After decreasing, the new init count is: %i\n" , count );
63
-
64
- return result ;
65
- }
0 commit comments