aboutsummaryrefslogtreecommitdiff
path: root/src/examples/https_fileserver_example.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/examples/https_fileserver_example.c')
-rw-r--r--src/examples/https_fileserver_example.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/examples/https_fileserver_example.c b/src/examples/https_fileserver_example.c
index ae304f72..30fbf4d8 100644
--- a/src/examples/https_fileserver_example.c
+++ b/src/examples/https_fileserver_example.c
@@ -112,10 +112,19 @@ OT1qAbIblaRuWqCsid8BzP7ZQiAnAWgMRSUg1gzDwSwRhrYQRRWAyn/Qipzec+27\n\
112static ssize_t 112static ssize_t
113file_reader (void *cls, uint64_t pos, char *buf, size_t max) 113file_reader (void *cls, uint64_t pos, char *buf, size_t max)
114{ 114{
115 FILE *file = cls; 115 FILE *file = (FILE *) cls;
116 size_t bytes_read;
116 117
117 (void) fseek (file, pos, SEEK_SET); 118 /* 'fseek' may not support files larger 2GiB, depending on platform.
118 return fread (buf, 1, max, file); 119 * For production code, make sure that 'pos' has valid values, supported by
120 * 'fseek', or use 'fseeko' or similar function. */
121 if (0 != fseek (file, (long) pos, SEEK_SET))
122 return MHD_CONTENT_READER_END_WITH_ERROR;
123 bytes_read = fread (buf, 1, max, file);
124 if (0 == bytes_read)
125 return (0 != ferror (file)) ? MHD_CONTENT_READER_END_WITH_ERROR :
126 MHD_CONTENT_READER_END_OF_STREAM;
127 return (ssize_t) bytes_read;
119} 128}
120 129
121 130