randomizw
android port git-svn-id: svn://db.shs.com.ru/pip@39 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#ifndef WINDOWS
|
||||
# include <sys/ioctl.h>
|
||||
# include <fcntl.h>
|
||||
# include <termios.h>
|
||||
#else
|
||||
# include <wincon.h>
|
||||
# ifndef COMMON_LVB_UNDERSCORE
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);}
|
||||
|
||||
@@ -32,7 +32,7 @@ const PIChar PIDir::separator = '/';
|
||||
#endif
|
||||
#ifndef WINDOWS
|
||||
# ifdef ANDROID
|
||||
# include <sys/dirent.h>
|
||||
# include <dirent.h>
|
||||
# else
|
||||
# include <sys/dir.h>
|
||||
# endif
|
||||
@@ -219,7 +219,7 @@ PIVector<PIFile::FileInfo> PIDir::entries() {
|
||||
const_cast<char*>(p.data()), 0
|
||||
# endif
|
||||
, 0,
|
||||
# ifdef MAC_OS
|
||||
# if defined(MAC_OS) || defined(ANDROID)
|
||||
alphasort);
|
||||
# else
|
||||
versionsort);
|
||||
|
||||
@@ -454,7 +454,7 @@ bool PIEthernet::listen(bool threaded) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//#include <QDebug>
|
||||
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_));
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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.;
|
||||
|
||||
@@ -140,6 +140,8 @@ inline double toDeg(double rad) {return rad * M_180_PI;}
|
||||
template<typename T>
|
||||
inline PICout operator <<(PICout s, const complex<T> & 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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user