confused about ngx_write_file
hook
nginx-forum at forum.nginx.org
Mon Nov 20 07:59:39 UTC 2017
Hi
I'm writing some module with using ngx_write_file. I found file's
offset is incorrect, in this case:
```
u_char av = 0x01 | 0x04;
// file cur offset -> 4096;
ngx_write_file(file, &av, 1, 4)
```
file->offset would be 4097, but real offset is 4096.
I'm confused with the codes :
192 ssize_t
193 ngx_write_file(ngx_file_t *file, u_char *buf, size_t size, off_t
offset)
194 {
........
221
222 file->offset += n;
223 written += n;
224
225 if ((size_t) n == size) {
226 return written;
227 }
228
229 offset += n;
230 size -= n;
231 }
should it be:
222 written += n;
223 offset += n;
224
225 if (offset > file->offset) {
226 file->offset = offset;
227 }
228
229 if ((size_t) n == size) {
230 return written;
231 }
232
233 size -= n;
234 }
Thanks!
Posted at Nginx Forum: https://forum.nginx.org/read.php?2,277386,277386#msg-277386
More information about the nginx
mailing list