Welcome! Log In Create A New Profile

Advanced

bug in function ngx_write_file?

lu wenbin
July 01, 2010 01:58AM
Hi
I read the code in src/os/ngx_files.c, function ngx_write_file, but
get a little confused
* for ( ;; ) {
n = pwrite(file->fd, buf, size, offset);

if (n == -1) {
ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno,
"pwrite() \"%s\" failed", file->name.data);
return NGX_ERROR;
}

file->offset += n;
written += n;

if ((size_t) n == size) {
return written;
}

offset += n;
size -= n;
}
* the code seems want to write all content in buf to file(file->fd), but
I think *n = pwrite(file->fd, buf, size, offset) *should be changed to* **n
= pwrite(file->fd, buf+written, size, offset);
man pwrite:
**pwrite() writes up to count bytes from the buffer starting at buf
to the file descriptor fd at offset offset. The file offset is not
changed.**


*
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

bug in function ngx_write_file?

lu wenbin 2625 July 01, 2010 01:58AM

Re: bug in function ngx_write_file?

Igor Sysoev 1413 July 01, 2010 02:02AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 105
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready