Welcome! Log In Create A New Profile

Advanced

Re: [Patch] add -h to nginx

All files from this thread

File Name File Size   Posted by Date  
nginx-help.patch 1.3 KB open | download Jérôme Loyet 03/24/2009 Read message
nginx-help.patch 1.3 KB open | download Jérôme Loyet 03/24/2009 Read message
nginx-help.patch 1.4 KB open | download Jérôme Loyet 03/24/2009 Read message
March 25, 2009 06:19AM
On Tue, Mar 24, 2009 at 02:15:29PM +0100, J?r?me Loyet wrote:

> And I ask myself a question, why use those lines:
> p = "nginx version: " NGINX_VER CRLF;
> n = sizeof("nginx version: " NGINX_VER CRLF) - 1;
>
> if (ngx_write_fd(ngx_stderr_fileno, p, n) != n) {
> return 1;
> }
>
> instead of
>
> p = "nginx version: " NGINX_VER CRLF;
>
> if (ngx_write_fd(ngx_stderr_fileno, p, strlen(p)) != n) {
> return 1;
> }

Because strlen() finds a string length on run-time, scanning for trailing
zero, while sizeof() return length of a known string on compile time.
For this reason I use strlen() only if it's really needed.

However, here are two notes:
1) modern compilers usually optimize such strlen()s to just sizeof()s,
2) this place is not time critical, so strlen() can be used.


--
Igor Sysoev
http://sysoev.ru/en/
Subject Author Posted

[Patch] add -h to nginx Attachments

Jérôme Loyet March 24, 2009 09:47AM

Re: [Patch] add -h to nginx Attachments

Jérôme Loyet March 24, 2009 09:52AM

Re: [Patch] add -h to nginx

Juan Fco. Giordana March 24, 2009 10:27AM

Re: [Patch] add -h to nginx Attachments

Jérôme Loyet March 24, 2009 11:36AM

Re: [Patch] add -h to nginx

Igor Sysoev March 25, 2009 06:19AM

Re: [Patch] add -h to nginx

Igor Sysoev March 25, 2009 06:23AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 199
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