コード例 #1
0
ファイル: hcp_library.c プロジェクト: adamarvid/hcp
void HCP_CALL hcp_Leftshift(hcp_tRuntime* R, hcp_tBlob* pSource, const hcp_Size_t Steps) {
	if (pSource->length < Steps) {
		return;
	}

	const hcp_Uint8* source = (hcp_Uint8*)((hcp_Size_t)pSource->value + Steps);

	hcp_Memcpy((hcp_tState*)R->context, pSource->value, source, pSource->length - Steps);

	pSource->length -= Steps;
}
コード例 #2
0
ファイル: hcp_library.c プロジェクト: adamarvid/hcp
hcp_Int hcp_AppendBytes(const hcp_Uint8* pSource, const hcp_Size_t Length, hcp_tBlob* pDestination) {
	if (pSource == HCP_NULL || Length == 0) {
		return HCP_NOERROR;
	}

	if (Length + pDestination->length >= pDestination->maxLength) {
		return HCP_BLOBOUTOFRANGE;
	}

	hcp_Int error = HCP_NOERROR;
	hcp_Uint8* dest = (hcp_Uint8*)((hcp_Size_t)pDestination->value + pDestination->length);

	hcp_Memcpy(HCP_NULL, dest, pSource, Length);

	pDestination->length += Length;
	return HCP_NOERROR;
}
コード例 #3
0
ファイル: hcp.cpp プロジェクト: husqvarnagroup/hcp
bool hcp::Runtime::scanDir(const char* codecPath,const char** error) {
	uv_fs_t req;
	int numFiles = uv_fs_scandir(uv_default_loop(), &req, codecPath, UV_FS_SCANDIR, nullptr);

	if (numFiles < 0) {
		if (error) {
			*error = uv_strerror(numFiles);
		}

		return false;
	}

	for (int i = 0; i < numFiles; i++) {
		uv_dirent_t ent;
		hcp::tCodec codec;

		int r = uv_fs_scandir_next(&req, &ent);

		if (r == UV_EOF) {
			break;
		}

		hcp_Boolean found = HCP_FALSE;
		// skip codecs with duplicate name
		hcp_FindFirst(&_codecs.header, 0, (void*)ent.name, &found);

		if (found == HCP_TRUE) {
			continue;
		}

		if (hcp::Runtime::hasExtension(ent.name, ".DLL") ||
			hcp::Runtime::hasExtension(ent.name, ".SO") ||
        hcp::Runtime::hasExtension(ent.name, ".DYLIB")) {

			hcp_Size_t pathLen = hcp_szStrLen((hcp_szStr)codecPath);
			hcp_Size_t nameLen = hcp_szStrLen((hcp_szStr)ent.name);

			codec.path = (char*)hcp_Malloc(_state, pathLen + nameLen + 2);
			
			hcp_Memcpy(_state, codec.path, codecPath, pathLen);
			hcp_Memcpy(_state, codec.path + pathLen, "/", 1);
			hcp_Memcpy(_state, codec.path + pathLen + 1, ent.name, nameLen + 1);

			if (loadLibrary(codec.path, &codec, error)) {
				hcp_Size_t index;
				auto code = hcp_Push(&_codecs.header, &codec, &index);

				if (code != HCP_NOERROR) {
					// TODO: Logg load errors
					hcp_Free(_state, codec.path);
				}
			}
			else {
				// TODO: Logg load errors
				hcp_Free(_state, codec.path);
			}
		}
		else {
			continue;
		}
	}

	return true;
}