Ignore:
Timestamp:
11/07/14 17:51:01 (9 years ago)
Author:
Maciej Komosinski
Message:

Sources support both 32-bit and 64-bit, and more compilers

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/common/nonstd_stdio.cpp

    r227 r247  
    55#include "nonstd_stdio.h"
    66#include "nonstd.h"
     7#include "Convert.h" //strTOwstr()
     8#include <common/stl-util.h>
    79
    810#if defined _WIN32 && !defined SHP
    911 //<unistd.h> not needed for unlink()
    1012 #include "Shlwapi.h" //PathIsRelative()
    11  #include "Util.h" //strTOwstr()
     13 #include <sys/stat.h> //_stat
    1214#else
    1315 #include <unistd.h>
     
    2325}
    2426
     27bool directoryExists(const char* path)
     28{
     29struct _stat s;
     30if (_stat(path,&s)!=0) return false;
     31return S_ISDIR(s.st_mode);
     32}
     33
     34bool makeDirectory(const char* path)
     35{
     36#ifdef _WIN32
     37return mkdir(path)==0;
     38#else
     39return mkdir(path,0777)==0;
     40#endif
     41}
     42
     43bool makeDirectories(const char* path)
     44{
     45if (directoryExists(path)) return true;
     46string parentdir=getFileDir(path);
     47if (!makeDirectories(parentdir.c_str())) return false;
     48return makeDirectory(path);
     49}
     50
     51int getFileSize(const char* path)
     52{
     53int size;
     54MFILE *f=mfopen(path,FOPEN_READ_BINARY);
     55if (f==NULL) return -1;
     56size=getFileSize(f);
     57mfclose(f);
     58return size;
     59}
     60
     61int getFileSize(MFILE *f)
     62{
     63  int saved_pos = mftell(f);
     64  mfseek(f, 0, SEEK_END);
     65  int size = mftell(f);
     66  mfseek(f, saved_pos, SEEK_SET);
     67  return size;
     68}
     69
    2570bool removeFile(const char* path)
    2671{
     
    3580        return PathIsRelative(fname) == FALSE; //no wide char for old borland compiler
    3681 #else
    37         return PathIsRelative(Util::strTOwstr(fname).c_str()) == FALSE; //http://msdn.microsoft.com/en-us/library/bb773660%28v=vs.85%29.aspx
     82        return PathIsRelative(Convert::strTOwstr(fname).c_str()) == FALSE; //http://msdn.microsoft.com/en-us/library/bb773660%28v=vs.85%29.aspx
    3883 #endif
    3984#else
Note: See TracChangeset for help on using the changeset viewer.