Add tftp_custom_fwrite
This commit is contained in:
2023-11-13 13:28:57 +01:00
parent d36ce9ae1e
commit c568acc9e6
2 changed files with 22 additions and 0 deletions

View File

@@ -30,6 +30,7 @@ void tftp_server_init(void);
void tftp_server_deinit(void);
void tftp_custom_fseek(tftp_custom_file_t* handle, size_t offset, int whence);
size_t tftp_custom_fread(void* buf, size_t bytes, tftp_custom_file_t* handle);
size_t tftp_custom_fwrite(void* buf, size_t bytes, tftp_custom_file_t* handle);
#ifdef __cplusplus
}

View File

@@ -82,6 +82,27 @@ size_t tftp_custom_fread(void* buf, size_t bytes, tftp_custom_file_t* handle) {
return bytes;
}
/**
* @brief tftp custom file functions to write the data
* auto rolling over the offset
*
* @param buf The buffer to write the data to
* @param bytes The number of bytes to write
* @param handle The handle to the file to write to
* @return The number of bytes written
*/
size_t tftp_custom_fwrite(void* buf, size_t bytes, tftp_custom_file_t* handle) {
if (handle->ofset + bytes > handle->len) {
bytes = handle->len - handle->ofset;
}
memcpy(handle->data + handle->ofset, buf, bytes);
handle->ofset += bytes;
if (handle->ofset > handle->len) {
bytes = 0;
}
return bytes;
}
/**
* @brief tftp helper functions
*/