[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: libps

> Hi All,
> ps.h states on lines 257-260 that:
> /* The process's argv, as a string with each element separated by '\0'.  */
> char *args;
> /* The length of ARGS.  */
> unsigned args_len;
> It actually contains that plus an extra null at the end.

That comment is imprecise.  The code is correct as it stands.  It should
say that it's stored in what we now call "argz format" (terminology is due
to Miles Bader, who wrote all the fine <argz.h> routines to make handling
these buggers easy).  What "argz format" means is that each string is
followed by a '\0' terminator (including the final string), and the length
refers to the sum of the strings' lengths including each string's
terminator.  This is a more simple and consistent definition than eliding
the final terminator, it has the feature of making the tail of the argz a
properly-terminated C string you can use in normal ways, and it makes it
possible to distinguish an empty argz (no strings, length 0) from an argz
containing just the empty string ("", length 1)--or, in fact, to represent
a trailing empty string in an argz at all.

Reply to: