TFTP
Fix error of not writing the index.txt correctly
This commit is contained in:
@@ -15,6 +15,27 @@ static llfs_file_t virt_file[2] = {
|
||||
{.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]) {
|
||||
|
||||
Reference in New Issue
Block a user