Skip to content

Commit

Permalink
zos: fix compile errors and garbage in output (#91)
Browse files Browse the repository at this point in the history
* fix RuntimeTools/appmetrics#585

* fix #84

* Update AUTHORS.md
  • Loading branch information
gabylb authored and mattcolegate committed Aug 21, 2019
1 parent 24c99a4 commit 182b635
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ Authors ordered by first contribution:
- Richard Lau (https://github.com/richardlau)
- Gibson Fahnestock (https://github.com/gibfahn)
- Abdirahim Musse (https://github.com/ab-m)

- Gaby Baghdadi (https://github.com/gabylb)
2 changes: 1 addition & 1 deletion binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
}],
['OS in "os390 zos"', {
"defines": [ "_ZOS", "_UNIX03_THREADS" ],
'cflags_cc': ['-Wc,EXPORTALL', '-qnoconvlit'],
'cflags_cc': ['-Wc,EXPORTALL', '-qascii'],
'cflags!': [ '-fno-omit-frame-pointer' ],
}],
['OS=="linux"', {
Expand Down
8 changes: 8 additions & 0 deletions src/ibmras/common/LogManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
#define VPRINT vsprintf
#endif

#ifdef _ZOS
extern "C" int dprintf(int fd, const char *fmt, ...);
#endif

extern "C" {

DECL void* ibmras_common_LogManager_getLogger(const char* name) {
Expand Down Expand Up @@ -56,8 +60,12 @@ void LogManager::processMsg(const std::string &msg) {
if (localLogFunc) {
localLogFunc(msg);
} else {
#ifdef _ZOS
dprintf(2,"%s\n",msg.c_str());
#else
std::cerr << msg << '\n';
std::cerr.flush();
#endif
}
return;
}
Expand Down
17 changes: 12 additions & 5 deletions src/ibmras/common/util/strUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,12 @@ std::string expectedNativeCodepage() {
}


void convertCodePage(char * str, const char* toCodePage, const char * fromCodePage) {
int convertCodePage(char * str, const char* toCodePage, const char * fromCodePage) {
// return 0: no change, 1: changed, -1: error
std::string codepage = expectedNativeCodepage();
if (codepage.compare("IBM-1047") == 0) {
//already in that codepage - return
return;
return 0;
}
char *cp = (char*)ibmras::common::memory::allocate(strlen(str) + 1);
strcpy(cp,str);
Expand All @@ -117,15 +118,19 @@ void convertCodePage(char * str, const char* toCodePage, const char * fromCodePa

if ((cd = iconv_open(toCodePage, fromCodePage)) == (iconv_t)(-1)) {
fprintf(stderr, "Cannot open converter to %s from %s\n", toCodePage, fromCodePage);
return;
return -1;
}

rc = iconv(cd, &inptr, &inleft, &outptr, &outleft);
if (rc == -1) {
fprintf(stderr, "Error in converting characters\n");
}
else {
rc = 1;
}
iconv_close(cd);
ibmras::common::memory::deallocate((unsigned char**)&cp);
return rc;
}
#endif

Expand All @@ -135,9 +140,11 @@ void native2Ascii(char * str, bool convertToCurrentLocale) {
if ( NULL != str )
{
if (convertToCurrentLocale) {
convertCodePage(str, expectedNativeCodepage().c_str(), "IBM-1047");
int rc = convertCodePage(str, expectedNativeCodepage().c_str(), "IBM-1047");
if (rc==1) {
__etoa(str);
}
}
__etoa(str);
}
#endif
}
Expand Down

0 comments on commit 182b635

Please sign in to comment.