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

📄 os_divers.c

📁 一个用于智能手机的多媒体库适合S60 WinCE的跨平台开发库
💻 C
📖 第 1 页 / 共 3 页
字号:
/* *			GPAC - Multimedia Framework C SDK * *			Copyright (c) Jean Le Feuvre 2000-2005 *					All rights reserved * *  This file is part of GPAC / common tools sub-project * *  GPAC is free software; you can redistribute it and/or modify *  it under the terms of the GNU Lesser General Public License as published by *  the Free Software Foundation; either version 2, or (at your option) *  any later version. *    *  GPAC is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *  GNU Lesser General Public License for more details. *    *  You should have received a copy of the GNU Lesser General Public *  License along with this library; see the file COPYING.  If not, write to *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  * */#include <gpac/tools.h>#if defined(_WIN32_WCE)#include <winsock.h>#include <tlhelp32.h>#elif defined(WIN32)#include <time.h>#include <sys/timeb.h>#include <io.h>#include <windows.h>#include <tlhelp32.h>#else#include <time.h>#include <sys/stat.h>#include <sys/time.h>#include <dirent.h>#include <unistd.h>#include <sys/times.h>#include <sys/resource.h>#ifndef __BEOS__#include <errno.h>#endif#define SLEEP_ABS_SELECT		1static u32 sys_start_time = 0;#endif#ifndef _WIN32_WCE#include <locale.h>#endif#ifndef WIN32u32 gf_sys_clock(){	struct timeval now;	gettimeofday(&now, NULL);	return ( (now.tv_sec)*1000 + (now.tv_usec) / 1000) - sys_start_time;}#endifvoid gf_sleep(u32 ms){#ifdef WIN32	Sleep(ms);#else	s32 sel_err;	struct timeval tv;#ifndef SLEEP_ABS_SELECT	u32 prev, now, elapsed;#endif#ifdef SLEEP_ABS_SELECT	tv.tv_sec = ms/1000;	tv.tv_usec = (ms%1000)*1000;#else	prev = gf_sys_clock();#endif	do {		errno = 0;#ifndef SLEEP_ABS_SELECT		now = gf_sys_clock();		elapsed = (now - prev);		if ( elapsed >= ms ) {			break;		}		prev = now;		ms -= elapsed;		tv.tv_sec = ms/1000;		tv.tv_usec = (ms%1000)*1000;#endif		sel_err = select(0, NULL, NULL, NULL, &tv);	} while ( sel_err && (errno == EINTR) );#endif}#ifndef gettimeofday#ifdef _WIN32_WCE/*	Conversion code for WinCE from pthreads WinCE	(FILETIME in Win32 is from jan 1, 1601)	time between jan 1, 1601 and jan 1, 1970 in units of 100 nanoseconds */#define TIMESPEC_TO_FILETIME_OFFSET (((LONGLONG)27111902 << 32) + (LONGLONG)3577643008)s32 gettimeofday(struct timeval *tp, void *tz){	FILETIME ft;	SYSTEMTIME st;	s32 val;	GetSystemTime(&st);    SystemTimeToFileTime(&st, &ft);	val = (s32) ((*(LONGLONG *) &ft - TIMESPEC_TO_FILETIME_OFFSET) / 10000000);	tp->tv_sec = (u32) val;	val = (s32 ) ((*(LONGLONG *) &ft - TIMESPEC_TO_FILETIME_OFFSET - ((LONGLONG) val * (LONGLONG) 10000000)) * 100);	tp->tv_usec = val;	return 0;}#elif defined(WIN32)s32 gettimeofday(struct timeval *tp, void *tz){	struct _timeb timebuffer;   	_ftime( &timebuffer );	tp->tv_sec  = timebuffer.time;	tp->tv_usec = timebuffer.millitm * 1000;	return 0;}#endif#endif#ifdef _WIN32_WCEvoid CE_Assert(u32 valid){	if (!valid) {		MessageBox(NULL, _T("ASSERT FAILED"), _T("Fatal Error"), MB_OK);	}}void CE_WideToChar(unsigned short *w_str, char *str){	WideCharToMultiByte(CP_ACP, 0, w_str, -1, str, GF_MAX_PATH, NULL, NULL);}void CE_CharToWide(char *str, unsigned short *w_str){	MultiByteToWideChar(CP_ACP, 0, str, -1, w_str, GF_MAX_PATH);}#endifvoid gf_delete_file(char *fileName){#if defined(_WIN32_WCE)	TCHAR swzName[MAX_PATH];	CE_CharToWide(fileName, swzName);	DeleteFile(swzName);#elif defined(WIN32)	DeleteFile(fileName);#else	remove(fileName);#endif}void gf_rand_init(Bool Reset){	if (Reset) {		srand(1);	} else {#if defined(_WIN32_WCE)		srand( (u32) GetTickCount() );#else		srand( (u32) time(NULL) );#endif	}}u32 gf_rand(){	return rand();}#ifndef GPAC_READ_ONLYFILE *gf_temp_file_new(){#if defined(_WIN32_WCE)	TCHAR pPath[MAX_PATH+1];	TCHAR pTemp[MAX_PATH+1];	if (!GetTempPath(MAX_PATH, pPath)) {		pPath[0] = '.';		pPath[1] = '.';	}	if (GetTempFileName(pPath, TEXT("git"), 0, pTemp))		return _wfopen(pTemp, TEXT("w+b"));	return NULL;#elif defined(WIN32)	return tmpfile();#else	return tmpfile(); #endif}#endifvoid gf_utc_time_since_1970(u32 *sec, u32 *msec){#if defined (WIN32) && !defined(_WIN32_WCE)	struct _timeb	tb;	_ftime( &tb );	*sec = tb.time;	*msec = tb.millitm;#else	struct timeval tv;	gettimeofday(&tv, NULL);	*sec = tv.tv_sec;	*msec = tv.tv_usec/1000;#endif}void gf_get_user_name(char *buf, u32 buf_size){	strcpy(buf, "mpeg4-user");#if 0	s32 len;	char *t;	strcpy(buf, "");	len = 1024;	GetUserName(buf, &len);	if (!len) {		t = getenv("USER");		if (t) strcpy(buf, t);	}#endif#if 0	struct passwd *pw;	pw = getpwuid(getuid());	strcpy(buf, "");	if (pw && pw->pw_name) strcpy(name, pw->pw_name);#endif}/*enumerate directories*/GF_Err gf_enum_directory(const char *dir, Bool enum_directory, gf_enum_dir_item enum_dir_fct, void *cbck, const char *filter){	unsigned char item_path[GF_MAX_PATH];#if defined(_WIN32_WCE)	unsigned char _path[GF_MAX_PATH];	unsigned short path[GF_MAX_PATH];	unsigned short w_filter[GF_MAX_PATH];	unsigned char file[GF_MAX_PATH];#else	unsigned char path[GF_MAX_PATH], *file;#endif#ifdef WIN32	WIN32_FIND_DATA FindData;	HANDLE SearchH;#else		DIR *the_dir;	struct dirent* the_file;	struct stat st;#endif	if (!dir || !enum_dir_fct) return GF_BAD_PARAM;#if defined (_WIN32_WCE)	if (dir[strlen(dir) - 1] == GF_PATH_SEPARATOR) {		sprintf(_path, "%s*", dir);	} else {		sprintf(_path, "%s%c*", dir, GF_PATH_SEPARATOR);	}	CE_CharToWide(_path, path);	CE_CharToWide((char *)filter, w_filter);#elif defined(WIN32)	if (dir[strlen(dir) - 1] == GF_PATH_SEPARATOR) {		sprintf(path, "%s*", dir);	} else {		sprintf(path, "%s%c*", dir, GF_PATH_SEPARATOR);	}#else	strcpy(path, dir);	if (path[strlen(path)-1] != '/') strcat(path, "/");#endif#ifdef WIN32	SearchH= FindFirstFile(path, &FindData);	if (SearchH == INVALID_HANDLE_VALUE) return GF_IO_ERR;#if defined (_WIN32_WCE)	_path[strlen(_path)-1] = 0;#else	path[strlen(path)-1] = 0;#endif	while (SearchH != INVALID_HANDLE_VALUE) {#else	the_dir = opendir(path);	if (the_dir == NULL) {		GF_LOG(GF_LOG_ERROR, GF_LOG_CORE, ("[Core] Cannot open directory %s for enumeration\n", path));		return GF_IO_ERR;	}	the_file = readdir(the_dir);	while (the_file) {#endif#if defined (_WIN32_WCE)		if (!wcscmp(FindData.cFileName, _T(".") )) goto next;		if (!wcscmp(FindData.cFileName, _T("..") )) goto next;#elif defined(WIN32)		if (!strcmp(FindData.cFileName, ".")) goto next;		if (!strcmp(FindData.cFileName, "..")) goto next;#else		if (!strcmp(the_file->d_name, "..")) goto next;		if (the_file->d_name[0] == '.') goto next;#endif#ifdef WIN32		if (!enum_directory && (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) goto next;		if (enum_directory && !(FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) goto next;#endif		if (filter) {#if defined (_WIN32_WCE)			short ext[30];			short *sep = wcsrchr(FindData.cFileName, (wchar_t) '.');			if (!sep) goto next;			wcscpy(ext, sep+1);			wcslwr(ext);			if (!wcsstr(w_filter, ext)) goto next;#elif defined(WIN32)			char ext[30];			char *sep = strrchr(FindData.cFileName, '.');			if (!sep) goto next;			strcpy(ext, sep+1);			strlwr(ext);			if (!strstr(filter, ext)) goto next;#else			char ext[30];			char *sep = strrchr(the_file->d_name, '.');			if (!sep) goto next;			strcpy(ext, sep+1);			strlwr(ext);			if (!strstr(filter, sep+1)) goto next;#endif		}#if defined (_WIN32_WCE)		CE_WideToChar(FindData.cFileName, file);		strcpy(item_path, _path);		strcat(item_path, file);#elif defined(WIN32)		strcpy(item_path, path);		strcat(item_path, FindData.cFileName);		file = FindData.cFileName;#else		strcpy(item_path, path);		strcat(item_path, the_file->d_name);	GF_LOG(GF_LOG_DEBUG, GF_LOG_CORE, ("[Core] Checking file %s for enum\n", item_path));				if (stat( item_path, &st ) != 0) goto next;		if (enum_directory && ( (st.st_mode & S_IFMT) != S_IFDIR)) goto next;		if (!enum_directory && ((st.st_mode & S_IFMT) == S_IFDIR)) goto next;		file = the_file->d_name;#endif		if (enum_dir_fct(cbck, file, item_path)) {#ifdef WIN32			FindClose(SearchH);#endif			break;		}next:

⌨️ 快捷键说明

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