Pharos
0.7.23
Modern Web Framework & Web App Hosting Service.
Toggle main menu visibility
Loading...
Searching...
No Matches
native_app_runtime_clone.c
Go to the documentation of this file.
1
/**
2
* @file
3
* @brief Deep-copies AppRuntime structures so loaded runtime state can be duplicated safely.
4
*/
5
6
#include "
native_app_runtime_clone.h
"
7
8
#include <stdlib.h>
9
#include <string.h>
10
11
#ifdef _WIN32
12
#define native_clone_strdup _strdup
13
#else
14
#define native_clone_strdup strdup
15
#endif
16
17
static
void
clear_cloned_app_runtime
(
AppRuntime
*app) {
18
if
(app == NULL) {
19
return
;
20
}
21
free(app->
app_id
);
22
free(app->
app_root
);
23
free(app->
build_dir
);
24
free(app->
artifact_dir
);
25
free(app->
host_profile
);
26
free(app->
compiled_entrypoint
);
27
free(app->
state_path
);
28
free(app->
base_path
);
29
free(app->
log_path
);
30
free(app->
log_format
);
31
free(app->
error_report_path
);
32
free(app->
debug
);
33
free(app->
runtime_conf_path
);
34
memset(app, 0,
sizeof
(*app));
35
}
36
37
static
char
*
clone_optional_string
(
const
char
*value) {
38
if
(value == NULL) {
39
return
NULL;
40
}
41
return
native_clone_strdup
(value);
42
}
43
44
int
clone_app_runtime_native
(
const
AppRuntime
*source,
AppRuntime
*target) {
45
if
(source == NULL || target == NULL) {
46
return
-1;
47
}
48
memset(target, 0,
sizeof
(*target));
49
target->
app_id
=
clone_optional_string
(source->
app_id
);
50
target->
app_root
=
clone_optional_string
(source->
app_root
);
51
target->
build_dir
=
clone_optional_string
(source->
build_dir
);
52
target->
artifact_dir
=
clone_optional_string
(source->
artifact_dir
);
53
target->
host_profile
=
clone_optional_string
(source->
host_profile
);
54
target->
compiled_entrypoint
=
clone_optional_string
(source->
compiled_entrypoint
);
55
target->
state_path
=
clone_optional_string
(source->
state_path
);
56
target->
base_path
=
clone_optional_string
(source->
base_path
);
57
target->
log_path
=
clone_optional_string
(source->
log_path
);
58
target->
log_format
=
clone_optional_string
(source->
log_format
);
59
target->
error_report_path
=
clone_optional_string
(source->
error_report_path
);
60
target->
debug
=
clone_optional_string
(source->
debug
);
61
target->
runtime_conf_path
=
clone_optional_string
(source->
runtime_conf_path
);
62
if
((source->
app_id
!= NULL && target->
app_id
== NULL) ||
63
(source->
app_root
!= NULL && target->
app_root
== NULL) ||
64
(source->
build_dir
!= NULL && target->
build_dir
== NULL) ||
65
(source->
artifact_dir
!= NULL && target->
artifact_dir
== NULL) ||
66
(source->
host_profile
!= NULL && target->
host_profile
== NULL) ||
67
(source->
compiled_entrypoint
!= NULL && target->
compiled_entrypoint
== NULL) ||
68
(source->
state_path
!= NULL && target->
state_path
== NULL) ||
69
(source->
base_path
!= NULL && target->
base_path
== NULL) ||
70
(source->
log_path
!= NULL && target->
log_path
== NULL) ||
71
(source->
log_format
!= NULL && target->
log_format
== NULL) ||
72
(source->
error_report_path
!= NULL && target->
error_report_path
== NULL) ||
73
(source->
debug
!= NULL && target->
debug
== NULL) ||
74
(source->
runtime_conf_path
!= NULL && target->
runtime_conf_path
== NULL)) {
75
clear_cloned_app_runtime
(target);
76
return
-1;
77
}
78
return
0;
79
}
clone_optional_string
static char * clone_optional_string(const char *value)
Definition
native_app_runtime_clone.c:37
native_clone_strdup
#define native_clone_strdup
Definition
native_app_runtime_clone.c:14
clone_app_runtime_native
int clone_app_runtime_native(const AppRuntime *source, AppRuntime *target)
Deep-copies one loaded app runtime into another record.
Definition
native_app_runtime_clone.c:44
clear_cloned_app_runtime
static void clear_cloned_app_runtime(AppRuntime *app)
Definition
native_app_runtime_clone.c:17
native_app_runtime_clone.h
Declares helpers for cloning AppRuntime values.
AppRuntime
Loaded runtime metadata for one Pharos app artifact.
Definition
native_runtime_types.h:37
AppRuntime::build_dir
char * build_dir
Definition
native_runtime_types.h:40
AppRuntime::error_report_path
char * error_report_path
Definition
native_runtime_types.h:48
AppRuntime::debug
char * debug
Definition
native_runtime_types.h:49
AppRuntime::artifact_dir
char * artifact_dir
Definition
native_runtime_types.h:41
AppRuntime::base_path
char * base_path
Definition
native_runtime_types.h:45
AppRuntime::app_id
char * app_id
Definition
native_runtime_types.h:38
AppRuntime::compiled_entrypoint
char * compiled_entrypoint
Definition
native_runtime_types.h:43
AppRuntime::app_root
char * app_root
Definition
native_runtime_types.h:39
AppRuntime::host_profile
char * host_profile
Definition
native_runtime_types.h:42
AppRuntime::state_path
char * state_path
Definition
native_runtime_types.h:44
AppRuntime::log_format
char * log_format
Definition
native_runtime_types.h:47
AppRuntime::log_path
char * log_path
Definition
native_runtime_types.h:46
AppRuntime::runtime_conf_path
char * runtime_conf_path
Definition
native_runtime_types.h:50
src
native_runtime
c
native_app_runtime_clone.c
Generated by
1.17.0