The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=823d00b2d447247f1c5860e3bbc61f6fd19a70e5
commit 823d00b2d447247f1c5860e3bbc61f6fd19a70e5 Author: Dag-Erling Smørgrav <[email protected]> AuthorDate: 2026-06-04 22:41:22 +0000 Commit: Dag-Erling Smørgrav <[email protected]> CommitDate: 2026-06-04 22:41:22 +0000 libc: Constify the getcap API MFC after: 1 week Inspired by: NetBSD Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D57252 --- contrib/ncurses/include/ncurses_defs | 2 +- contrib/telnet/libtelnet/getent.c | 6 +++--- include/stdlib.h | 6 +++--- lib/libc/gen/disklabel.c | 5 +++-- lib/libc/gen/getcap.3 | 8 ++++---- lib/libc/gen/getcap.c | 18 ++++++++++-------- lib/libutil/login_cap.c | 3 +-- libexec/getty/subr.c | 7 +------ usr.bin/cap_mkdb/cap_mkdb.c | 6 +++--- usr.bin/tip/tip/remote.c | 2 +- usr.sbin/lpr/common_source/printcap.c | 2 +- 11 files changed, 31 insertions(+), 34 deletions(-) diff --git a/contrib/ncurses/include/ncurses_defs b/contrib/ncurses/include/ncurses_defs index 8058fb25bd09..a706582c1910 100644 --- a/contrib/ncurses/include/ncurses_defs +++ b/contrib/ncurses/include/ncurses_defs @@ -34,7 +34,7 @@ BROKEN_LINKER BSD_TPUTS -CGETENT_CONST /* nothing */ +CGETENT_CONST const CPP_HAS_PARAM_INIT CURSES_ACS_ARRAY acs_map CURSES_WACS_ARRAY _nc_wacs diff --git a/contrib/telnet/libtelnet/getent.c b/contrib/telnet/libtelnet/getent.c index 3be745e96c0b..98122cd7e7ac 100644 --- a/contrib/telnet/libtelnet/getent.c +++ b/contrib/telnet/libtelnet/getent.c @@ -39,17 +39,17 @@ static char sccsid[] = "@(#)getent.c 8.2 (Berkeley) 12/15/93"; #include "misc-proto.h" static char *area; -static char gettytab[] = "/etc/gettytab"; +static const char * const dba[] = { "/etc/gettytab", NULL }; /*ARGSUSED*/ int getent(char *cp __unused, const char *name) { int retval; - char *tempnam, *dba[2] = { gettytab, NULL }; + char *tempnam; tempnam = strdup(name); - retval = cgetent(&area, dba, tempnam) == 0 ? 1 : 0; + retval = cgetent(&area, dba, tempnam) == 0 ? 1 : 0; free(tempnam); return(retval); } diff --git a/include/stdlib.h b/include/stdlib.h index 305aea4b8672..5f705b9f7f42 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -279,10 +279,10 @@ char *getbsize(int *, long *); /* getcap(3) functions */ char *cgetcap(char *, const char *, int); int cgetclose(void); -int cgetent(char **, char **, const char *); -int cgetfirst(char **, char **); +int cgetent(char **, const char * const *, const char *); +int cgetfirst(char **, const char * const *); int cgetmatch(const char *, const char *); -int cgetnext(char **, char **); +int cgetnext(char **, const char * const *); int cgetnum(char *, const char *, long *); int cgetset(const char *); int cgetstr(char *, const char *, char **); diff --git a/lib/libc/gen/disklabel.c b/lib/libc/gen/disklabel.c index 4b3730920529..9a43b004c6aa 100644 --- a/lib/libc/gen/disklabel.c +++ b/lib/libc/gen/disklabel.c @@ -54,6 +54,8 @@ gettype(char *t, const char **names) return (0); } +static const char *db_array[] = { _PATH_DISKTAB, NULL }; + struct disklabel * getdiskbyname(const char *name) { @@ -61,13 +63,12 @@ getdiskbyname(const char *name) struct disklabel *dp = &disk; struct partition *pp; char *buf; - char *db_array[2] = { _PATH_DISKTAB, 0 }; char *cp, *cq; /* can't be register */ char p, max, psize[3], pbsize[3], pfsize[3], poffset[3], ptype[3]; u_int32_t *dx; - if (cgetent(&buf, db_array, (char *) name) < 0) + if (cgetent(&buf, db_array, name) < 0) return NULL; bzero((char *)&disk, sizeof(disk)); diff --git a/lib/libc/gen/getcap.3 b/lib/libc/gen/getcap.3 index 00c7edd8026f..772becb650f5 100644 --- a/lib/libc/gen/getcap.3 +++ b/lib/libc/gen/getcap.3 @@ -28,7 +28,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd March 22, 2002 +.Dd May 26, 2026 .Dt GETCAP 3 .Os .Sh NAME @@ -48,7 +48,7 @@ .Sh SYNOPSIS .In stdlib.h .Ft int -.Fn cgetent "char **buf" "char **db_array" "const char *name" +.Fn cgetent "char **buf" "const char * const *db_array" "const char *name" .Ft int .Fn cgetset "const char *ent" .Ft int @@ -62,9 +62,9 @@ .Ft int .Fn cgetustr "char *buf" "const char *cap" "char **str" .Ft int -.Fn cgetfirst "char **buf" "char **db_array" +.Fn cgetfirst "char **buf" "const char * const *db_array" .Ft int -.Fn cgetnext "char **buf" "char **db_array" +.Fn cgetnext "char **buf" "const char * const *db_array" .Ft int .Fn cgetclose "void" .Sh DESCRIPTION diff --git a/lib/libc/gen/getcap.c b/lib/libc/gen/getcap.c index cfb81ed0d065..7544e7343f45 100644 --- a/lib/libc/gen/getcap.c +++ b/lib/libc/gen/getcap.c @@ -62,7 +62,8 @@ static char *toprec; /* Additional record specified by cgetset() */ static int gottoprec; /* Flag indicating retrieval of toprecord */ static int cdbget(DB *, char **, const char *); -static int getent(char **, u_int *, char **, int, const char *, int, char *); +static int getent(char **, u_int *, const char * const *, int, + const char *, int, char *); static int nfcmp(char *, char *); /* @@ -154,7 +155,7 @@ cgetcap(char *buf, const char *cap, int type) * reference loop is detected. */ int -cgetent(char **buf, char **db_array, const char *name) +cgetent(char **buf, const char * const *db_array, const char *name) { u_int dummy; @@ -180,11 +181,12 @@ cgetent(char **buf, char **db_array, const char *name) * MAX_RECURSION. */ static int -getent(char **cap, u_int *len, char **db_array, int fd, const char *name, - int depth, char *nfield) +getent(char **cap, u_int *len, const char * const *db_array, int fd, + const char *name, int depth, char *nfield) { DB *capdbp; - char *r_end, *rp, **db_p; + const char * const *db_p; + char *r_end, *rp; int myfd, eof, foundit, retval; char *record, *cbuf; int tc_not_resolved; @@ -611,7 +613,7 @@ cgetmatch(const char *buf, const char *name) int -cgetfirst(char **buf, char **db_array) +cgetfirst(char **buf, const char * const *db_array) { (void)cgetclose(); return (cgetnext(buf, db_array)); @@ -619,7 +621,7 @@ cgetfirst(char **buf, char **db_array) static FILE *pfp; static int slash; -static char **dbp; +static const char * const *dbp; int cgetclose(void) @@ -640,7 +642,7 @@ cgetclose(void) * upon returning an entry with more remaining, and -1 if an error occurs. */ int -cgetnext(char **bp, char **db_array) +cgetnext(char **bp, const char * const *db_array) { size_t len; int done, hadreaderr, savederrno, status; diff --git a/lib/libutil/login_cap.c b/lib/libutil/login_cap.c index 0d7becacbfc7..1894b8e8cd83 100644 --- a/lib/libutil/login_cap.c +++ b/lib/libutil/login_cap.c @@ -299,8 +299,7 @@ login_getclassbyname(char const *name, const struct passwd *pwd) const char *msg = NULL; const char *dir; char userpath[MAXPATHLEN]; - - static char *login_dbarray[] = { NULL, NULL, NULL }; + const char *login_dbarray[] = { NULL, NULL, NULL }; me = (name != NULL && strcmp(name, LOGIN_MECLASS) == 0); dir = (!me || pwd == NULL) ? NULL : pwd->pw_dir; diff --git a/libexec/getty/subr.c b/libexec/getty/subr.c index 05186f593bf4..15eaf2ee2a58 100644 --- a/libexec/getty/subr.c +++ b/libexec/getty/subr.c @@ -54,6 +54,7 @@ void gettable(const char *name) { + static const char *dba[2] = { _PATH_GETTYTAB, NULL }; char *buf = NULL; struct gettystrs *sp; struct gettynums *np; @@ -61,15 +62,9 @@ gettable(const char *name) long n; int l; char *p; - static char path_gettytab[PATH_MAX]; - char *dba[2]; static int firsttime = 1; - strlcpy(path_gettytab, _PATH_GETTYTAB, sizeof(path_gettytab)); - dba[0] = path_gettytab; - dba[1] = NULL; - if (firsttime) { /* * we need to strdup() anything in the strings array diff --git a/usr.bin/cap_mkdb/cap_mkdb.c b/usr.bin/cap_mkdb/cap_mkdb.c index 019dad1ee72e..ea14bad474b5 100644 --- a/usr.bin/cap_mkdb/cap_mkdb.c +++ b/usr.bin/cap_mkdb/cap_mkdb.c @@ -40,7 +40,7 @@ #include <string.h> #include <unistd.h> -static void db_build(char **); +static void db_build(const char * const *); static void dounlink(void); static void usage(void); @@ -113,7 +113,7 @@ main(int argc, char *argv[]) if (atexit(dounlink)) err(1, "atexit"); - db_build(argv); + db_build((const char * const *)argv); if (capdbp->close(capdbp) < 0) err(1, "%s", capname); @@ -142,7 +142,7 @@ dounlink(void) * details above. */ static void -db_build(char **ifiles) +db_build(const char * const *ifiles) { DBT key, data; recno_t reccnt; diff --git a/usr.bin/tip/tip/remote.c b/usr.bin/tip/tip/remote.c index 00ce25f52b5c..01b1d59230dc 100644 --- a/usr.bin/tip/tip/remote.c +++ b/usr.bin/tip/tip/remote.c @@ -53,7 +53,7 @@ static char *capstrings[] = { "di", "es", "ex", "fo", "rc", "re", "pa", 0 }; -static char *db_array[3] = { _PATH_REMOTE, 0, 0 }; +static const char *db_array[] = { _PATH_REMOTE, NULL, NULL }; #define cgetflag(f) (cgetcap(bp, f, ':') != NULL) diff --git a/usr.sbin/lpr/common_source/printcap.c b/usr.sbin/lpr/common_source/printcap.c index 35fcab4c16eb..2b9cb67b6df4 100644 --- a/usr.sbin/lpr/common_source/printcap.c +++ b/usr.sbin/lpr/common_source/printcap.c @@ -54,7 +54,7 @@ /* * Routines and data used in processing the printcap file. */ -static char *printcapdb[] = { __DECONST(char *, _PATH_PRINTCAP), NULL }; +static const char *printcapdb[] = { _PATH_PRINTCAP, NULL }; static char *capdb_canonical_name(const char *_bp); static int capdb_getaltlog(char *_bp, const char *_shrt,
