[Patch] add -h to nginx

Igor Sysoev is at rambler-co.ru
Wed Mar 25 13:19:39 MSK 2009


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/





More information about the nginx mailing list