Ejemplo n.º 1
0
int64_t
omrfile_length(struct OMRPortLibrary *portLibrary, const char *path)
{
	int64_t result = -1;
	wchar_t unicodeBuffer[UNICODE_BUFFER_SIZE], *unicodePath;

	Trc_PRT_file_length_Entry(path);

	/* Convert the filename from UTF8 to Unicode */
	unicodePath = file_get_unicode_path(portLibrary, path, unicodeBuffer, UNICODE_BUFFER_SIZE);
	if (NULL != unicodePath) {
		WIN32_FILE_ATTRIBUTE_DATA myStat;
		if (0 == GetFileAttributesExW(unicodePath, GetFileExInfoStandard, &myStat)) {
			int32_t error = GetLastError();
			result = portLibrary->error_set_last_error(portLibrary, error, findError(error));
		} else {
			result = ((int64_t)myStat.nFileSizeHigh) << 32;
			result += (int64_t)myStat.nFileSizeLow;
		}

		if (unicodeBuffer != unicodePath) {
			portLibrary->mem_free_memory(portLibrary, unicodePath);
		}
	}

	Trc_PRT_file_length_Exit(result);
	return result;
}
Ejemplo n.º 2
0
int64_t
omrfile_length(struct OMRPortLibrary *portLibrary, const char *path)
{
	struct stat st;

	Trc_PRT_file_length_Entry(path);

	/* Neutrino does not handle NULL for stat */
	if (0 != stat(path, &st)) {
		int32_t errorCode = portLibrary->error_set_last_error(portLibrary, errno, findError(errno));
		Trc_PRT_file_length_Exit(errorCode);
		return errorCode;
	}
	Trc_PRT_file_length_Exit((int64_t)st.st_size);
	return (int64_t) st.st_size;
}