Pharos
0.7.23
Modern Web Framework & Web App Hosting Service.
Toggle main menu visibility
Loading...
Searching...
No Matches
native_spawn_temp_body.c
Go to the documentation of this file.
1
/**
2
* @file
3
* @brief Writes multipart request bodies to temporary files and removes them during cleanup.
4
*/
5
6
#include "
native_spawn_temp_body.h
"
7
8
#include <stdlib.h>
9
#include <string.h>
10
11
#ifdef _WIN32
12
#include <io.h>
13
#define pharos_spawn_temp_body_write _write
14
#define pharos_spawn_temp_body_close _close
15
#define pharos_spawn_temp_body_unlink _unlink
16
#define pharos_spawn_temp_body_strdup _strdup
17
#else
18
#include <unistd.h>
19
#define pharos_spawn_temp_body_write write
20
#define pharos_spawn_temp_body_close close
21
#define pharos_spawn_temp_body_unlink unlink
22
#define pharos_spawn_temp_body_strdup strdup
23
#endif
24
25
#if defined(_WIN32)
26
int
write_native_temp_body_file
(
const
char
*body,
size_t
body_len,
char
**temp_body_path_out) {
27
(void)body;
28
(void)body_len;
29
if
(temp_body_path_out != NULL) {
30
*temp_body_path_out = NULL;
31
}
32
return
78;
33
}
34
#else
35
int
write_native_temp_body_file
(
const
char
*body,
size_t
body_len,
char
**temp_body_path_out) {
36
char
temp_template[] =
"/tmp/pharos-body-XXXXXX"
;
37
int
temp_fd;
38
if
(temp_body_path_out == NULL) {
39
return
69;
40
}
41
*temp_body_path_out = NULL;
42
temp_fd = mkstemp(temp_template);
43
if
(temp_fd < 0) {
44
return
69;
45
}
46
if
(body_len > 0 &&
pharos_spawn_temp_body_write
(temp_fd, body != NULL ? body :
""
, body_len) < 0) {
47
pharos_spawn_temp_body_close
(temp_fd);
48
pharos_spawn_temp_body_unlink
(temp_template);
49
return
69;
50
}
51
pharos_spawn_temp_body_close
(temp_fd);
52
*temp_body_path_out =
pharos_spawn_temp_body_strdup
(temp_template);
53
if
(*temp_body_path_out == NULL) {
54
pharos_spawn_temp_body_unlink
(temp_template);
55
return
69;
56
}
57
return
0;
58
}
59
#endif
60
61
void
cleanup_native_temp_body_file
(
char
**temp_body_path_io) {
62
if
(temp_body_path_io == NULL || *temp_body_path_io == NULL) {
63
return
;
64
}
65
pharos_spawn_temp_body_unlink
(*temp_body_path_io);
66
free(*temp_body_path_io);
67
*temp_body_path_io = NULL;
68
}
pharos_spawn_temp_body_strdup
#define pharos_spawn_temp_body_strdup
Definition
native_spawn_temp_body.c:22
write_native_temp_body_file
int write_native_temp_body_file(const char *body, size_t body_len, char **temp_body_path_out)
Writes a request body to a temporary file for multipart request execution.
Definition
native_spawn_temp_body.c:35
pharos_spawn_temp_body_write
#define pharos_spawn_temp_body_write
Definition
native_spawn_temp_body.c:19
pharos_spawn_temp_body_unlink
#define pharos_spawn_temp_body_unlink
Definition
native_spawn_temp_body.c:21
cleanup_native_temp_body_file
void cleanup_native_temp_body_file(char **temp_body_path_io)
Removes a temporary request-body file and clears its stored path.
Definition
native_spawn_temp_body.c:61
pharos_spawn_temp_body_close
#define pharos_spawn_temp_body_close
Definition
native_spawn_temp_body.c:20
native_spawn_temp_body.h
Declares temporary request-body file helpers.
src
native_runtime
c
native_spawn_temp_body.c
Generated by
1.17.0