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
@@ -70,7 +70,7 @@
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <nl_types.h>
|
||||
#include <Dt/MsgCatP.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "EUSDebug.hh"
|
||||
@@ -98,34 +98,6 @@ Application::_appResources[] = {
|
||||
#define NL_CAT_LOCALE 0
|
||||
#endif
|
||||
|
||||
#ifdef hpV4
|
||||
/*
|
||||
* Wrapper around catgets -- this makes sure the message string is saved
|
||||
* in a safe location; so repeated calls to catgets() do not overwrite
|
||||
* the catgets() internal buffer. This has been a problem on HP systems.
|
||||
*/
|
||||
char *catgets_cache2(nl_catd catd, int set, int num, char *dflt)
|
||||
{
|
||||
|
||||
#define MSGS_PER_SET_MAX 12
|
||||
#define NUM_SETS_MAX 2
|
||||
|
||||
/* array to hold messages from catalog */
|
||||
static char *MsgCat[NUM_SETS_MAX][MSGS_PER_SET_MAX];
|
||||
|
||||
/* convert to a zero based index */
|
||||
int setIdx = set - 1;
|
||||
int numIdx = num - 1;
|
||||
|
||||
if ( ! MsgCat[setIdx][numIdx] ) {
|
||||
MsgCat[setIdx][numIdx] = strdup( catgets(catd, set, num, dflt));
|
||||
}
|
||||
|
||||
return MsgCat[setIdx][numIdx];
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Application *theApplication = NULL;
|
||||
|
||||
nl_catd catd = (nl_catd) -1; // catgets file descriptor
|
||||
@@ -261,7 +233,7 @@ Application::~Application()
|
||||
#endif
|
||||
#endif
|
||||
|
||||
catclose(catd);
|
||||
CATCLOSE(catd);
|
||||
|
||||
// In an MT environment, calling exit() causes threads to
|
||||
// hang and a deadlock results.
|
||||
@@ -387,7 +359,7 @@ void
|
||||
Application::open_catalog()
|
||||
{
|
||||
// open message catalog file
|
||||
catd = catopen("MotifApp", NL_CAT_LOCALE);
|
||||
catd = CATOPEN("MotifApp", NL_CAT_LOCALE);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user