Fix error of not writing the index.txt correctly
This commit is contained in:
2023-11-09 18:07:47 +01:00
parent 8237f7911b
commit 81da833c5b

View File

@@ -13,7 +13,28 @@ extern struct llfs_data_file* llfs_root;
static llfs_file_t virt_file[2] = {
{.name = "index.txt", .data = "test", .len = 4},
{.name = "virtImage.raw", .data = "test", .len = 4}
};
};
int str_cat_str(char* dest, int dest_size, const char* src) {
int dest_len = strlen(dest);
int src_len = strlen(src);
if (dest_len + src_len > dest_size) {
return -1;
}
memcpy(dest + dest_len, src, src_len);
return 0;
}
int str_cat(char* dest, int dest_size, char c)
{
int dest_len = strlen(dest);
if (dest_len + 1 > dest_size) {
return -1;
}
dest[dest_len] = c;
dest[dest_len + 1] = '\0';
return 0;
}
/**
* @brief tftp helper functions
@@ -72,10 +93,13 @@ int tftp_read(void* handle, void* buf, int bytes) {
if (file == &virt_file[0]) {
const struct llfs_data_file* root = llfs_root;
snprintf(buf, bytes, "%s\n", virt_file[0].name);
snprintf(buf, bytes, "%s\n", virt_file[1].name);
str_cat_str(buf, bytes, virt_file[0].name);
str_cat(buf, bytes, '\n');
str_cat_str(buf, bytes, virt_file[1].name);
str_cat(buf, bytes, '\n');
while(root != NULL) {
snprintf(buf, bytes, "%s\n", root->name);
str_cat(buf, bytes, root->name);
str_cat(buf, bytes, '\n');
file = root->next;
}
} else if (file == &virt_file[1]) {