aboutsummaryrefslogtreecommitdiff
path: root/src/routing.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/routing.c')
-rw-r--r--src/routing.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/routing.c b/src/routing.c
index d5d3969..1ae4ce9 100644
--- a/src/routing.c
+++ b/src/routing.c
@@ -322,16 +322,26 @@ bool serve_static_file_with_mime(const char *request_path_relative_to_static, co
char file_buffer[BUFFER_SIZE];
size_t bytes_read;
+ bool send_error = false;
- while ((bytes_read = fread(file_buffer, 1, sizeof(file_buffer), fp)) > 0) {
+ clearerr(fp);
+ while (!send_error && !feof(fp) && !ferror(fp) && (bytes_read = fread(file_buffer, 1, sizeof(file_buffer), fp)) > 0) {
if (send(current_client_socket, file_buffer, bytes_read, 0) < 0) {
perror("Error sending static file content");
fprintf(stderr, "[ERROR] serve_static_file_with_mime: Failed to send content for '%s'.\n",
full_static_path);
- break;
+ send_error = true;
}
}
+ if (ferror(fp)) {
+ perror("Error reading static file");
+ fprintf(stderr, "[ERROR] serve_static_file_with_mime: Failed to read '%s'.\n",
+ full_static_path);
+ fclose(fp);
+ return true;
+ }
+
fclose(fp);
return true;
}