Skip to content

Commit

Permalink
Change mg_file_read() signature: return mg_str
Browse files Browse the repository at this point in the history
  • Loading branch information
cpq committed Feb 16, 2024
1 parent d128d21 commit cf707f9
Show file tree
Hide file tree
Showing 23 changed files with 84 additions and 1,036 deletions.
8 changes: 4 additions & 4 deletions examples/device-dashboard/packed_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ static const unsigned char v1[] = {
0, 0 // .
};
static const unsigned char v2[] = {
31, 139, 8, 8, 87, 102, 129, 101, 0, 3, 99, 111, // ....Wf.e..co
31, 139, 8, 8, 7, 115, 132, 101, 0, 3, 99, 111, // .....s.e..co
109, 112, 111, 110, 101, 110, 116, 115, 46, 106, 115, 0, // mponents.js.
237, 93, 235, 115, 219, 70, 146, 255, 238, 191, 98, 162, // .].s.F....b.
242, 45, 169, 181, 0, 225, 77, 64, 182, 148, 114, 156, // [email protected].
Expand Down Expand Up @@ -2127,7 +2127,7 @@ static const unsigned char v5[] = {
237, 34, 77, 0, 0, 0 // ."M..
};
static const unsigned char v6[] = {
31, 139, 8, 8, 215, 103, 114, 101, 0, 3, 109, 97, // .....gre..ma
31, 139, 8, 8, 93, 214, 178, 101, 0, 3, 109, 97, // ....]..e..ma
105, 110, 46, 106, 115, 0, 189, 91, 233, 114, 219, 72, // in.js..[.r.H
146, 254, 239, 167, 168, 230, 184, 155, 164, 155, 0, 9, // ............
82, 151, 105, 81, 29, 62, 219, 158, 112, 219, 14, 75, // R.iQ.>..p..K
Expand Down Expand Up @@ -2668,11 +2668,11 @@ static const struct packed_file {
time_t mtime;
} packed_files[] = {
{"/web_root/bundle.js.gz", v1, sizeof(v1), 1695912421},
{"/web_root/components.js.gz", v2, sizeof(v2), 1702979159},
{"/web_root/components.js.gz", v2, sizeof(v2), 1703179015},
{"/web_root/history.min.js.gz", v3, sizeof(v3), 1695912421},
{"/web_root/index.html.gz", v4, sizeof(v4), 1693654553},
{"/web_root/main.css.gz", v5, sizeof(v5), 1702757929},
{"/web_root/main.js.gz", v6, sizeof(v6), 1701996503},
{"/web_root/main.js.gz", v6, sizeof(v6), 1706219101},
{"/certs/server_cert.pem", v7, sizeof(v7), 1692695603},
{"/certs/server_key.pem", v8, sizeof(v8), 1692695603},
{NULL, NULL, 0, 0}
Expand Down
2 changes: 2 additions & 0 deletions examples/esp32/uart-bridge/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@

const char *s_listening_url = "http://0.0.0.0:80";

#if 0
char *config_read(void) {
return mg_file_read(&mg_fs_posix, FS_ROOT "/config.json", NULL);
}
#endif

void config_write(struct mg_str config) {
mg_file_write(&mg_fs_posix, FS_ROOT "/config.json", config.ptr, config.len);
Expand Down
11 changes: 5 additions & 6 deletions examples/modbus-dashboard/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@ static void signal_handler(int sig_num) {

bool web_load_settings(void *buf, size_t len) {
bool ok = false;
size_t size = 0;
void *data = mg_file_read(&mg_fs_posix, CONFIG_FILE, &size);
if (data == NULL) {
struct mg_str data = mg_file_read(&mg_fs_posix, CONFIG_FILE);
if (data.ptr == NULL) {
MG_ERROR(("Error reading %s", CONFIG_FILE));
} else if (size != len) {
} else if (data.len != len) {
MG_ERROR(("%s size != %lu", CONFIG_FILE, len));
} else {
memcpy(buf, data, len);
memcpy(buf, data.ptr, len);
}
free(data);
free((void *) data.ptr);
return ok;
}

Expand Down
8 changes: 4 additions & 4 deletions examples/mqtt-dashboard/device/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ static void set_device_id(void) {
fclose(fp);
}
#elif defined(__linux__)
char *id = mg_file_read(&mg_fs_posix, "/etc/machine-id", NULL);
if (id != NULL) {
mg_snprintf(buf, sizeof(buf), "%s", id);
free(id);
struct mg_str id = mg_file_read(&mg_fs_posix, "/etc/machine-id");
if (id.ptr != NULL) {
mg_snprintf(buf, sizeof(buf), "%s", id.ptr);
free((void *) id.ptr);
}
#endif

Expand Down

This file was deleted.

Loading

0 comments on commit cf707f9

Please sign in to comment.