Esempio n. 1
0
int32_t
omrfile_chmod(struct OMRPortLibrary *portLibrary, const char *path, int32_t mode)
{
	int32_t attrs;
	int32_t result;
	wchar_t unicodeBuffer[UNICODE_BUFFER_SIZE], *unicodePath;
	int32_t actualMode = J9_FILE_MODE_READABLE;

	Trc_PRT_file_chmod_Entry(path, mode);
	/* Convert the filename from UTF8 to Unicode */
	unicodePath = file_get_unicode_path(portLibrary, path, unicodeBuffer, UNICODE_BUFFER_SIZE);
	if (NULL == unicodePath) {
		Trc_PRT_file_chmod_Exit(-1);
		return -1;
	}

	attrs = GetFileAttributesW(unicodePath);
	if (attrs == INVALID_FILE_ATTRIBUTES) {
		int32_t setError;
		result = GetLastError();
		setError = portLibrary->error_set_last_error(portLibrary, result, findError(result));
		Trc_PRT_file_chmod_getAttributesFailed(setError);
		if (unicodeBuffer != unicodePath) {
			portLibrary->mem_free_memory(portLibrary, unicodePath);
		}
		Trc_PRT_file_chmod_Exit(-1);
		return -1;
	}
	if (J9_FILE_MODE_WRITABLE == (J9_FILE_MODE_WRITABLE & mode)) {
		/* If all of the write-enable bits in mode are set, then turn off READONLY */
		attrs = attrs & ~FILE_ATTRIBUTE_READONLY;
		actualMode |= J9_FILE_MODE_WRITABLE;
	} else {
		attrs = attrs | FILE_ATTRIBUTE_READONLY;
	}
	result = SetFileAttributesW(unicodePath, attrs);
	if (0 == result) {
		int32_t setError;
		result = GetLastError();
		setError = portLibrary->error_set_last_error(portLibrary, result, findError(result));
		Trc_PRT_file_chmod_setAttributesFailed(setError);
		actualMode = -1;
	}
	if (unicodeBuffer != unicodePath) {
		portLibrary->mem_free_memory(portLibrary, unicodePath);
	}
	Trc_PRT_file_chmod_Exit(actualMode);
	return actualMode;
}
Esempio n. 2
0
int32_t
omrfile_chmod(struct OMRPortLibrary *portLibrary, const char *path, int32_t mode)
{
	int32_t result;
	intptr_t actualMode = -1;
	struct stat buffer;
	const int32_t MODEBITS = 07777; /* bits from  S_ISUID down: lstat can return mode with the high-order bits set. */

	Trc_PRT_file_chmod_Entry(path, mode);
	result = chmod(path, mode);
	if (0 != result) {
		result = portLibrary->error_set_last_error(portLibrary, errno, findError(errno));
		Trc_PRT_file_chmod_setAttributesFailed(result);
	} else if (0 != lstat(path, &buffer)) {
		result = portLibrary->error_set_last_error(portLibrary, errno, findError(errno));
		Trc_PRT_file_chmod_getAttributesFailed(result);
	} else {
		actualMode = buffer.st_mode & MODEBITS;
	}
	Trc_PRT_file_chmod_Exit(actualMode);
	return actualMode;
}