Esempio n. 1
0
void filecopy()
{
	int fd1,fd2;
	fd1=open("cat.c",O_RDWR);
	fd2=open("ccc",O_RDWR);
	filecp(fd1,fd2);
//	printf("%d %d",fd1,fd2);
	close(fd1);
	close(fd2);
}
Esempio n. 2
0
static VALUE
win32_readlink(const char* file)
{
	VALUE error = Qnil;
	VALUE target = Qnil;
	HANDLE h = INVALID_HANDLE_VALUE;
	bool ok = true;
	REPARSE_DATA_BUFFER* buf = NULL;
	const size_t buf_size = MAXIMUM_REPARSE_DATA_BUFFER_SIZE;

	buf = (REPARSE_DATA_BUFFER*)xmalloc(buf_size);
	if(ok)
	{
		const DWORD share_mode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
		const DWORD access_mode = FILE_READ_EA;
		const DWORD attributes =
				  FILE_FLAG_BACKUP_SEMANTICS
				| FILE_ATTRIBUTE_REPARSE_POINT
				| FILE_FLAG_OPEN_REPARSE_POINT;

		h = CreateFile( file, access_mode, share_mode,
			0, OPEN_EXISTING, attributes, NULL);

		if(!(ok = (h != INVALID_HANDLE_VALUE)))
		{
			error = make_api_error(file);
		}
	}

	if(ok)
	{
		DWORD returned_size;
		ok = 0 != DeviceIoControl (h, FSCTL_GET_REPARSE_POINT,
			NULL, 0, buf, buf_size, &returned_size, NULL);
		if(!ok)
		{
			error = make_api_error(file);
		}
	}
	if(ok)
	{
		wchar_t* raw_target = NULL;
		long target_len = 0;

		switch (buf->ReparseTag)
		{
		case IO_REPARSE_TAG_MOUNT_POINT:
		{
			raw_target = &buf->MountPointReparseBuffer.PathBuffer[
				buf->MountPointReparseBuffer.SubstituteNameOffset / sizeof(wchar_t)];
			target_len = buf->MountPointReparseBuffer.SubstituteNameLength / sizeof(wchar_t);
			break;
		}
		case IO_REPARSE_TAG_SYMLINK:
		{
			raw_target = &buf->SymbolicLinkReparseBuffer.PathBuffer[
				buf->SymbolicLinkReparseBuffer.SubstituteNameOffset / sizeof(wchar_t)];
			target_len = buf->SymbolicLinkReparseBuffer.SubstituteNameLength / sizeof(wchar_t);
			break;
		}
		default:
			ok = false;
			error = make_error_str(rb_eIOError, "file %s is not a symlink", file);
		}
		if(ok)
		{
			wchar_t* resolved;
			resolved = resolve_api_path(raw_target);
			target_len -= resolved - raw_target;
			target = wstr_to_str(filecp(), resolved, target_len);
		}
	}


	if( h != INVALID_HANDLE_VALUE )
	{
		CloseHandle(h);
	}
	xfree(buf);

	if( !NIL_P(error) )
	{
		rb_exc_raise(error);
	}
	return target;
}