diff --git a/src/console/piscreen.cpp b/src/console/piscreen.cpp index f406c372..4faf2e81 100644 --- a/src/console/piscreen.cpp +++ b/src/console/piscreen.cpp @@ -21,6 +21,7 @@ #ifndef WINDOWS # include # include +# include #else # include # ifndef COMMON_LVB_UNDERSCORE diff --git a/src/core/pibase.h b/src/core/pibase.h index a8bf86da..1cff8a15 100644 --- a/src/core/pibase.h +++ b/src/core/pibase.h @@ -111,8 +111,8 @@ #ifdef ANDROID # define tcdrain(fd) ioctl(fd, TCSBRK, 1) - inline int wctomb(char * c, wchar_t w) {*c = ((char * )&w)[0]; return 1;} - inline int mbtowc(wchar_t * w, const char * c, size_t) {*w = ((wchar_t * )&c)[0]; return 1;} + //inline int wctomb(char * c, wchar_t w) {*c = ((char * )&w)[0]; return 1;} + //inline int mbtowc(wchar_t * w, const char * c, size_t) {*w = ((wchar_t * )&c)[0]; return 1;} #endif #ifdef MAC_OS diff --git a/src/core/piinit.cpp b/src/core/piinit.cpp index dedfa35a..4c2141d1 100644 --- a/src/core/piinit.cpp +++ b/src/core/piinit.cpp @@ -158,8 +158,9 @@ PIInit::PIInit() { sinfo->user = ps->pw_name; else { memset(cbuff, 0, 1024); - if (getlogin_r(cbuff, 1023) == 0) - sinfo->user = cbuff; + char * l = getlogin(); + if (l) + sinfo->user = l; } struct utsname uns; if (uname(&uns) == 0) { diff --git a/src/core/pistring.cpp b/src/core/pistring.cpp index 73d129a4..1f6b16de 100755 --- a/src/core/pistring.cpp +++ b/src/core/pistring.cpp @@ -81,6 +81,9 @@ const int PIString::fromBaseN[] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - #else # define pisprintf(f, v) char ch[256]; memset(ch, 0, 256); sprintf_s(ch, 256, f, v); #endif +#ifdef ANDROID +int wctomb(char * c, wchar_t w) {*c = ((char * )&w)[0]; return 1;} +#endif PIString PIString::itos(const int num) {pisprintf("%d", num); return PIString(ch);} PIString PIString::ltos(const long num) {pisprintf("%ld", num); return PIString(ch);} diff --git a/src/io/pidir.cpp b/src/io/pidir.cpp index 4106bc50..f3ab01d1 100755 --- a/src/io/pidir.cpp +++ b/src/io/pidir.cpp @@ -32,7 +32,7 @@ const PIChar PIDir::separator = '/'; #endif #ifndef WINDOWS # ifdef ANDROID -# include +# include # else # include # endif @@ -219,7 +219,7 @@ PIVector PIDir::entries() { const_cast(p.data()), 0 # endif , 0, -# ifdef MAC_OS +# if defined(MAC_OS) || defined(ANDROID) alphasort); # else versionsort); diff --git a/src/io/piethernet.cpp b/src/io/piethernet.cpp index 37125d33..52a73127 100755 --- a/src/io/piethernet.cpp +++ b/src/io/piethernet.cpp @@ -454,7 +454,7 @@ bool PIEthernet::listen(bool threaded) { return true; } - +//#include int PIEthernet::read(void * read_to, int max_size) { //cout << "read " << sock << endl; if (sock == -1) init(); @@ -486,8 +486,10 @@ int PIEthernet::read(void * read_to, int max_size) { PRIVATE->addr_.sin_len = sizeof(PRIVATE->addr_); #endif //piCoutObj << "connect to " << ip_ << ":" << port_ << "..."; - connected_ = (::connect(sock, (sockaddr * )&PRIVATE->addr_, sizeof(PRIVATE->addr_)) == 0); + //qDebug() << "connect to " << ip_.data() << ":" << port_ << sock << PRIVATE->addr_.sin_addr.s_addr << "..."; + connected_ = (::connect(sock, (sockaddr * )&(PRIVATE->addr_), sizeof(PRIVATE->addr_)) == 0); //piCoutObj << "connect to " << ip_ << ":" << port_ << connected_; + //qDebug() << "connect to " << ip_.data() << ":" << port_ << connected_; if (!connected_) piCoutObj << "Can`t connect to " << ip_ << ":" << port_ << ", " << ethErrorString(); opened_ = connected_; @@ -497,13 +499,16 @@ int PIEthernet::read(void * read_to, int max_size) { } else piMSleep(10); //piCout << "connected to" << path(); + //qDebug() << "connected to" << path().data(); } if (!connected_) return -1; errorClear(); rs = ethRecv(sock, read_to, max_size); //piCoutObj << "readed" << rs; + //qDebug() << "readed" << rs; if (rs <= 0) { lerr = ethErrorCore(); + //qDebug() << "readed error" << errorString().data(); #ifdef WINDOWS if (lerr == WSAEWOULDBLOCK || /*lerr == NO_ERROR ||*/ lerr == WSAETIMEDOUT) { #else @@ -521,6 +526,7 @@ int PIEthernet::read(void * read_to, int max_size) { //piCoutObj << "eth" << ip_ << "disconnected"; } if (rs > 0) received(read_to, rs); + //qDebug() << "return from read" << rs; return rs; case UDP: memset(&PRIVATE->raddr_, 0, sizeof(PRIVATE->raddr_)); diff --git a/src/io/pifile.cpp b/src/io/pifile.cpp index 49fb9f38..72a04876 100755 --- a/src/io/pifile.cpp +++ b/src/io/pifile.cpp @@ -322,15 +322,20 @@ PIFile::FileInfo PIFile::fileInfo(const PIString & path) { ret.size = fs.st_size; ret.id_user = fs.st_uid; ret.id_group = fs.st_gid; -#ifdef MAC_OS -# define ATIME st_atimespec -# define MTIME st_ctimespec +#ifdef ANDROID + ret.time_access = PIDateTime::fromSystemTime(PISystemTime(fs.st_atime, fs.st_atime_nsec)); + ret.time_modification = PIDateTime::fromSystemTime(PISystemTime(fs.st_mtime, fs.st_mtime_nsec)); #else -# define ATIME st_atim -# define MTIME st_mtim +# ifdef MAC_OS +# define ATIME st_atimespec +# define MTIME st_ctimespec +# else +# define ATIME st_atim +# define MTIME st_mtim +# endif + ret.time_access = PIDateTime::fromSystemTime(PISystemTime(fs.ATIME.tv_sec, fs.ATIME.tv_nsec)); + ret.time_modification = PIDateTime::fromSystemTime(PISystemTime(fs.MTIME.tv_sec, fs.MTIME.tv_nsec)); #endif - ret.time_access = PIDateTime::fromSystemTime(PISystemTime(fs.ATIME.tv_sec, fs.ATIME.tv_nsec)); - ret.time_modification = PIDateTime::fromSystemTime(PISystemTime(fs.MTIME.tv_sec, fs.MTIME.tv_nsec)); ret.perm_user = FileInfo::Permissions((mode & S_IRUSR) == S_IRUSR, (mode & S_IWUSR) == S_IWUSR, (mode & S_IXUSR) == S_IXUSR); ret.perm_group = FileInfo::Permissions((mode & S_IRGRP) == S_IRGRP, (mode & S_IWGRP) == S_IWGRP, (mode & S_IXGRP) == S_IXGRP); ret.perm_other = FileInfo::Permissions((mode & S_IROTH) == S_IROTH, (mode & S_IWOTH) == S_IWOTH, (mode & S_IXOTH) == S_IXOTH); diff --git a/src/math/pimathbase.cpp b/src/math/pimathbase.cpp index 7c2d9cc7..89214b3a 100644 --- a/src/math/pimathbase.cpp +++ b/src/math/pimathbase.cpp @@ -18,6 +18,7 @@ */ #include "pimathbase.h" +#include "pitime.h" double piJ0(const double & v) { @@ -450,6 +451,11 @@ double piYn(int n, const double & v) { } +void randomize() { + srand(PISystemTime::current(true).nanoseconds); +} + + double randomn(double dv, double sv) { static bool agen = false; double s = 2., v0 = 0., v1 = 0.; diff --git a/src/math/pimathbase.h b/src/math/pimathbase.h index e5749924..96826658 100644 --- a/src/math/pimathbase.h +++ b/src/math/pimathbase.h @@ -140,6 +140,8 @@ inline double toDeg(double rad) {return rad * M_180_PI;} template inline PICout operator <<(PICout s, const complex & v) {s.space(); s.setControl(0, true); s << "(" << v.real() << "; " << v.imag() << ")"; s.restoreControl(); return s;} +void randomize(); + // [-1 ; 1] inline double randomd() {return (double)random() / RAND_MAX * 2. - 1.;} // [-1 ; 1] normal diff --git a/src/system/pilibrary.cpp b/src/system/pilibrary.cpp index ba6cb4a8..0ce4680e 100644 --- a/src/system/pilibrary.cpp +++ b/src/system/pilibrary.cpp @@ -101,7 +101,7 @@ void PILibrary::getLastError() { #ifdef WINDOWS liberror = errorString(); #else - char * e = dlerror(); + const char * e = dlerror(); if (e) liberror = e; else liberror.clear(); #endif