Example #1
0
uintptr_t
omrfile_findfirst(struct OMRPortLibrary *portLibrary, const char *path, char *resultbuf)
{
#if defined(AIXPPC)
	DIR64 *dirp = NULL;
#else
	DIR *dirp = NULL;
#endif

#if defined(AIXPPC)
	struct dirent64 *entry;
#else
	struct dirent *entry;
#endif

	Trc_PRT_file_findfirst_Entry2(path, resultbuf);

#if defined(AIXPPC)
	dirp = opendir64(path);
#else
	dirp = opendir(path);
#endif
	if (dirp == NULL) {
		Trc_PRT_file_findfirst_ExitFail(-1);
		return (uintptr_t)-1;
	}
#if defined(AIXPPC)
	entry = readdir64(dirp);
#else
	entry = readdir(dirp);
#endif
	if (entry == NULL) {
#if defined(AIXPPC)
		closedir64(dirp);
#else
		closedir(dirp);
#endif
		Trc_PRT_file_findfirst_ExitFail(-1);
		return (uintptr_t)-1;
	}
	strcpy(resultbuf, entry->d_name);
	Trc_PRT_file_findfirst_Exit((uintptr_t)dirp);
	return (uintptr_t)dirp;
}
Example #2
0
uintptr_t
omrfile_findfirst(struct OMRPortLibrary *portLibrary, const char *path, char *resultbuf)
{
	WIN32_FIND_DATAW findFileData;
	char newPath[EsMaxPath + 1];
	HANDLE result;
	wchar_t unicodeBuffer[UNICODE_BUFFER_SIZE], *unicodePath;

	Trc_PRT_file_findfirst_Entry2(path, resultbuf);

	strcpy(newPath, path);
	strcat(newPath, "*");

	/* Convert the filename from UTF8 to Unicode */
	unicodePath = file_get_unicode_path(portLibrary, newPath, unicodeBuffer, UNICODE_BUFFER_SIZE);
	if (NULL == unicodePath) {
		Trc_PRT_file_findfirst_ExitFail(-1);
		return (uintptr_t)-1;
	}

	result = FindFirstFileW(unicodePath, &findFileData);
	if (unicodeBuffer != unicodePath) {
		portLibrary->mem_free_memory(portLibrary, unicodePath);
	}
	if (result == INVALID_HANDLE_VALUE) {
		int32_t error = GetLastError();
		error = portLibrary->error_set_last_error(portLibrary, error, findError(error));
		Trc_PRT_file_findfirst_ExitFail(error);
		return (uintptr_t)-1;
	}

	/* Assume a successful conversion. The data may be truncated to fit. */
	port_convertToUTF8(portLibrary, findFileData.cFileName, resultbuf, EsMaxPath);
	Trc_PRT_file_findfirst_Exit((uintptr_t)result);
	return (uintptr_t) result;
}