On Mon, Apr 26, 2010 at 7:04 AM, Cyril Hrubis <[email protected]> wrote: > Hi! >> 2. Why do you feel this is required? > > Well, accordingly to POSIX you can't realy rely on having /bin/sh or even > /usr/bin/sh. On the other hand I haven't seen any linux system that has no > /bin/sh. And accordingly to FSH /bin/sh is required to exist. So this really > depends on how much we want to be compatible with POSIX and strange unixes out > there (if there are any).
Even though POSIX doesn't say that /bin/sh shouldn't exist, if /bin/sh doesn't exist then the person executing the tests is up a creek without a paddle. It's fine to leave it as-is. > * FSH http://www.pathname.com/fhs/ > * POSIX http://www.opengroup.org/onlinepubs/000095399/utilities/sh.html > (paragraph "application usage") > >> 3. This should really be a single snprintf call: >> >> + /* copy path */ >> + for (i = 0; i < buf_len && path[i] != '\0' && path[i] != ':'; >> i++) >> + buf[i] = path[i]; >> + >> + /* add slash at the end if needed */ >> + if (buf[i - 1] != '/') >> + buf[i++] = '/'; >> + /* copy the program name */ >> + strncpy(buf + i, prog_name, buf_len - i); >> >> similar to the following: >> >> if (snprintf(buf, buf_len, "%s/%s", path_element, prog_name) > buf_len) >> /* error out */ >> else if (file_exist(buf)) >> return 0; /* etc... */ >> /* ... */ > > This way I would need either to copy the path element into temporary > path_element[] array each time before snprintf is called or duplicate the > string returned by getenv("PATH") so that I could insert '\0' in it. Advance the pointer for the path array as necessary and just NUL terminate the end? The point was that strncpy is a bad operation to perform when dealing with paths (especially when the return code isn't checked like above). Thanks, -Garrett ------------------------------------------------------------------------------ _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
