TFTP
Add tftp_custom_fwrite
This commit is contained in:
@@ -30,6 +30,7 @@ void tftp_server_init(void);
|
|||||||
void tftp_server_deinit(void);
|
void tftp_server_deinit(void);
|
||||||
void tftp_custom_fseek(tftp_custom_file_t* handle, size_t offset, int whence);
|
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_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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,6 +82,27 @@ size_t tftp_custom_fread(void* buf, size_t bytes, tftp_custom_file_t* handle) {
|
|||||||
return bytes;
|
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
|
* @brief tftp helper functions
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user