📄 util.cc
字号:
//// Copyright (c) 2002 by Istv醤 V醨adi//// This file is part of dxr3Player, a DVD player written specifically // for the DXR3 (aka Hollywood+) decoder card.// This program is free software; you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation; either version 2 of the License, or// (at your option) any later version.//// This program 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 General Public License for more details.//// You should have received a copy of the GNU General Public License// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA//------------------------------------------------------------------------------#include "Util.h"#include <cstdio>#include <cstdarg>#include <cstring>#include <ctime>#include <unistd.h>#include <sys/time.h>#include <sys/stat.h>//------------------------------------------------------------------------------namespace {millis_t getMillisForTimeval(const struct timeval& tv){ millis_t millis = tv.tv_sec; millis *= 1000; millis += tv.tv_usec / 1000; return millis;}}//------------------------------------------------------------------------------millis_t Util::currentTimeMillis(){ struct timeval tv; gettimeofday(&tv, 0); return getMillisForTimeval(tv);}//------------------------------------------------------------------------------bool Util::readLine(char* buffer, size_t length, FILE* file){ bool commentLine = true; do { char* s = fgets(buffer, length, file); if (s==0) return false; if (*buffer != '#') { size_t lineLength = strlen(buffer); if (buffer[lineLength-1]=='\n') { buffer[lineLength-1] = '\0'; } commentLine = false; } } while(commentLine); return true;}//------------------------------------------------------------------------------unsigned Util::getLanguageCode(const char* language){ if (language==0 || strlen(language)!=2) { return 0xffff; } unsigned l0 = language[0]; l0 &= 0xff; unsigned l1 = language[1]; l1 &= 0xff; if ( l0<'a' || l0>'z' || l1<'a' || l1>'z') { return 0xffff; } else { return ((l0<<8) | l1); }}//------------------------------------------------------------------------------bool Util::makeDirectory(const char* path){ char* lastSlash = strrchr(path, '/'); if (lastSlash!=NULL && lastSlash!=path) { char buffer[256]; unsigned length = lastSlash - path; if (length>=sizeof(buffer)) return false; memcpy(buffer, path, length); buffer[length] = '\0'; if (!makeDirectory(buffer)) return false; } struct stat st; bool exists = stat(path, &st)==0; exists = exists && S_ISDIR(st.st_mode); exists = exists && (access(path, R_OK|X_OK)==0); if (!exists) { return mkdir(path, 0755)==0; } else { return true; }}//------------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -