git: 641e8e39560d - main - Revert "libc: Constify the getcap API"
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 05 Jun 2026 17:17:49 UTC
The branch main has been updated by des:
URL: https://cgit.FreeBSD.org/src/commit/?id=641e8e39560d2acd2a52658af422bfd30aabb2bd
commit 641e8e39560d2acd2a52658af422bfd30aabb2bd
Author: Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-06-05 17:15:46 +0000
Commit: Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-06-05 17:15:46 +0000
Revert "libc: Constify the getcap API"
This broke cross-building on Linux and macOS.
This reverts commit 823d00b2d447247f1c5860e3bbc61f6fd19a70e5.
---
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, 34 insertions(+), 31 deletions(-)
diff --git a/contrib/ncurses/include/ncurses_defs b/contrib/ncurses/include/ncurses_defs
index a706582c1910..8058fb25bd09 100644
--- a/contrib/ncurses/include/ncurses_defs
+++ b/contrib/ncurses/include/ncurses_defs
@@ -34,7 +34,7 @@
BROKEN_LINKER
BSD_TPUTS
-CGETENT_CONST const
+CGETENT_CONST /* nothing */
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 98122cd7e7ac..3be745e96c0b 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 const char * const dba[] = { "/etc/gettytab", NULL };
+static char gettytab[] = "/etc/gettytab";
/*ARGSUSED*/
int
getent(char *cp __unused, const char *name)
{
int retval;
- char *tempnam;
+ char *tempnam, *dba[2] = { gettytab, NULL };
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 5f705b9f7f42..305aea4b8672 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 **, const char * const *, const char *);
-int cgetfirst(char **, const char * const *);
+int cgetent(char **, char **, const char *);
+int cgetfirst(char **, char **);
int cgetmatch(const char *, const char *);
-int cgetnext(char **, const char * const *);
+int cgetnext(char **, char **);
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 9a43b004c6aa..4b3730920529 100644
--- a/lib/libc/gen/disklabel.c
+++ b/lib/libc/gen/disklabel.c
@@ -54,8 +54,6 @@ gettype(char *t, const char **names)
return (0);
}
-static const char *db_array[] = { _PATH_DISKTAB, NULL };
-
struct disklabel *
getdiskbyname(const char *name)
{
@@ -63,12 +61,13 @@ 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, name) < 0)
+ if (cgetent(&buf, db_array, (char *) name) < 0)
return NULL;
bzero((char *)&disk, sizeof(disk));
diff --git a/lib/libc/gen/getcap.3 b/lib/libc/gen/getcap.3
index 772becb650f5..00c7edd8026f 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 May 26, 2026
+.Dd March 22, 2002
.Dt GETCAP 3
.Os
.Sh NAME
@@ -48,7 +48,7 @@
.Sh SYNOPSIS
.In stdlib.h
.Ft int
-.Fn cgetent "char **buf" "const char * const *db_array" "const char *name"
+.Fn cgetent "char **buf" "char **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" "const char * const *db_array"
+.Fn cgetfirst "char **buf" "char **db_array"
.Ft int
-.Fn cgetnext "char **buf" "const char * const *db_array"
+.Fn cgetnext "char **buf" "char **db_array"
.Ft int
.Fn cgetclose "void"
.Sh DESCRIPTION
diff --git a/lib/libc/gen/getcap.c b/lib/libc/gen/getcap.c
index 7544e7343f45..cfb81ed0d065 100644
--- a/lib/libc/gen/getcap.c
+++ b/lib/libc/gen/getcap.c
@@ -62,8 +62,7 @@ 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 *, const char * const *, int,
- const char *, int, char *);
+static int getent(char **, u_int *, char **, int, const char *, int, char *);
static int nfcmp(char *, char *);
/*
@@ -155,7 +154,7 @@ cgetcap(char *buf, const char *cap, int type)
* reference loop is detected.
*/
int
-cgetent(char **buf, const char * const *db_array, const char *name)
+cgetent(char **buf, char **db_array, const char *name)
{
u_int dummy;
@@ -181,12 +180,11 @@ cgetent(char **buf, const char * const *db_array, const char *name)
* MAX_RECURSION.
*/
static int
-getent(char **cap, u_int *len, const char * const *db_array, int fd,
- const char *name, int depth, char *nfield)
+getent(char **cap, u_int *len, char **db_array, int fd, const char *name,
+ int depth, char *nfield)
{
DB *capdbp;
- const char * const *db_p;
- char *r_end, *rp;
+ char *r_end, *rp, **db_p;
int myfd, eof, foundit, retval;
char *record, *cbuf;
int tc_not_resolved;
@@ -613,7 +611,7 @@ cgetmatch(const char *buf, const char *name)
int
-cgetfirst(char **buf, const char * const *db_array)
+cgetfirst(char **buf, char **db_array)
{
(void)cgetclose();
return (cgetnext(buf, db_array));
@@ -621,7 +619,7 @@ cgetfirst(char **buf, const char * const *db_array)
static FILE *pfp;
static int slash;
-static const char * const *dbp;
+static char **dbp;
int
cgetclose(void)
@@ -642,7 +640,7 @@ cgetclose(void)
* upon returning an entry with more remaining, and -1 if an error occurs.
*/
int
-cgetnext(char **bp, const char * const *db_array)
+cgetnext(char **bp, char **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 1894b8e8cd83..0d7becacbfc7 100644
--- a/lib/libutil/login_cap.c
+++ b/lib/libutil/login_cap.c
@@ -299,7 +299,8 @@ login_getclassbyname(char const *name, const struct passwd *pwd)
const char *msg = NULL;
const char *dir;
char userpath[MAXPATHLEN];
- const char *login_dbarray[] = { NULL, NULL, NULL };
+
+ static 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 15eaf2ee2a58..05186f593bf4 100644
--- a/libexec/getty/subr.c
+++ b/libexec/getty/subr.c
@@ -54,7 +54,6 @@
void
gettable(const char *name)
{
- static const char *dba[2] = { _PATH_GETTYTAB, NULL };
char *buf = NULL;
struct gettystrs *sp;
struct gettynums *np;
@@ -62,9 +61,15 @@ 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 ea14bad474b5..019dad1ee72e 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(const char * const *);
+static void db_build(char **);
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((const char * const *)argv);
+ db_build(argv);
if (capdbp->close(capdbp) < 0)
err(1, "%s", capname);
@@ -142,7 +142,7 @@ dounlink(void)
* details above.
*/
static void
-db_build(const char * const *ifiles)
+db_build(char **ifiles)
{
DBT key, data;
recno_t reccnt;
diff --git a/usr.bin/tip/tip/remote.c b/usr.bin/tip/tip/remote.c
index 01b1d59230dc..00ce25f52b5c 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 const char *db_array[] = { _PATH_REMOTE, NULL, NULL };
+static char *db_array[3] = { _PATH_REMOTE, 0, 0 };
#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 2b9cb67b6df4..35fcab4c16eb 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 const char *printcapdb[] = { _PATH_PRINTCAP, NULL };
+static char *printcapdb[] = { __DECONST(char *, _PATH_PRINTCAP), NULL };
static char *capdb_canonical_name(const char *_bp);
static int capdb_getaltlog(char *_bp, const char *_shrt,