⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 os_divers.c

📁 一个用于智能手机的多媒体库适合S60 WinCE的跨平台开发库
💻 C
📖 第 1 页 / 共 3 页
字号:
#ifdef WIN32		if (!FindNextFile(SearchH, &FindData)) {			FindClose(SearchH);			break;		}#else		the_file = readdir(the_dir);#endif	}#ifndef WIN32	closedir(the_dir);#endif	return GF_OK;}#ifndef WIN32char * my_str_upr(char *str){	u32 i;	for (i=0; i<strlen(str); i++) {		str[i] = toupper(str[i]);	}	return str;}char * my_str_lwr(char *str){	u32 i;	for (i=0; i<strlen(str); i++) {		str[i] = tolower(str[i]);	}	return str;}#endifu64 gf_f64_tell(FILE *fp){#if defined(_WIN32_WCE)	return (u64) ftell(fp);#elif defined(WIN32)	fpos_t pos;	if (fgetpos(fp, &pos))		return (u64) -1;	else		return ((u64) pos);#elif defined(CONFIG_LINUX)	return (u64) ftello64(fp);#elif defined(CONFIG_FREEBSD)	return (u64) ftell(fp);#else	return (u64) ftell(fp);#endif}u64 gf_f64_seek(FILE *fp, s64 offset, s32 whence){#if defined(_WIN32_WCE)	return (u64) fseek(fp, (s32) offset, whence);#elif defined(WIN32)	fpos_t pos;	if (whence == SEEK_CUR) {		fgetpos(fp, &pos);		pos += (fpos_t) offset;	} 	else if (whence == SEEK_END) 		pos = (fpos_t) (_filelengthi64(fileno(fp)) + offset);	else if (whence == SEEK_SET)		pos = (fpos_t) offset;	return fsetpos(fp, &pos);#elif defined(CONFIG_LINUX)	return fseeko64(fp, (off64_t) offset, whence);#elif defined(CONFIG_FREEBSD)	return fseek(fp, offset, whence);#else	return fseek(fp, (s32) offset, whence);#endif}FILE *gf_f64_open(const char *file_name, const char *mode){#if defined(WIN32)	return fopen(file_name, mode);#elif defined(CONFIG_LINUX)	return fopen64(file_name, mode);#elif defined(CONFIG_FREEBSD)	return fopen(file_name, mode);#else	return fopen(file_name, mode);#endif}/*seems OK under mingw also*/#ifdef WIN32#ifdef _WIN32_WCEBool gf_prompt_has_input(){	return 0;}char gf_prompt_get_char() { return 0; }void gf_prompt_set_echo_off(Bool echo_off) { return; }#else#include <conio.h>#include <windows.h>Bool gf_prompt_has_input(){	return kbhit();}char gf_prompt_get_char(){	return getchar();}void gf_prompt_set_echo_off(Bool echo_off) {	DWORD flags;	HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);	GetConsoleMode(hStdin, &flags);	if (echo_off) flags &= ~ENABLE_ECHO_INPUT;	else flags |= ENABLE_ECHO_INPUT;	SetConsoleMode(hStdin, flags);}#endif#else/*linux kbhit/getchar- borrowed on debian mailing lists, (author Mike Brownlow)*/#include <termios.h>static struct termios t_orig, t_new;static s32 ch_peek = -1;static void init_keyboard(){	tcgetattr(0, &t_orig);	t_new = t_orig;	t_new.c_lflag &= ~ICANON;	t_new.c_lflag &= ~ECHO;	t_new.c_lflag &= ~ISIG;	t_new.c_cc[VMIN] = 1;	t_new.c_cc[VTIME] = 0;	tcsetattr(0, TCSANOW, &t_new);}static void close_keyboard(Bool new_line){	tcsetattr(0,TCSANOW, &t_orig);	if (new_line) fprintf(stdout, "\n");}void gf_prompt_set_echo_off(Bool echo_off) { 	init_keyboard();	if (echo_off) t_orig.c_lflag &= ~ECHO;	else t_orig.c_lflag |= ECHO;	close_keyboard(0);}Bool gf_prompt_has_input(){	u8 ch;	s32 nread;	init_keyboard();	if (ch_peek != -1) return 1;	t_new.c_cc[VMIN]=0;	tcsetattr(0, TCSANOW, &t_new);	nread = read(0, &ch, 1);	t_new.c_cc[VMIN]=1;	tcsetattr(0, TCSANOW, &t_new);	if(nread == 1) {		ch_peek = ch;		return 1;	}	close_keyboard(0);	return 0;}char gf_prompt_get_char(){	char ch;	if (ch_peek != -1) {		ch = ch_peek;		ch_peek = -1;		close_keyboard(1);		return ch;	}	read(0,&ch,1);	close_keyboard(1);	return ch;}#endifstatic u32 sys_init = 0;static u32 last_update_time = 0;static u64 last_process_k_u_time = 0;GF_SystemRTInfo the_rti;#if defined(_WIN32_WCE)static LARGE_INTEGER frequency , init_counter;static u64 last_total_k_u_time = 0;static u32 mem_usage_at_startup = 0;#ifndef GetCurrentPermissionsDWORD GetCurrentPermissions();#endif#ifndef SetProcPermissionsvoid SetProcPermissions(DWORD );#endif#elif defined(WIN32)static LARGE_INTEGER frequency , init_counter;static u64 last_proc_idle_time = 0;static u64 last_proc_k_u_time = 0;static HINSTANCE psapi_hinst = NULL;typedef BOOL(WINAPI* NTGetSystemTimes)(VOID *,VOID *,VOID *);NTGetSystemTimes MyGetSystemTimes = NULL;typedef BOOL(WINAPI* NTGetProcessMemoryInfo)(HANDLE,VOID *,DWORD);NTGetProcessMemoryInfo MyGetProcessMemoryInfo = NULL;typedef int(WINAPI* NTQuerySystemInfo)(ULONG,PVOID,ULONG,PULONG);NTQuerySystemInfo MyQuerySystemInfo = NULL;#ifndef PROCESS_MEMORY_COUNTERStypedef struct _PROCESS_MEMORY_COUNTERS {  	DWORD cb;	DWORD PageFaultCount;	SIZE_T PeakWorkingSetSize;	SIZE_T WorkingSetSize;	SIZE_T QuotaPeakPagedPoolUsage;	SIZE_T QuotaPagedPoolUsage;	SIZE_T QuotaPeakNonPagedPoolUsage;	SIZE_T QuotaNonPagedPoolUsage;	SIZE_T PagefileUsage;	SIZE_T PeakPagefileUsage;} PROCESS_MEMORY_COUNTERS;#endif#ifndef SYSTEM_PROCESSOR_PERFORMANCE_INFORMATIONtypedef struct _SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION {	LARGE_INTEGER IdleTime;	LARGE_INTEGER KernelTime;	LARGE_INTEGER UserTime;	LARGE_INTEGER Reserved1[2];	ULONG Reserved2;} SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION;#endif#elsestatic u64 last_cpu_u_k_time = 0;static u64 last_cpu_idle_time = 0;static u64 mem_at_startup = 0;#endif#ifdef WIN32static u32 (*OS_GetSysClock)();u32 gf_sys_clock(){	return OS_GetSysClock();}#endif#if defined(_WIN32_WCE)static u32 OS_GetSysClockHIGHRES(){	LARGE_INTEGER now;	QueryPerformanceCounter(&now);	now.QuadPart -= init_counter.QuadPart;	return (u32) ((now.QuadPart * 1000) / frequency.QuadPart);}static u32 OS_GetSysClockNORMAL() { return GetTickCount(); }#elif defined(WIN32)static u32 OS_GetSysClockHIGHRES(){	LARGE_INTEGER now;	QueryPerformanceCounter(&now);	now.QuadPart -= init_counter.QuadPart;	return (u32) (now.QuadPart * 1000 / frequency.QuadPart);}u32 OS_GetSysClockNORMAL() { return timeGetTime(); }#endifvoid gf_sys_init(){	if (!sys_init) {#if defined(WIN32)#if defined(_WIN32_WCE)		MEMORYSTATUS ms;#endif		frequency.QuadPart = 0;		/*clock setup*/		if (QueryPerformanceFrequency(&frequency)) {			QueryPerformanceCounter(&init_counter);			OS_GetSysClock = OS_GetSysClockHIGHRES;			GF_LOG(GF_LOG_INFO, GF_LOG_CORE, ("[core] using WIN32 performance timer\n"));		} else {#ifndef _WIN32_WCE			timeBeginPeriod(1);#endif			OS_GetSysClock = OS_GetSysClockNORMAL;			GF_LOG(GF_LOG_INFO, GF_LOG_CORE, ("[core] using WIN32 regular timer\n"));		}		GF_LOG(GF_LOG_INFO, GF_LOG_CORE, ("[core] checking for run-time info tools"));#if defined(_WIN32_WCE)		last_total_k_u_time = last_process_k_u_time = 0;		last_update_time = 0;		memset(&the_rti, 0, sizeof(GF_SystemRTInfo));		the_rti.pid = GetCurrentProcessId();		GlobalMemoryStatus(&ms);		mem_usage_at_startup = ms.dwAvailPhys;#else		/*cpu usage tools are buried in win32 dlls...*/		MyGetSystemTimes = (NTGetSystemTimes) GetProcAddress(GetModuleHandle("kernel32.dll"), "GetSystemTimes");		if (!MyGetSystemTimes) {			MyQuerySystemInfo = (NTQuerySystemInfo) GetProcAddress(GetModuleHandle("ntdll.dll"), "NtQuerySystemInformation");			if (MyQuerySystemInfo) {				GF_LOG(GF_LOG_INFO, GF_LOG_CORE, (" - CPU: QuerySystemInformation"));			}		} else {			GF_LOG(GF_LOG_INFO, GF_LOG_CORE, (" - CPU: GetSystemsTimes"));		}		psapi_hinst = LoadLibrary("psapi.dll");		MyGetProcessMemoryInfo = (NTGetProcessMemoryInfo) GetProcAddress(psapi_hinst, "GetProcessMemoryInfo");		if (MyGetProcessMemoryInfo) {			GF_LOG(GF_LOG_INFO, GF_LOG_CORE, (" - memory: GetProcessMemoryInfo"));		}		last_process_k_u_time = last_proc_idle_time = last_proc_k_u_time = 0;		last_update_time = 0;		memset(&the_rti, 0, sizeof(GF_SystemRTInfo));		the_rti.pid = GetCurrentProcessId();#endif		GF_LOG(GF_LOG_INFO, GF_LOG_CORE, ("\n"));#else		/*linux threads...*/		last_process_k_u_time = 0;		last_cpu_u_k_time = last_cpu_idle_time = 0;		last_update_time = 0;		memset(&the_rti, 0, sizeof(GF_SystemRTInfo));		the_rti.pid = getpid();		sys_start_time = gf_sys_clock();#endif		GF_LOG(GF_LOG_INFO, GF_LOG_CORE, ("[core] process id %d\n", the_rti.pid));#ifndef _WIN32_WCE		setlocale( LC_NUMERIC, "C" ); #endif	}	sys_init += 1;}void gf_sys_close(){	if (sys_init > 0) {		sys_init --;		if (sys_init) return;		/*prevent any call*/		last_update_time = 0xFFFFFFFF;#if defined(WIN32) && !defined(_WIN32_WCE)		if (!frequency.QuadPart) timeEndPeriod(1);				MyGetSystemTimes = NULL;		MyGetProcessMemoryInfo = NULL;		MyQuerySystemInfo = NULL;		if (psapi_hinst) FreeLibrary(psapi_hinst);		psapi_hinst = NULL;#endif	}}extern size_t gpac_allocated_memory;extern size_t gpac_nb_alloc_blocs;/*CPU and Memory Usage*/#ifdef WIN32Bool gf_sys_get_rti(u32 refresh_time_ms, GF_SystemRTInfo *rti, u32 flags){#if defined(_WIN32_WCE)	THREADENTRY32 tentry;	u64 total_cpu_time, process_cpu_time;	DWORD orig_perm;	#endif	MEMORYSTATUS ms;	u64 creation, exit, kernel, user, process_k_u_time, proc_idle_time, proc_k_u_time;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -