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:
committed by
Jon Trulson
parent
8278e0eae3
commit
7010b2c11b
@@ -1,10 +1,13 @@
|
||||
XCOMM $XConsortium: Imakefile /main/5 1996/09/30 14:12:43 drk $
|
||||
|
||||
SRCS = merge.c mkcatdefs.c
|
||||
DEFINES = -DNO_XLIB
|
||||
|
||||
SRCS = merge.c mkcatdefs.c MsgCat.c
|
||||
|
||||
all:: merge mkcatdefs
|
||||
|
||||
NormalProgramTarget(merge,merge.o,,,)
|
||||
NormalProgramTarget(merge,merge.o MsgCat.o,,,)
|
||||
NormalProgramTarget(mkcatdefs,mkcatdefs.o,,,)
|
||||
|
||||
DependTarget()
|
||||
LinkSourceFile(MsgCat.c,$(DTSVCSRC)/DtUtil2)
|
||||
|
||||
@@ -95,9 +95,10 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <locale.h>
|
||||
#include <nl_types.h>
|
||||
#include <Dt/MsgCatP.h>
|
||||
|
||||
nl_catd catfile[2] = {NULL, NULL}; /* [0] for primary, [1] for default */
|
||||
/* [0] for primary, [1] for default */
|
||||
nl_catd catfile[2] = {(nl_catd) -1, (nl_catd) -1};
|
||||
char *big_buff;
|
||||
char *lang = NULL;
|
||||
char envvar[100];
|
||||
@@ -164,11 +165,8 @@ void main (int argc, char *argv [])
|
||||
c = get_char ();
|
||||
}
|
||||
|
||||
if ( catfile[0] )
|
||||
catclose(catfile[0]);
|
||||
|
||||
if ( catfile[1] )
|
||||
catclose(catfile[1]);
|
||||
CATCLOSE(catfile[0]);
|
||||
CATCLOSE(catfile[1]);
|
||||
|
||||
unlink("./.dt_pfile.cat");
|
||||
unlink("./.dt_dfile.cat");
|
||||
@@ -247,7 +245,7 @@ void cat_open (void)
|
||||
}
|
||||
}
|
||||
|
||||
catfile[0] = catopen("./.dt_pfile.cat",0);
|
||||
catfile[0] = CATOPEN("./.dt_pfile.cat",0);
|
||||
|
||||
if(dfile != NULL)
|
||||
{
|
||||
@@ -259,10 +257,10 @@ void cat_open (void)
|
||||
|
||||
}
|
||||
|
||||
catfile[1] = catopen("./.dt_dfile.cat",0);
|
||||
catfile[1] = CATOPEN("./.dt_dfile.cat",0);
|
||||
|
||||
/* if all fails */
|
||||
if(catfile[0] == NULL && catfile[1] == NULL)
|
||||
if((catfile[0] == (nl_catd) -1) && (catfile[1] == (nl_catd) -1))
|
||||
fatal("Can't open message files.\n", 0, 9);
|
||||
|
||||
}
|
||||
@@ -276,9 +274,9 @@ int find_message (int msg)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if(catfile[0] != NULL)
|
||||
if(catfile[0] != (nl_catd) -1)
|
||||
ret = find_msg_in_file(msg, 0);
|
||||
if(ret == 0 && catfile[1] != NULL)
|
||||
if(ret == 0 && catfile[1] != (nl_catd) -1)
|
||||
ret = find_msg_in_file(msg, 1);
|
||||
return ret;
|
||||
}
|
||||
@@ -293,7 +291,7 @@ int find_message (int msg)
|
||||
*/
|
||||
int find_msg_in_file (int msg, int file)
|
||||
{
|
||||
big_buff = catgets(catfile[file],1,msg,"MSG_NOT_FOUND");
|
||||
big_buff = CATGETS(catfile[file],1,msg,"MSG_NOT_FOUND");
|
||||
if ( strcmp(big_buff,"MSG_NOT_FOUND") )
|
||||
return(1);
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user