Centralize catgets() calls through MsgCat

CDE has relied upon catgets() implementations following a relaxed
interpretation of the XPG internationalization standard that ignored
-1, the standard error value returned by catopen, as the catalog
argument. However, this same behavior causes segmentation faults with
the musl C library.

This patch:

- Centralizes (with the exception of ToolTalk) all calls to catopen(),
  catgets(), and catclose() through MsgCat within the DtSvc library.
- Prevents calls to catgets() and catclose() that rely upon
  undefined behavior.
- Eliminates a number of bespoke catgets() wrappers, including multiple
  redundant caching implementations designed to work around a design
  peculiarity in HP/UX.
- Eases building CDE without XPG internationalization support by providing
  the appropriate macros.
This commit is contained in:
Lev Kujawski
2021-01-30 20:05:13 -07:00
committed by Jon Trulson
parent 8278e0eae3
commit 7010b2c11b
241 changed files with 3153 additions and 3493 deletions

View File

@@ -17,9 +17,10 @@ SYS_LIBRARIES = -lm -ldl -lgen
SRCS1 = dthello.c
SRCS = $(SRCS1)
OBJS = dthello.o \
$(CDELIBSRC)/DtSvc/DtUtil2/EnvControl.o \
$(CDELIBSRC)/DtSvc/DtUtil2/DtNlUtils.o \
$(CDELIBSRC)/DtSvc/DtUtil2/GetDispRes.o
$(CDELIBSRC)/DtSvc/DtUtil2/EnvControl.o \
$(CDELIBSRC)/DtSvc/DtUtil2/GetDispRes.o \
$(CDELIBSRC)/DtSvc/DtUtil2/MsgCat.o
ComplexProgramTarget(dthello)

View File

@@ -76,7 +76,7 @@
#include <limits.h>
#include <locale.h>
#ifndef NO_MESSAGE_CATALOG
# include <nl_types.h>
# include <Dt/MsgCatP.h>
#endif
#include <Dt/EnvControlP.h>
@@ -1147,30 +1147,15 @@ GetMessage(
int n,
char *s )
{
char *msg;
char *lang;
nl_catd catopen();
char *catgets();
static int first = 1;
static nl_catd nlmsg_fd;
if ( first )
static nl_catd nlmsg_fd = (nl_catd) -1;
if ( first )
{
first = 0;
lang = (char *) getenv ("LANG");
if (!lang || !(strcmp (lang, "C")))
/*
* If LANG is not set or if LANG=C, then there
* is no need to open the message catalog - just
* return the built-in string "s".
*/
nlmsg_fd = (nl_catd)-1;
else
nlmsg_fd = catopen("dthello", NL_CAT_LOCALE);
nlmsg_fd = CATOPEN("dthello", NL_CAT_LOCALE);
}
msg=catgets(nlmsg_fd,set,n,s);
return (msg);
return CATGETS(nlmsg_fd, set, n, s);
}
#endif