MFC r302943,r302944,r303004,r303010,r303011,r303013,r303014,r303074,


MFC r302943,r302944,r303004,r303010,r303011,r303013,r303014,r303074,


In short:

  1. All situations with glob(3) error return codes are well defined by

POSIX, so rewrite old sporadic errors processing to match those

Including subcases:

Both C99 and POSIX directly prohibits any standard function to set errno
to 0. Breaking this rule in 2001 NetBSD hack was imported which attempts
to workaround very limited glob(3) return codes amount.
Use POSIX-compatible workaround now with E2BIG which can't comes from
other functions used instead of prohibited 0.

Process errors happpens in (*readdirfunc)() too, as POSIX requires.

Per POSIX GLOB_NOCHECK should return original pattern,
unmodified, if no matches found. But our code strips all '\'
returning it. Rewrite the code to allow to return original pattern.

GLOB_ERR and gl_errfunc are supposed to work only for real directories
per POSIX, so don't act on missing or plain files for ENOENT or ENOTDIR
(as TODO in the code suggested).
Remove the hack in the manpage describing how to skip ENOENT and ENOTDIR
in gl_errfunc, it is unneeded now.

Per POSIX GLOB_ERR must be considered even if gl_errfunc is not set,
old code skips it in that case.

  1. For near MAXPATHLEN long pathes old glob(3) code can operate on

truncated results, prevent it in several places.

  1. Results was not sorted according to collate as POSIX requires.
  1. globtilde() forget to convert expanded user home dir from multibyte to

wide chars. Moreover, those chars are addded as not protected, so
can be treated as special chars.

  1. Backward hack for EILSEQ in g_Ctoc() was not implemented, so all

pathes with illegal byte sequences are skipped as result, implement it now.

  1. GLOB_BRACE was somehow broken. First it repeatedly calls glob0() in

globexp1() recursive calls, but glob0() was not supposed to be called
repeatedly in the original code. It finalize results by possible adding
original pattern for no match case, may return GLOB_NOMATCH error and
by sorting all things. Original pattern adding or GLOB_NOMATCH error
can happens each time glob0() called repeatedly, and sorting happens
for one item only, all things are never sorted. Second, f.e. "a{a"
pattern does not match "a{a" file but match "a" file instead.
Third, some errors (f.e. for limits or overflow) can be ignored
by GLOB_BRACE code because it forces return (0).

Add non-finalizing flag to glob0() and make globexp0() wrapper around
recursively called globexp1() to finalize things like glob0() does.
Reorganize braces code to work correctly.

  1. Don't allow MB_CUR_MAX * strlen overallocation hits GLOB_LIMIT_STRING

(ARG_MAX) limit, use final string length, not malloced space for it.


acheAuthored on
rS304202: tcp/lro: Make # of LRO entries tunable