Пример #1
0
/* On all platforms operate on UTF-8 encoding */
int
#if defined(WIN32)
translated_main(int argc, char **argv, char **envp)
#else /* defined(WIN32) */
main(int argc, char **argv, char **envp)
#endif /* defined(WIN32) */
{
	RCType rc = RC_OK;
#if defined(J9ZOS390)
	/* Convert EBCDIC to UTF-8 (ASCII) */
	if (-1 != iconv_init()) {
		/* translate argv strings to ascii */
		for (int i = 0; i < argc; i++) {
			argv[i] = e2a_string(argv[i]);
			if (NULL == argv[i]) {
				eprintf("failed to convert argument #%d from EBCDIC to ASCII", i);
				rc = RC_FAILED;
				break;
			}
		}
	} else {
		eprintf("failed to initialize iconv");
		rc = RC_FAILED;
	}
#endif /* defined(J9ZOS390) */
	if (RC_OK == rc) {
		rc = startTraceGen(argc, argv);
	}
	return (RC_OK == rc) ? 0 : -1;
}
Пример #2
0
char *
omrfile_read_text(struct OMRPortLibrary *portLibrary, intptr_t fd, char *buf, intptr_t nbytes)
{
#if (defined(J9ZOS390))
	const char eol = a2e_tab['\n'];
	char *tempStr = NULL;
#else
	const static char eol = '\n';
#endif /* defined(J9ZOS390) */
	char temp[64];
	char *cursor = buf;
	BOOLEAN foundEOL = FALSE;

	if (nbytes <= 0) {
		return NULL;
	}

	/* discount 1 for the trailing NUL */
	nbytes -= 1;

	while ((!foundEOL) && (nbytes > 0)) {
		intptr_t i = 0;
		intptr_t count = sizeof(temp) > nbytes ? nbytes : sizeof(temp);
		count = portLibrary->file_read(portLibrary, fd, temp, count);

		/* ignore translation for now, except on z/OS */
		if (count < 0) {
			if (cursor == buf) {
				return NULL;
			} else {
				break;
			}
		}

		for (i = 0; i < count; i++) {
			char c = temp[i];
			*cursor = c;
			cursor += 1;

			if (eol == c) { /* EOL */
				/*function will return on EOL, move the file pointer to the EOL, prepare for next read*/
				portLibrary->file_seek(portLibrary, fd, i - count + 1, EsSeekCur);
				foundEOL = TRUE;
				break;
			}
		}
		nbytes -= count;
	}

	*cursor = '\0';
#if (defined(J9ZOS390))
	tempStr = e2a_string(buf);
	if (NULL == tempStr) {
		return NULL;
	}

	memcpy(buf, tempStr, strlen(buf));
	free(tempStr);
#endif /* defined(J9ZOS390) */
	return buf;
}