示例#1
0
文件: log.cpp 项目: mbolhuis/xbmc
bool CLog::Init(const char* path)
{
  CSingleLock waitLock(critSec);
  if (!m_file)
  {
    // g_settings.m_logFolder is initialized in the CSettings constructor
    // and changed in CApplication::Create()
#ifdef _WIN32
    CStdStringW pathW;
    g_charsetConverter.utf8ToW(path, pathW, false);
    CStdStringW strLogFile, strLogFileOld;

    strLogFile.Format(L"%sxbmc.log", pathW);
    strLogFileOld.Format(L"%sxbmc.old.log", pathW);

    struct __stat64 info;
    if (_wstat64(strLogFileOld.c_str(),&info) == 0 &&
        !::DeleteFileW(strLogFileOld.c_str()))
      return false;
    if (_wstat64(strLogFile.c_str(),&info) == 0 &&
        !::MoveFileW(strLogFile.c_str(),strLogFileOld.c_str()))
      return false;

    m_file = _wfsopen(strLogFile.c_str(),L"wb", _SH_DENYWR);
#else
    CStdString strLogFile, strLogFileOld;

    strLogFile.Format("%sxbmc.log", path);
    strLogFileOld.Format("%sxbmc.old.log", path);

    struct stat64 info;
    if (stat64(strLogFileOld.c_str(),&info) == 0 &&
        remove(strLogFileOld.c_str()) != 0)
      return false;
    if (stat64(strLogFile.c_str(),&info) == 0 &&
        rename(strLogFile.c_str(),strLogFileOld.c_str()) != 0)
      return false;

    m_file = fopen(strLogFile.c_str(),"wb");
#endif
  }

  if (m_file)
  {
    unsigned char BOM[3] = {0xEF, 0xBB, 0xBF};
    fwrite(BOM, sizeof(BOM), 1, m_file);
  }

  if (!m_repeatLine)
    m_repeatLine = new CStdString;

  return m_file != NULL;
}
示例#2
0
// Returns the size of filename (64bit)
u64 GetSize(const std::string &filename)
{
    if (!Exists(filename))
    {
        LOG_ERROR(Common_Filesystem, "failed %s: No such file", filename.c_str());
        return 0;
    }

    if (IsDirectory(filename))
    {
        LOG_ERROR(Common_Filesystem, "failed %s: is a directory", filename.c_str());
        return 0;
    }

    struct stat64 buf;
#ifdef _WIN32
    if (_wstat64(Common::UTF8ToUTF16W(filename).c_str(), &buf) == 0)
#else
    if (stat64(filename.c_str(), &buf) == 0)
#endif
    {
        LOG_TRACE(Common_Filesystem, "%s: %lld",
                filename.c_str(), (long long)buf.st_size);
        return buf.st_size;
    }

    LOG_ERROR(Common_Filesystem, "Stat failed %s: %s",
            filename.c_str(), GetLastErrorMsg());
    return 0;
}
示例#3
0
/* plFileInfo */
plFileInfo::plFileInfo(const plFileName &filename)
    : fFileSize(-1), fCreateTime(), fModifyTime(), fFlags()
{
    if (!filename.IsValid())
        return;

#if HS_BUILD_FOR_WIN32
    struct __stat64 info;
    if (_wstat64(filename.AsString().ToWchar(), &info) != 0)
        return;
#else
    struct stat info;
    if (stat(filename.AsString().c_str(), &info) != 0)
        return;
#endif

    fFlags |= kEntryExists;
    fFileSize = info.st_size;
    fCreateTime = info.st_ctime;
    fModifyTime = info.st_mtime;
    if (info.st_mode & S_IFDIR)
        fFlags |= kIsDirectory;
    if (info.st_mode & S_IFREG)
        fFlags |= kIsNormalFile;
}
示例#4
0
// Returns true if file filename exists
bool Exists(const std::string &filename)
{
	// Make sure Windows will no longer handle critical errors, which means no annoying "No disk" dialog
	// Save the old error mode 
#if defined(_WIN32) && !defined(__MINGW32__)
	int OldMode = SetErrorMode(SEM_FAILCRITICALERRORS);
#endif

	struct stat64 file_info;
#if defined(_WIN32) && defined(UNICODE) && !defined(__MINGW32__)
	std::wstring copy = ConvertUTF8ToWString(filename);
	StripTailDirSlashes(copy);

	int result = _wstat64(copy.c_str(), &file_info);
#else
	std::string copy(filename);
	StripTailDirSlashes(copy);

	int result = stat64(copy.c_str(), &file_info);
#endif

	// Set the old error mode
#if defined(_WIN32) && !defined(__MINGW32__)
	SetErrorMode(OldMode);
#endif

	return (result == 0);
}
示例#5
0
int VSIWin32FilesystemHandler::Stat( const char * pszFilename, 
                                     VSIStatBufL * pStatBuf,
                                     int nFlags )

{
    (void) nFlags;

#if (defined(WIN32) && _MSC_VER >= 1310) || __MSVCRT_VERSION__ >= 0x0601
    if( CSLTestBoolean(
            CPLGetConfigOption( "GDAL_FILENAME_IS_UTF8", "YES" ) ) )
    {
        int nResult;
        wchar_t *pwszFilename = 
            CPLRecodeToWChar( pszFilename, CPL_ENC_UTF8, CPL_ENC_UCS2 );

        nResult = _wstat64( pwszFilename, pStatBuf );
        CPLFree( pwszFilename );

        return nResult;
    }
    else
#endif
    {
        return( VSI_STAT64( pszFilename, pStatBuf ) );
    }
}
示例#6
0
int S_windows_stat64(const char *pathname, struct STATBUF *buffer) {
  wchar_t wpathname[PATH_MAX];
  if (MultiByteToWideChar(CP_UTF8,0,pathname,-1,wpathname,PATH_MAX) == 0)
    return _stat64(pathname, buffer);
  else
    return _wstat64(wpathname, buffer);
}
示例#7
0
文件: File.cpp 项目: jetlive/skiaming
bool File::FileExists(const wstring& sFileName)
{
   struct __stat64 buf;  
   int iResult = _wstat64( sFileName.c_str() , &buf);
   
   return (0 == iResult ? true : false);
}
示例#8
0
	void File::get_time(Time* create, Time* access, Time* write) const
	{
		struct _stat64 stat;
		if(_wstat64(path, &stat)) SSH_THROW(L"Не удалось получить время файла %s!", path);
		if(access) *access = stat.st_atime;
		if(create) *create = stat.st_ctime;
		if(write) *write = stat.st_mtime;
	}
示例#9
0
int BLI_wstat(const wchar_t *path, BLI_stat_t *buffer)
{
#if defined(_MSC_VER)
	return _wstat64(path, buffer);
#else
	return _wstat(path, buffer);
#endif
}
示例#10
0
bool exists(const char *filename)
{
  wstring wfn = StringFormat::UTF82Wide(filename);

  struct __stat64 st;
  int res = _wstat64(wfn.c_str(), &st);

  return (res == 0);
}
示例#11
0
 static bool exists(const string &filename) {
   #if !defined(_WIN32)
   struct stat64 data;
   return stat64(filename, &data) == 0;
   #else
   struct __stat64 data;
   return _wstat64(utf16_t(filename), &data) == 0;
   #endif
 }
示例#12
0
int BLI_wstat(const wchar_t *path, BLI_stat_t *buffer)
{
#if defined(_MSC_VER) || defined(__MINGW64__)
	return _wstat64(path, buffer);
#elif defined(__MINGW32__)
	return _wstati64(path, buffer);
#else
	return _wstat(path, buffer);
#endif
}
示例#13
0
文件: File.cpp 项目: jetlive/skiaming
bool File::DirExists(const wstring& sFileName)
{  
   struct __stat64 buf;  
   int iResult = _wstat64( sFileName.c_str() , &buf);
   
   if (0 == iResult) {	    
	   return (buf.st_mode & _S_IFDIR ? true : false);
   }
   else return false;   
}
int
hssystemfileio_copy_permissions(const wchar_t *old_path, const wchar_t *new_path)
{
	struct __stat64 st;
	int rc = _wstat64(old_path, &st);
	if (rc == -1)
	{ return rc; }
	
	return _wchmod(new_path, st.st_mode);
}
示例#15
0
 static uintmax_t size(const string &filename) {
   #if !defined(_WIN32)
   struct stat64 data;
   stat64(filename, &data);
   #else
   struct __stat64 data;
   _wstat64(utf16_t(filename), &data);
   #endif
   return S_ISREG(data.st_mode) ? data.st_size : 0u;
 }
示例#16
0
static int path_wstat(const wstring& path_wc, path_stat_t *st)
{
#if defined(_MSC_VER) || defined(__MINGW64__)
	return _wstat64(path_wc.c_str(), st);
#elif defined(__MINGW32__)
	return _wstati64(path_wc.c_str(), st);
#else
	return _wstat(path_wc.c_str(), st);
#endif
}
示例#17
0
文件: file.hpp 项目: Cydrak/dasShiny
 static bool exists(const string& filename) {
   #if !defined(_WIN32)
   struct stat64 data;
   if(stat64(filename, &data) != 0) return false;
   #else
   struct __stat64 data;
   if(_wstat64(utf16_t(filename), &data) != 0) return false;
   #endif
   //return true if this is a file, and false if this is a directory
   return !(data.st_mode & S_IFDIR);
 }
示例#18
0
int	__zbx_stat(const char *path, struct stat *buf)
{
	int	ret;
	wchar_t	*wpath;

	wpath = zbx_utf8_to_unicode(path);
	ret = _wstat64(wpath, buf);
	zbx_free(wpath);

	return ret;
}
示例#19
0
int _stat64_utf8(const char *path, struct __stat64 *buffer)
{
	wchar_t *wpath;
	int ret;

	if (!(wpath = wchar_from_utf8(path))) return -1;
	ret = _wstat64(wpath, buffer);
	free(wpath);

	return ret;
}
示例#20
0
文件: os_windows.c 项目: peluse/nvml
/*
 * os_stat -- stat abstraction layer
 */
int
os_stat(const char *pathname, os_stat_t *buf)
{
	wchar_t *path = util_toUTF16(pathname);
	if (path == NULL)
		return -1;

	int ret = _wstat64(path, buf);

	util_free_UTF16(path);
	return ret;
}
示例#21
0
bool
isDirectory(const std::string &path)
{
   auto winPath = platform::toWinApiString(path);
   struct _stat64 info;

   if (_wstat64(winPath.c_str(), &info)) {
      return false;
   }

   return !!(info.st_mode & _S_IFDIR);
}
示例#22
0
    /**
        Determines whether the specified file exists

        \param[in]      path        Path to file
        \returns        true        iff the path refers to a file (not a directory) and the file exists

        The Exists method should not be used for path validation, this method merely checks
        if the file specified in path exists. Passing an invalid path to Existsl returns false.

        Be aware that another process can potentially do something with the file in between the
        time you call the Exists method and perform another operation on the file, such as Delete.
        A recommended programming practice is to wrap the Exists method, and the operations you
        take on the file, in a try...catch block. The Exists method can only help to ensure that the
        file will be available, it cannot guarantee it.

        The path parameter is permitted to specify relative or absolute path information.
        Relative path information is interpreted as relative to the current working directory.
        To obtain the current working directory, see GetCurrentDirectory.

        \note If path describes a directory, this method returns false.
    */
    bool SCXFile::Exists(const SCXFilePath& path) {
#if defined(WIN32)
        struct __stat64 buf;
        int failure = _wstat64(path.Get().c_str(), &buf );
#elif defined(SCX_UNIX)
        SCXFileSystem::SCXStatStruct buf;
        std::string localizedName = SCXFileSystem::EncodePath(path);
        int failure = SCXFileSystem::Stat(localizedName.c_str(), &buf );
#else
#error
#endif
        return !failure && !(buf.st_mode & S_IFDIR);
    }
示例#23
0
 static time_t timestamp(const string &filename, file::time mode = file::time::create) {
   #if !defined(_WIN32)
   struct stat64 data;
   stat64(filename, &data);
   #else
   struct __stat64 data;
   _wstat64(utf16_t(filename), &data);
   #endif
   switch(mode) { default:
     case file::time::create: return data.st_ctime;
     case file::time::modify: return data.st_mtime;
     case file::time::access: return data.st_atime;
   }
 }
示例#24
0
bool StFileNode::isFileExists(const StCString& thePath) {
#ifdef _WIN32
    StStringUtfWide aPath;
    aPath.fromUnicode(thePath);
    struct __stat64 aStatBuffer;
    return _wstat64(aPath.toCString(), &aStatBuffer) == 0;
#elif (defined(__APPLE__))
    struct stat aStatBuffer;
    return stat(thePath.toCString(), &aStatBuffer) == 0;
#else
    struct stat64 aStatBuffer;
    return stat64(thePath.toCString(), &aStatBuffer) == 0;
#endif
}
示例#25
0
文件: BFile.hpp 项目: digideskio/byps
  BINLINE int64_t BFile::size() const {

#ifdef _MSC_VER
	  wstring n = getFullName();
	  struct _stat64 stat_buf;
	  int rc = _wstat64(n.c_str(), &stat_buf);
#else
	  string n = getFullNameUtf8();
	  struct stat stat_buf;
	  int rc = stat(n.c_str(), &stat_buf);
#endif

    return rc == 0 ? stat_buf.st_size : -1;
  }
示例#26
0
uint64_t GetModifiedTimestamp(const string &filename)
{
  wstring wfn = StringFormat::UTF82Wide(filename);

  struct __stat64 st;
  int res = _wstat64(wfn.c_str(), &st);

  if(res == 0)
  {
    return (uint64_t)st.st_mtime;
  }

  return 0;
}
示例#27
0
hpatch_BOOL _hpatch_getPathStat_noEndDirSeparator(const char* path_utf8,hpatch_TPathType* out_type,
                                                  hpatch_StreamPos_t* out_fileSize,size_t* out_st_mode){
#if (_IS_USED_WIN32_UTF8_WAPI)
    int            wsize;
    wchar_t        path_w[hpatch_kPathMaxSize];
    struct _stat64 s;
#else
#   ifdef _MSC_VER
    struct _stat64 s;
#   else
    struct stat  s;
#   endif
#endif
    
    int          rt;
    assert(out_type!=0);
    memset(&s,0,sizeof(s));
#if (_IS_USED_WIN32_UTF8_WAPI)
    wsize=_utf8FileName_to_w(path_utf8,path_w,hpatch_kPathMaxSize);
    if (wsize<=0) return hpatch_FALSE;
    rt = _wstat64(path_w,&s);
#else
#   ifdef _MSC_VER
    rt = _stat64(path_utf8,&s);
#   else
    rt = stat(path_utf8,&s);
#   endif
#endif
    
    if(rt!=0){
        if (errno==ENOENT){
            *out_type=kPathType_notExist;
            return hpatch_TRUE;
        }
        return hpatch_FALSE; //error
    }else if ((s.st_mode&S_IFMT)==S_IFREG){
        *out_type=kPathType_file;
        if (out_fileSize) *out_fileSize=s.st_size;
        if (out_st_mode) *out_st_mode=s.st_mode;
        return hpatch_TRUE;
    }else if ((s.st_mode&S_IFMT)==S_IFDIR){
        *out_type=kPathType_dir;
        if (out_fileSize) *out_fileSize=0;
        if (out_st_mode) *out_st_mode=s.st_mode;
        return hpatch_TRUE;
    }else{
        return hpatch_FALSE; //as error; unknow how to dispose
    }
}
示例#28
0
int flac_internal_stat64_utf8(const char *path, struct __stat64 *buffer)
{
	if (!utf8_filenames) {
		return _stat64(path, buffer);
	} else {
		wchar_t *wpath;
		int ret;

		if (!(wpath = wchar_from_utf8(path))) return -1;
		ret = _wstat64(wpath, buffer);
		free(wpath);

		return ret;
	}
}
BOOL FileTransferModule_Impl::sendFile(IN const CString& sFilePath, IN const std::string& sSendToSID,IN BOOL bOnlineMode)
{
    if (TransferFileEntityManager::getInstance()->checkIfIsSending(sFilePath))
    {
        return FALSE;
    }
    TransferFileEntity fileEntity;

    //获取文件大小
    struct __stat64 buffer;
    _wstat64(sFilePath, &buffer);
    fileEntity.nFileSize = (UInt32)buffer.st_size;
    if (0 != fileEntity.nFileSize)
    {
        CString strFileName = sFilePath;
        strFileName.Replace(_T("\\"), _T("/"));//mac上对于路径字符“\”需要做特殊处理,windows上则可以识别
        fileEntity.sFileName = util::cStringToString(strFileName);
        fileEntity.sFromID = module::getSysConfigModule()->userID();
        fileEntity.sToID = sSendToSID;
        uint32_t transMode = 0;
        transMode = bOnlineMode ? IM::BaseDefine::FileType::FILE_TYPE_ONLINE : IM::BaseDefine::FileType::FILE_TYPE_OFFLINE;

        LOG__(DEBG,_T("FileTransferSevice_Impl::sendFile sTaskID = %s"), util::stringToCString(fileEntity.sTaskID));

        imcore::IMLibCoreStartOperationWithLambda(
            [=]()
        {
            IM::File::IMFileReq imFileReq;
            LOG__(APP, _T("imFileReq,name=%s,size=%d,toId=%s"),util::stringToCString(fileEntity.sFileName)
                  ,fileEntity.nFileSize,util::stringToCString(fileEntity.sToID));
            imFileReq.set_from_user_id(util::stringToInt32(fileEntity.sFromID));
            imFileReq.set_to_user_id(util::stringToInt32(fileEntity.sToID));
            imFileReq.set_file_name(fileEntity.sFileName);
            imFileReq.set_file_size(fileEntity.nFileSize);
            imFileReq.set_trans_mode(static_cast<IM::BaseDefine::FileType>(transMode));

            module::getTcpClientModule()->sendPacket(IM::BaseDefine::ServiceID::DFFX_SID_FILE
                    , IM::BaseDefine::FileCmdID::DFFX_CID_FILE_REQUEST
                    , &imFileReq);
        });

        return TRUE;
    }
    LOG__(ERR, _T("fileEntity FileSize error,size = %d"), fileEntity.nFileSize);
    return FALSE;
}
__int64	FileSize(const char *_filename)
{
	__stat64 buf;
	
	size_t len = strlen(_filename) + 1;
	wchar_t wcstr[128];
	size_t n;
	mbstowcs_s(&n, wcstr, len, _filename, _TRUNCATE);

	if (_wstat64(wcstr, &buf) != 0)
	{
		Logw("ERROR: FileSize: _wstat64(%s) = %d\n", _filename, errno);
		return (RETURN_FAILURE);
	}

	return (buf.st_size);


} // end FileSize()