bool gettime( machine&m, FSP arg1, FSP arg2, FSP arg3) { #if defined( HAVE_GETTIMEOFDAY ) && defined( HAVE_CTIME ) struct timeval current_time; gettimeofday( ¤t_time, NULL ); return arg1.Unify(FSP(&m, ((mint) current_time.tv_sec / 86400))) && arg2.Unify(FSP(&m, ((mint) current_time.tv_sec % 86400))) && arg3.Unify(FSP(&m, ((mint) current_time.tv_usec))); #else // HAVE_GETTIMEOFDAY && HAVE_CTIME RUNWARN( "getdata: gettimeofday is not implemented in this system" ); return fail; #endif // HAVE_GETTIMEOFDAY && HAVE_CTIME }
FileRandRead::FSP MMapRandRead::read(size_t offset, vespalib::DataBuffer & buffer, size_t sz) { const char *data = static_cast<const char *>(_file->MemoryMapPtr(offset)); assert(data != nullptr); assert(_file->MemoryMapPtr(offset+sz-1) != nullptr); vespalib::DataBuffer(data, sz).swap(buffer); return FSP(); }
FileRandRead::FSP NormalRandRead::read(size_t offset, vespalib::DataBuffer & buffer, size_t sz) { buffer.clear(); buffer.ensureFree(sz); _file->ReadBuf(buffer.getFree(), sz, offset); buffer.moveFreeToData(sz); return FSP(); }
bool get_argc( machine& m, FSP arg1 ) { FSP result = FSP( m, static_cast<mint>(lilfes_arg_flag::getArgc()) ); if( ! arg1.Unify( result )) { return false; } return true; }
FileRandRead::FSP DirectIORandRead::read(size_t offset, vespalib::DataBuffer & buffer, size_t sz) { size_t padBefore(0); size_t padAfter(0); bool directio = _file->DirectIOPadding(offset, sz, padBefore, padAfter); buffer.clear(); buffer.ensureFree(padBefore + sz + padAfter + _alignment - 1); if (directio) { size_t unAligned = (-reinterpret_cast<size_t>(buffer.getFree()) & (_alignment - 1)); buffer.moveFreeToData(unAligned); buffer.moveDataToDead(unAligned); } // XXX needs to use pread or file-position-mutex _file->ReadBuf(buffer.getFree(), padBefore + sz + padAfter, offset - padBefore); buffer.moveFreeToData(padBefore + sz); buffer.moveDataToDead(padBefore); return FSP(); }
bool get_argv( machine& m, FSP arg1, FSP arg2 ) { if ( ! arg1.IsInteger() ) { RUNWARN( "get_argv/2: arg1 requires integer" ); return false; } int i = arg1.ReadInteger(); if( i >= lilfes_arg_flag::getArgc() ) { RUNWARN( "get_argv/2: arg1 is too big" ); return false; } FSP result = FSP( m, lilfes_arg_flag::getArgv( i ).c_str() ); if( ! arg2.Unify( result ) ) { return false; } return true; }