diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/gen/fts.3 | 23 | ||||
-rw-r--r-- | lib/libc/gen/fts.c | 18 |
2 files changed, 27 insertions, 14 deletions
diff --git a/lib/libc/gen/fts.3 b/lib/libc/gen/fts.3 index cd6bdb78e5d..967346efcd4 100644 --- a/lib/libc/gen/fts.3 +++ b/lib/libc/gen/fts.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: fts.3,v 1.25 2009/03/23 22:57:36 sobrado Exp $ +.\" $OpenBSD: fts.3,v 1.26 2009/08/27 16:19:27 millert Exp $ .\" .\" Copyright (c) 1989, 1991, 1993, 1994 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)fts.3 8.5 (Berkeley) 4/16/94 .\" -.Dd $Mdocdate: March 23 2009 $ +.Dd $Mdocdate: August 27 2009 $ .Dt FTS 3 .Os .Sh NAME @@ -230,10 +230,25 @@ was found. The .Li FTSENT structure representing the parent of the starting point (or root) -of the traversal is numbered \-1, and the +of the traversal is numbered +.Ev FTS_PARENTLEVEL +(\-1), and the .Li FTSENT structure for the root -itself is numbered 0. +itself is numbered +.Ev FTS_ROOTLEVEL +(0). +Note that while +.Fa fts_level +cannot hold a number of levels greater than +.Ev FTS_MAXLEVEL , +the +.Nm +functions themselves are not limited to a fixed number +of levels. +Application code that inspects +.Fa fts_level +should be written with this in mind. .It Fa fts_errno Upon return of an .Li FTSENT diff --git a/lib/libc/gen/fts.c b/lib/libc/gen/fts.c index 62b815fd2f0..bbc1dc7475b 100644 --- a/lib/libc/gen/fts.c +++ b/lib/libc/gen/fts.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fts.c,v 1.42 2009/02/11 13:24:05 otto Exp $ */ +/* $OpenBSD: fts.c,v 1.43 2009/08/27 16:19:27 millert Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -633,15 +633,13 @@ fts_build(FTS *sp, int type) len++; maxlen = sp->fts_pathlen - len; - if (cur->fts_level == SHRT_MAX) { - (void)closedir(dirp); - cur->fts_info = FTS_ERR; - SET(FTS_STOP); - errno = ENAMETOOLONG; - return (NULL); - } - - level = cur->fts_level + 1; + /* + * fts_level is a short so we must prevent it from wrapping + * around to FTS_ROOTLEVEL and FTS_ROOTPARENTLEVEL. + */ + level = cur->fts_level; + if (level < FTS_MAXLEVEL) + level++; /* Read the directory, attaching each entry to the `link' pointer. */ doadjust = 0; |