confused about ngx_write_file
Ruslan Ermilov
ru at nginx.com
Mon Nov 20 11:06:30 UTC 2017
On Mon, Nov 20, 2017 at 02:59:39AM -0500, hook wrote:
> 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.
file->offset is only used for sequential read/write. For other
cases, its value is undefined.
> 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
>
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
>
--
Ruslan Ermilov
Assume stupidity not malice
More information about the nginx
mailing list