TFTP
Move over to the new fread that Lorentz is implementing
This commit is contained in:
@@ -10,8 +10,9 @@
|
||||
#include <tftp_server.h>
|
||||
#include "log.h"
|
||||
#include "llfs.h"
|
||||
#include "stdlib.h"
|
||||
#include "string.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define TFTP_READ 0
|
||||
|
||||
|
||||
@@ -52,7 +52,6 @@ int str_cat(char* dest, int dest_size, char c)
|
||||
*/
|
||||
void* tftp_open(const char* fname, const char* mode, u8_t write) {
|
||||
LOG_INFO(TAG, "Opening %s", fname);
|
||||
llfs_file_t* file;
|
||||
|
||||
if (strcmp(fname, virt_file[0].name) == 0 && write == TFTP_READ) {
|
||||
return &virt_file[0];
|
||||
@@ -60,7 +59,8 @@ void* tftp_open(const char* fname, const char* mode, u8_t write) {
|
||||
return &virt_file[1];
|
||||
}
|
||||
|
||||
return llfs_file_open(fname);
|
||||
// TODO: waiting on Lorentz to finish creating f* functions for LLFS
|
||||
return fopen(fname, write ? "wb" : "rb");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,6 +70,16 @@ void* tftp_open(const char* fname, const char* mode, u8_t write) {
|
||||
*/
|
||||
void tftp_close(void* handle) {
|
||||
LOG_INFO(TAG, "closing file");
|
||||
if (handle == NULL) {
|
||||
LOG_CRIT(TAG, "handle is null");
|
||||
return;
|
||||
}
|
||||
if (handle == &virt_file[0] || handle == &virt_file[1]) {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: waiting on Lorentz to finish creating f* functions for LLFS
|
||||
fclose((FILE*)handle);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,10 +95,10 @@ void tftp_close(void* handle) {
|
||||
int tftp_read(void* handle, void* buf, int bytes) {
|
||||
LOG_INFO(TAG, "reading file");
|
||||
if (handle == NULL) {
|
||||
LOG_ERROR(TAG, "handle is null");
|
||||
LOG_CRIT(TAG, "handle is null");
|
||||
return -1;
|
||||
}
|
||||
llfs_file_t* file = (llfs_file_t*)handle;
|
||||
FILE* file = (FILE*)handle;
|
||||
LOG_INFO(TAG, "reading file: %s", file->name);
|
||||
|
||||
if (file == &virt_file[0]) {
|
||||
@@ -106,7 +116,8 @@ int tftp_read(void* handle, void* buf, int bytes) {
|
||||
LOG_CRIT(TAG, "Exception: Trying to read a write only file");
|
||||
return -1;
|
||||
}
|
||||
memcpy(buf, file->data, bytes);
|
||||
// TODO: waiting on Lorentz to finish creating f* functions for LLFS
|
||||
fread(buf, sizeof(uint8_t), bytes, file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user