History log of /openbsd-current/lib/libc/gen/scandir.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.23 15-Apr-2024 florian

Add scandirat(3); from freebsd

To be used in httpd(8) shortly to prevent toctu issues.

This makes __fdopendir internally accessible to avoid unnecessary
syscalls in scandirat(3). Suggested & diff by guenther

suggested by & OK millert
tweak & OK guenther
OK tb, jca

This rides the libc crank.


# 1.22 14-Apr-2024 florian

Zap trailing whitespace.

OK tb


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE OPENBSD_7_1_BASE OPENBSD_7_2_BASE OPENBSD_7_3_BASE OPENBSD_7_4_BASE OPENBSD_7_5_BASE
# 1.21 28-Jun-2019 deraadt

When system calls indicate an error they return -1, not some arbitrary
value < 0. errno is only updated in this case. Change all (most?)
callers of syscalls to follow this better, and let's see if this strictness
helps us in the future.


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.20 20-Aug-2015 deraadt

All these files include <stdlib.h>, so do not need to cast
malloc/calloc/realloc* returns.


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.19 05-Feb-2015 millert

Include stdint.h, not limits.h to get SIZE_MAX. OK guenther@


# 1.18 16-Jan-2015 deraadt

Move to the <limits.h> universe.
review by millert, binary checking process with doug, concept with guenther


# 1.17 08-Oct-2014 deraadt

obvious reallocarray()


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.16 17-Apr-2013 tedu

add some prototypes, casts, includes, parenthesis, and whatnot to
silence some warnings.


Revision tags: OPENBSD_5_3_BASE
# 1.15 29-Nov-2012 guenther

Change scandir()'s 'select' argument from
int (*)(struct dirent *)
to
int (*)(const struct dirent *)
to match POSIX.

ok millert@, ports check by naddy@


Revision tags: OPENBSD_5_2_BASE
# 1.14 22-Mar-2012 matthew

Make DIR a private type within libc, give it the same underlying
typedef regardless of __BSD_VISIBLE, and eliminate the dirfd() macro.

ok guenther@


# 1.13 22-Mar-2012 guenther

Update alphasort() and scandir()'s argument types to match POSIX:
use "const struct dirent **" instead of "const void *". Also, add
__restrict to readdir_r().

ok matthew@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.12 02-Sep-2007 deraadt

use calloc() to avoid malloc(n * m) overflows; checked by djm canacar jsg


Revision tags: OPENBSD_4_2_BASE
# 1.11 26-Jun-2007 ray

It seems st_size is not always a good estimator for the number of
directory entries. ZFS, for instance, sets st_size to the number
of entries.

Use the same algorithm for the initial estimate but keep a minimum
to prevent a divide by zero. When the buffer is filled, instead
of re-using the same flawed algorithm, double the buffer size.

Also add check for integer overflow.

Bug reported by Ed Ravin, ZFS testing environment provided by Bryan
Allen.

OK millert


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.10 08-Aug-2005 espie

zap remaining rcsid.

Kill old files that are no longer compiled.

okay theo


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.9 18-May-2004 jfb

ansify function definitions and zap some `register'

ok millert@


Revision tags: OPENBSD_3_5_BASE
# 1.8 05-Mar-2004 tedu

don't leak memory. free and netbsd via Patrick Latifi


Revision tags: OPENBSD_3_4_BASE
# 1.7 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE
# 1.6 30-Jul-2002 millert

malloc paranoia; it is unlikely that any filesystem will support
enough directory entries to cause a problem but it is good form anyway.
deraadt@ OK.


Revision tags: OPENBSD_3_1_BASE
# 1.5 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE OPENBSD_3_0_BASE
# 1.4 14-Aug-1998 deraadt

realloc repair


Revision tags: OPENBSD_2_2_BASE OPENBSD_2_3_BASE
# 1.3 24-Jul-1997 deraadt

copy d_type; giles@nemeton.com.au


Revision tags: OPENBSD_2_0_BASE OPENBSD_2_1_BASE
# 1.2 19-Aug-1996 tholo

Fix RCS ids
Make sure everything uses {SYS,}LIBC_SCCS properly


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.22 14-Apr-2024 florian

Zap trailing whitespace.

OK tb


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE OPENBSD_7_1_BASE OPENBSD_7_2_BASE OPENBSD_7_3_BASE OPENBSD_7_4_BASE OPENBSD_7_5_BASE
# 1.21 28-Jun-2019 deraadt

When system calls indicate an error they return -1, not some arbitrary
value < 0. errno is only updated in this case. Change all (most?)
callers of syscalls to follow this better, and let's see if this strictness
helps us in the future.


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.20 20-Aug-2015 deraadt

All these files include <stdlib.h>, so do not need to cast
malloc/calloc/realloc* returns.


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.19 05-Feb-2015 millert

Include stdint.h, not limits.h to get SIZE_MAX. OK guenther@


# 1.18 16-Jan-2015 deraadt

Move to the <limits.h> universe.
review by millert, binary checking process with doug, concept with guenther


# 1.17 08-Oct-2014 deraadt

obvious reallocarray()


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.16 17-Apr-2013 tedu

add some prototypes, casts, includes, parenthesis, and whatnot to
silence some warnings.


Revision tags: OPENBSD_5_3_BASE
# 1.15 29-Nov-2012 guenther

Change scandir()'s 'select' argument from
int (*)(struct dirent *)
to
int (*)(const struct dirent *)
to match POSIX.

ok millert@, ports check by naddy@


Revision tags: OPENBSD_5_2_BASE
# 1.14 22-Mar-2012 matthew

Make DIR a private type within libc, give it the same underlying
typedef regardless of __BSD_VISIBLE, and eliminate the dirfd() macro.

ok guenther@


# 1.13 22-Mar-2012 guenther

Update alphasort() and scandir()'s argument types to match POSIX:
use "const struct dirent **" instead of "const void *". Also, add
__restrict to readdir_r().

ok matthew@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.12 02-Sep-2007 deraadt

use calloc() to avoid malloc(n * m) overflows; checked by djm canacar jsg


Revision tags: OPENBSD_4_2_BASE
# 1.11 26-Jun-2007 ray

It seems st_size is not always a good estimator for the number of
directory entries. ZFS, for instance, sets st_size to the number
of entries.

Use the same algorithm for the initial estimate but keep a minimum
to prevent a divide by zero. When the buffer is filled, instead
of re-using the same flawed algorithm, double the buffer size.

Also add check for integer overflow.

Bug reported by Ed Ravin, ZFS testing environment provided by Bryan
Allen.

OK millert


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.10 08-Aug-2005 espie

zap remaining rcsid.

Kill old files that are no longer compiled.

okay theo


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.9 18-May-2004 jfb

ansify function definitions and zap some `register'

ok millert@


Revision tags: OPENBSD_3_5_BASE
# 1.8 05-Mar-2004 tedu

don't leak memory. free and netbsd via Patrick Latifi


Revision tags: OPENBSD_3_4_BASE
# 1.7 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE
# 1.6 30-Jul-2002 millert

malloc paranoia; it is unlikely that any filesystem will support
enough directory entries to cause a problem but it is good form anyway.
deraadt@ OK.


Revision tags: OPENBSD_3_1_BASE
# 1.5 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE OPENBSD_3_0_BASE
# 1.4 14-Aug-1998 deraadt

realloc repair


Revision tags: OPENBSD_2_2_BASE OPENBSD_2_3_BASE
# 1.3 24-Jul-1997 deraadt

copy d_type; giles@nemeton.com.au


Revision tags: OPENBSD_2_0_BASE OPENBSD_2_1_BASE
# 1.2 19-Aug-1996 tholo

Fix RCS ids
Make sure everything uses {SYS,}LIBC_SCCS properly


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.21 28-Jun-2019 deraadt

When system calls indicate an error they return -1, not some arbitrary
value < 0. errno is only updated in this case. Change all (most?)
callers of syscalls to follow this better, and let's see if this strictness
helps us in the future.


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.20 20-Aug-2015 deraadt

All these files include <stdlib.h>, so do not need to cast
malloc/calloc/realloc* returns.


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.19 05-Feb-2015 millert

Include stdint.h, not limits.h to get SIZE_MAX. OK guenther@


# 1.18 16-Jan-2015 deraadt

Move to the <limits.h> universe.
review by millert, binary checking process with doug, concept with guenther


# 1.17 08-Oct-2014 deraadt

obvious reallocarray()


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.16 17-Apr-2013 tedu

add some prototypes, casts, includes, parenthesis, and whatnot to
silence some warnings.


Revision tags: OPENBSD_5_3_BASE
# 1.15 29-Nov-2012 guenther

Change scandir()'s 'select' argument from
int (*)(struct dirent *)
to
int (*)(const struct dirent *)
to match POSIX.

ok millert@, ports check by naddy@


Revision tags: OPENBSD_5_2_BASE
# 1.14 22-Mar-2012 matthew

Make DIR a private type within libc, give it the same underlying
typedef regardless of __BSD_VISIBLE, and eliminate the dirfd() macro.

ok guenther@


# 1.13 22-Mar-2012 guenther

Update alphasort() and scandir()'s argument types to match POSIX:
use "const struct dirent **" instead of "const void *". Also, add
__restrict to readdir_r().

ok matthew@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.12 02-Sep-2007 deraadt

use calloc() to avoid malloc(n * m) overflows; checked by djm canacar jsg


Revision tags: OPENBSD_4_2_BASE
# 1.11 26-Jun-2007 ray

It seems st_size is not always a good estimator for the number of
directory entries. ZFS, for instance, sets st_size to the number
of entries.

Use the same algorithm for the initial estimate but keep a minimum
to prevent a divide by zero. When the buffer is filled, instead
of re-using the same flawed algorithm, double the buffer size.

Also add check for integer overflow.

Bug reported by Ed Ravin, ZFS testing environment provided by Bryan
Allen.

OK millert


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.10 08-Aug-2005 espie

zap remaining rcsid.

Kill old files that are no longer compiled.

okay theo


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.9 18-May-2004 jfb

ansify function definitions and zap some `register'

ok millert@


Revision tags: OPENBSD_3_5_BASE
# 1.8 05-Mar-2004 tedu

don't leak memory. free and netbsd via Patrick Latifi


Revision tags: OPENBSD_3_4_BASE
# 1.7 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE
# 1.6 30-Jul-2002 millert

malloc paranoia; it is unlikely that any filesystem will support
enough directory entries to cause a problem but it is good form anyway.
deraadt@ OK.


Revision tags: OPENBSD_3_1_BASE
# 1.5 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE OPENBSD_3_0_BASE
# 1.4 14-Aug-1998 deraadt

realloc repair


Revision tags: OPENBSD_2_2_BASE OPENBSD_2_3_BASE
# 1.3 24-Jul-1997 deraadt

copy d_type; giles@nemeton.com.au


Revision tags: OPENBSD_2_0_BASE OPENBSD_2_1_BASE
# 1.2 19-Aug-1996 tholo

Fix RCS ids
Make sure everything uses {SYS,}LIBC_SCCS properly


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.20 20-Aug-2015 deraadt

All these files include <stdlib.h>, so do not need to cast
malloc/calloc/realloc* returns.


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.19 05-Feb-2015 millert

Include stdint.h, not limits.h to get SIZE_MAX. OK guenther@


# 1.18 16-Jan-2015 deraadt

Move to the <limits.h> universe.
review by millert, binary checking process with doug, concept with guenther


# 1.17 08-Oct-2014 deraadt

obvious reallocarray()


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.16 17-Apr-2013 tedu

add some prototypes, casts, includes, parenthesis, and whatnot to
silence some warnings.


Revision tags: OPENBSD_5_3_BASE
# 1.15 29-Nov-2012 guenther

Change scandir()'s 'select' argument from
int (*)(struct dirent *)
to
int (*)(const struct dirent *)
to match POSIX.

ok millert@, ports check by naddy@


Revision tags: OPENBSD_5_2_BASE
# 1.14 22-Mar-2012 matthew

Make DIR a private type within libc, give it the same underlying
typedef regardless of __BSD_VISIBLE, and eliminate the dirfd() macro.

ok guenther@


# 1.13 22-Mar-2012 guenther

Update alphasort() and scandir()'s argument types to match POSIX:
use "const struct dirent **" instead of "const void *". Also, add
__restrict to readdir_r().

ok matthew@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.12 02-Sep-2007 deraadt

use calloc() to avoid malloc(n * m) overflows; checked by djm canacar jsg


Revision tags: OPENBSD_4_2_BASE
# 1.11 26-Jun-2007 ray

It seems st_size is not always a good estimator for the number of
directory entries. ZFS, for instance, sets st_size to the number
of entries.

Use the same algorithm for the initial estimate but keep a minimum
to prevent a divide by zero. When the buffer is filled, instead
of re-using the same flawed algorithm, double the buffer size.

Also add check for integer overflow.

Bug reported by Ed Ravin, ZFS testing environment provided by Bryan
Allen.

OK millert


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.10 08-Aug-2005 espie

zap remaining rcsid.

Kill old files that are no longer compiled.

okay theo


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.9 18-May-2004 jfb

ansify function definitions and zap some `register'

ok millert@


Revision tags: OPENBSD_3_5_BASE
# 1.8 05-Mar-2004 tedu

don't leak memory. free and netbsd via Patrick Latifi


Revision tags: OPENBSD_3_4_BASE
# 1.7 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE
# 1.6 30-Jul-2002 millert

malloc paranoia; it is unlikely that any filesystem will support
enough directory entries to cause a problem but it is good form anyway.
deraadt@ OK.


Revision tags: OPENBSD_3_1_BASE
# 1.5 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE OPENBSD_3_0_BASE
# 1.4 14-Aug-1998 deraadt

realloc repair


Revision tags: OPENBSD_2_2_BASE OPENBSD_2_3_BASE
# 1.3 24-Jul-1997 deraadt

copy d_type; giles@nemeton.com.au


Revision tags: OPENBSD_2_0_BASE OPENBSD_2_1_BASE
# 1.2 19-Aug-1996 tholo

Fix RCS ids
Make sure everything uses {SYS,}LIBC_SCCS properly


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision