Pharos 0.7.23
Modern Web Framework & Web App Hosting Service.
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
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
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
37static char *clone_optional_string(const char *value) {
38 if (value == NULL) {
39 return NULL;
40 }
41 return native_clone_strdup(value);
42}
43
44int 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);
56 target->base_path = clone_optional_string(source->base_path);
57 target->log_path = clone_optional_string(source->log_path);
60 target->debug = clone_optional_string(source->debug);
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)) {
76 return -1;
77 }
78 return 0;
79}
static char * clone_optional_string(const char *value)
#define native_clone_strdup
int clone_app_runtime_native(const AppRuntime *source, AppRuntime *target)
Deep-copies one loaded app runtime into another record.
static void clear_cloned_app_runtime(AppRuntime *app)
Declares helpers for cloning AppRuntime values.
Loaded runtime metadata for one Pharos app artifact.