setmode patches

Liam J. Foy liamfoy at
Sun Jun 5 19:12:50 GMT 2005

Hey guys,

	I want to show you all some patches:

This will allow errno to be set in all cases to ERANGE. We can then check this
in applications which use setmode(3). Most usage of setmode(3) assumes that that
setmode will fail due to an invalid file mode. Example:

This snip is from chmod.c:

        if (hflag)
                change_mode = lchmod;
                change_mode = chmod;

        mode = *argv;
        if ((set = setmode(mode)) == NULL)
                errx(1, "invalid file mode: %s", mode);

        if ((ftsp = fts_open(++argv, fts_options, 0)) == NULL)
                err(1, "fts_open");
        for (rval = 0; (p = fts_read(ftsp)) != NULL;) {

However, setmode(3) can fail due to malloc. With the following patch, we can
show whether it was actually a bad file mode or something else (malloc):

Anyone have any comments/suggestions? There are also many other instances where
setmode is assumed to fail due to a invalid file mode only (I can also create
these patches).

		- Liam J. Foy
		liamfoy at

More information about the freebsd-standards mailing list