コード例 #1
0
ファイル: zi.c プロジェクト: 709889989/unispim
int LoadHZData(const TCHAR *hz_data_name)
{
	int file_length;

	assert(hz_data_name);

	if (share_segment->hz_data_loaded)
		return 1;

	file_length = GetFileLength(hz_data_name);
	if (file_length <= 0)
		return 0;

	hz_data = AllocateSharedMemory(hz_data_share_name, file_length);
	if (!hz_data)
		return 0;

	if ((file_length = LoadFromFile(hz_data_name, hz_data, file_length)) == -1)
	{
		FreeSharedMemory(hz_data_share_name, hz_data);
		Log(LOG_ID, L"汉字信息表文件打开失败。name=%s", hz_data_name);
		return 0;
	}

	if (!file_length)
		return 0;

	share_segment->hz_data_loaded = 1;

	return 1;
}
コード例 #2
0
ファイル: gbk_map.c プロジェクト: 52M/unispim
/**	GENERNATE GBKMAP到内存。
 *	返回:
 *		成功:1
 *		失败:0
 */
int GenGBKMapData()
{
	int i,j,pos_offset;
	byte pos_mask,*pos;

	if (share_segment->gbkmap_loaded)
		return 1;

	gbk_map = AllocateSharedMemory(gbkmap_share_name, GBKMAP_SIZE);
	if (!gbk_map)
		return 0;

	for ( i=0; i < sizeof(GBK_SCOPE)/sizeof(int)-1; i+=2 )
	{
		for ( j=GBK_SCOPE[i]; j <= GBK_SCOPE[i+1]; j++)
		{
			pos_offset = j >> 3;
			pos_mask = 1 << (j % 8);

			pos = (byte*)(gbk_map + pos_offset);
			*pos = (*pos) | pos_mask;			
		}
	}

	share_segment->gbkmap_loaded = 1;

	return 1;
}
コード例 #3
0
int create_shared_memory() {
    int id;
    
    id = AllocateSharedMemory(sizeof (Memory));

    return id;

}
コード例 #4
0
ファイル: fontcheck.c プロジェクト: 709889989/unispim
/**	加载fontmap到内存。
 *	参数:
 *		fontmap_file_name			fontmap文件全路径
 *	返回:
 *		成功:1
 *		失败:0
 */
int LoadFontMapData(const TCHAR *file_name)
{
	int file_length;

	assert(file_name);

	if ( pim_config->scope_gbk == HZ_SCOPE_GBK || !pim_config->hide_black_window )
	{
		share_segment->fontmap_loaded = 0;
		return 0;
	}

	if (share_segment->fontmap_loaded)
		return 1;

	file_length = GetFileLength(file_name);
	if (file_length <= 0)
		return 0;

	fontmap = AllocateSharedMemory(fontmap_share_name, file_length);
	if (!fontmap)
		return 0;

	if ((file_length = LoadFromFile(file_name, fontmap, file_length)) == -1)
	{
		FreeSharedMemory(fontmap_share_name, fontmap);
		Log(LOG_ID, L"FONT MAP文件打开失败。name=%s", file_name);
		return 0;
	}

	if (!file_length)
		return 0;

	share_segment->fontmap_loaded = 1;

	return 1;
}
コード例 #5
0
bool InitAPRGlobalStorage (APRGlobalStorage *storage_p, apr_pool_t *pool_p, apr_hashfunc_t hash_fn, unsigned char *(*make_key_fn) (const void *data_p, uint32 raw_key_length, uint32 *key_len_p), void (*free_key_and_value_fn) (unsigned char *key_p, void *value_p), server_rec *server_p, const char *mutex_filename_s, const char *cache_id_s, const char *provider_name_s)
{
	ap_socache_provider_t *provider_p = ap_lookup_provider (AP_SOCACHE_PROVIDER_GROUP, provider_name_s, AP_SOCACHE_PROVIDER_VERSION);

	if (provider_p)
		{
			apr_status_t status = apr_global_mutex_create (& (storage_p -> ags_mutex_p), mutex_filename_s, APR_THREAD_MUTEX_UNNESTED, pool_p);

			if (status == APR_SUCCESS)
				{
					char *current_dir_s = GetCurrentWorkingDirectory ();

					if (current_dir_s)
						{
							storage_p -> ags_largest_entry_memory_id = AllocateSharedMemory (current_dir_s, sizeof (unsigned int), 0644);

							FreeCopiedString (current_dir_s);

							if (storage_p -> ags_largest_entry_memory_id != -1)
								{
									storage_p -> ags_entries_p = apr_hash_make_custom (pool_p, hash_fn);

										if (storage_p -> ags_entries_p)
											{
												storage_p -> ags_pool_p = pool_p;
												storage_p -> ags_server_p = server_p;
												storage_p -> ags_make_key_fn = make_key_fn;
												storage_p -> ags_free_key_and_value_fn = free_key_and_value_fn;

												storage_p -> ags_cache_id_s = cache_id_s;
												storage_p -> ags_mutex_lock_filename_s = mutex_filename_s;

												storage_p -> ags_socache_instance_p = NULL;
												storage_p -> ags_socache_provider_p = provider_p;

												apr_pool_cleanup_register (pool_p, storage_p, (const void *) FreeAPRGlobalStorage, apr_pool_cleanup_null);

												return true;
											}		/* if (storage_p -> ags_entries_p) */
										else
											{
												PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to allocate shared memory hash table");
											}

									FreeSharedMemory (storage_p -> ags_largest_entry_memory_id);
								}		/* if (storage_p -> ags_largest_entry_memory_id != -1) */
							else
								{
									PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to allocate shared memory for largest chunk size");
								}

						}		/* if (mem_key_s) */
					else
						{
							PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to create memory key from \"%s\" and \".memory\"", cache_id_s);
						}

					apr_global_mutex_destroy (storage_p -> ags_mutex_p);
					storage_p -> ags_mutex_p = NULL;
				}		/* if (status == APR_SUCCESS) */
			else
				{
					PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to create global mutex for shared memory at %s", mutex_filename_s);
				}

		}		/* if (provider_p) */
	else
		{
			PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to find provider \"%s\"", provider_name_s ? provider_name_s : "NULL");
		}

	return false;
}