[PATCH weston v4] xwm: tell the shell the pid of the X clients

Bill Spitzak spitzak at gmail.com
Tue Jan 27 11:56:42 PST 2015


On 01/27/2015 06:52 AM, Daniel Stone wrote:

> POSIX.1-2001 says that if such
>         truncation occurs, then it is unspecified whether the returned
> buffer includes a terminating
>         null byte.
>
> I think the best thing to do here would be:
>    for (i = 0; i < sizeof(name); i++) {
>        if (name[i] == '\0')
>            break;
>    }
>    if (i == sizeof(name))
>        name[0] = '\0'; /* ignore stupid hostnames */

Or make the buffer 1 larger than you tell the function, and put a zero 
at the end:

    gethostname(buffer, sizeof(buffer)-1);
    buffer[sizeof(buffer)-1] = '\0';


More information about the wayland-devel mailing list