/* * Use the DMA2D peripheral in register to memory * mode to clear the frame buffer to a single * color. */ void dma2d_fill(uint32_t color) { #ifdef MEMORY_BENCHMARK uint32_t t1, t0; t0 = mtime(); #endif DMA2D_IFCR |= 0x3F; DMA2D_CR = DMA2D_SET(CR, MODE, DMA2D_CR_MODE_R2M); DMA2D_OPFCCR = 0x0; /* ARGB8888 pixels */ /* force it to have full alpha */ DMA2D_OCOLR = 0xff000000 | color; DMA2D_OOR = 0; DMA2D_NLR = DMA2D_SET(NLR, PL, 800) | 480; /* 480 lines */ DMA2D_OMAR = (uint32_t) FRAMEBUFFER_ADDRESS; /* kick it off */ DMA2D_CR |= DMA2D_CR_START; while (DMA2D_CR & DMA2D_CR_START); #ifdef MEMORY_BENCHMARK t1 = mtime(); printf("Transfer rate (R2M) %6.2f MB/sec\n", 1464.84 / (float) (t1 - t0)); #endif }
// This function returns time in seconds since the first call. // It's used but the ARP protocol in netether.c // You can remove this if your OS/COMPILER already supports standard ANSI time functions // or if you don't wish to use the ethernet feature of this stack. // This functions uses mtime()! ULONG time(ULONG *returnTime) { static ULONG timeStorage = 0; static ULONG lastTime = 0; ULONG newTime; ULONG timeDiff; if (timeStorage) { // Get new system time newTime = mtime(); // Get time difference in seconds since last call if (newTime >= lastTime) timeDiff = (newTime - lastTime) / 1000; else timeDiff = (0 - lastTime + newTime) / 1000; // If time difference is more than one second since last called, update time if (timeDiff >= 1 ) { timeStorage += timeDiff; lastTime += timeDiff * 1000; } } else { lastTime = mtime(); timeStorage = 1; } if (returnTime) *returnTime = timeStorage; return timeStorage; }
bool File::is_up_to_date(const std::string& in, const std::string& out) { // Return true if the output file is older than the input file. time_t t1 = mtime(out); time_t t2 = mtime(in); //time_t t3 = mtime(env_->program_path()); return t1 >= t2;// && t1 >= t3; }
fsd::fsd(char *configfile) { certfile=NULL; whazzupfile=NULL; dolog(L_INFO,"Booting server"); pmanager=new pman; /* Start the information manager */ manager=new manage(); configman=new configmanager(configfile); pmanager->registerprocess(configman); /* Create the METAR manager */ metarmanager=new mm; pmanager->registerprocess(metarmanager); /* Read the system configuration */ configure(); /* Create the management variables */ createmanagevars(); /* Create the server and the client interfaces */ createinterfaces(); /* Connect to the other server */ makeconnections(); dolog(L_INFO,"We are up"); prevnotify=prevlagcheck=timer=mtime(); prevwhazzup=mtime(); fileopen=0; }
void fsd::run() { pmanager->run(); if (timer!=mtime()) { timer=mtime(); dochecks(); } }
int clinterface::run() { int busy=tcpinterface::run(); if ((mtime()-prevwinddelta)>WINDDELTATIMEOUT) { prevwinddelta=mtime(); sendwinddelta(); } return busy; }
void echoserver_process_message( int32_t fd, int16_t ev, void * arg ) { struct session * s = (struct session *)arg; if ( ev & EV_READ ) { char buf[16384]; int32_t readn = -1; readn = read( fd, buf, 16384 ); if ( readn <= 0 ) { #if __DEBUG printf( "Client[%ld, %d] is closed, BYTES:%d, TIME:%lld .\n", s->sid, s->fd, s->iobytes, mtime() ); #endif //evsets_del( event_get_sets(s->evread), s->evread ); event_destroy( s->evread ); close( s->fd ); free( s ); goto PROCESS_END; } else { #if __DEBUG printf("echoserver_process_message(ev:%d) : TIME:%lld .\n", ev, mtime() ); #endif readn = write( fd, buf, readn ); s->iobytes += readn; } #if USE_LIBEVENT { struct timeval tv = {TIMEOUT_MSECS/1000, 0}; event_add( s->evread, &tv ); } #else evsets_add( event_get_sets(s->evread), s->evread, TIMEOUT_MSECS ); #endif } else { #if __DEBUG printf("echoserver_process_message(ev:%d) : TIME:%lld .\n", ev, mtime() ); #endif } PROCESS_END : return; }
int SBCELT_FUNC(celt_decode_float_futex)(CELTDecoder *st, const unsigned char *data, int len, float *pcm) { int slot = (int)((uintptr_t)st); debugf("decode_float; len=%i", len); workpage->slot = slot; memcpy(&workpage->encbuf[0], data, len); workpage->len = len; uint64_t begin = mtime(); // Wake up the helper, if necessary... workpage->ready = 0; futex_wake(&workpage->ready); int bad = 0; if (workpage->busywait) { while (!workpage->ready) { uint64_t elapsed = mtime() - begin; if (elapsed > lastrun*2) { bad = 1; break; } } } else { do { struct timespec ts = { 0, (lastrun*2) * NSEC_PER_USEC }; int err = futex_wait(&workpage->ready, 0, &ts); if (err == 0) { break; } else if (err == ETIMEDOUT) { bad = 1; break; } } while (!workpage->ready); } if (!bad) { uint64_t elapsed = mtime() - begin; #ifdef DYNAMIC_TIMEOUT lastrun = elapsed; #endif debugf("spent %lu usecs in decode\n", elapsed); memcpy(pcm, workpage->decbuf, sizeof(float)*480); } else { #ifdef DYNAMIC_TIMEOUT lastrun = 3000; #endif memset(pcm, 0, sizeof(float)*480); } return CELT_OK; }
void pr8_work(char *goal) { if (goal == NULL) return; printf("goal: %s\n", goal); struct target *target_goal = find_target(goal); if(target_goal == NULL) { } else { struct timespec t1 = mtime(target_goal->target_name); struct source *temp = target_goal->target_sources; bool recipe_flag = false; while(temp->next != NULL) { struct timespec t2 = mtime(temp->source_name); // source if (t1.tv_sec == 0 || t1.tv_sec < t2.tv_sec || ((t1.tv_sec == t2.tv_sec) && (t1.tv_nsec < t2.tv_nsec))) { recipe_flag = true; } temp = temp->next; } if(recipe_flag) { printf("%s is outdated or nonexistant, execute recipes\n", temp->source_name); recipe_list_print(target_goal->target_recipes); } } // if goal is a known target, // iterate through goal's list of sources, // call pr8_work() on each source // iterate through goal's list of sources, // compare times of goal and its sources // if necessary, iterate through goal's list of recipes, // print the recipe // ... more later return; }
/* Function: _log * -------------- * Log to a file or stdout * * level: 'E' for error, 'I' for info, 'D' for debug (verbose). * msg: Message to log. * * Returns: Value of fprintf, or 1 if message was ignored. */ int _log(char level, const char *fmt, ...) { int lasterr = errno; va_list arg; char buf[1024]; char ts[64]; time_t t = (mtime() / 1000); struct tm *lt = localtime(&t); strftime(ts, 64, "%H:%M:%S", lt); if (level != 'D' || verbose) { va_start(arg, fmt); vsnprintf(buf, 1023, fmt, arg); if (level == 'E') { int n = strlen(buf) - 1; snprintf((buf + n), (1023 - n), ": %s\r", strerror(lasterr)); } va_end(arg); return fprintf(logfd, "%c:[%s] %s\r\r", level, ts, buf); } else { return 1; } }
void server::receivepong(char *data) { int fd; time_t t; if (sscanf(data,"%d %ld", &fd, &t)!=2) return; lag=mtime()-t; }
void PingAllPlayer(int writesocket) { int i; for (i = 1; i <= sv_maxplayers; i++) { if (player[i].used == 1 && player[i].joinstatus >= 4) { int stringsize = 5; unsigned char *buffer = malloc(stringsize); if (buffer == NULL) error_exit("Memory error ( SendJoinMessage() )\n"); int position = 0; buffer[position] = 249; position++; buffer[position] = 0; position++; buffer[position] = 32; position++; buffer[position] = 191; position++; buffer[position] = 0; position++; player[i].start = mtime(); SendToPlayer(buffer, stringsize, i, 0, writesocket); free(buffer); } } }
unsigned long wait_till(unsigned long ts) { unsigned long t = mtime(); if (t > ts) return t; delay((ts - t)); return ts; }
// SBCELT_HelperMonitor implements a monitor thread that runs // when libsbcelt decides to use SBCELT_MODE_FUTEX. It is // response for determining whether the helper process has died, // and if that happens, restart it. static void *SBCELT_HelperMonitor(void *udata) { (void) udata; while (1) { uint64_t now = mtime(); uint64_t elapsed = now - lastdead; lastdead = now; // Throttle helper re-launches to around 1 per sec. if (elapsed < 1*USEC_PER_SEC) { usleep(1*USEC_PER_SEC); } debugf("restarted sbcelt-helper; %lu usec since last death", elapsed); pid_t child = fork(); if (child == -1) { // We're memory constrained. Wait and try again... usleep(5*USEC_PER_SEC); continue; } else if (child == 0) { // For SBCELT_SANDBOX_SECCOMP_BPF, it shouldn't matter // whether the child inherits any file descriptors, since // the only useful system call the process can make is futex(2). // // However, if we're running in Futex mode without a sandbox, // closing the file descriptors is indeed a good idea, which // is why we do it unconditionally below. (void) HANDLE_EINTR(close(0)); (void) HANDLE_EINTR(close(1)); #ifndef DEBUG xclosefrom(2); #else xclosefrom(3); #endif char *const argv[] = { SBCELT_HelperBinary(), NULL, }; execv(argv[0], argv); _exit(100); } int status; int retval = HANDLE_EINTR(waitpid(child, &status, 0)); if (retval == child) { if (WIFEXITED(status)) { debugf("sbcelt-helper died with exit status: %i", WEXITSTATUS(status)); } else if (WIFSIGNALED(status)) { debugf("sbcelt-helper died with signal: %i", WTERMSIG(status)); } } else if (retval == -1 && errno == EINVAL) { fprintf(stderr, "libsbcelt: waitpid() failed with EINVAL; internal error!\n"); fflush(stderr); exit(1); } } }
void PingAllPlayer(){ int i; for (i = 1; i <= sv_maxplayers; i++) if (player[i].used == 1 && player[i].joinstatus >= 4) player[i].start = mtime(); byte buffer[] = {249,0,32,191,0}; SendToAll(buffer, 5, 0); }
int main() { // for timing #ifdef WIN32 LARGE_INTEGER res; ::QueryPerformanceFrequency(&res); LARGE_INTEGER li,li2; #else struct timeval tv1,tv2; gettimeofday(&tv1,NULL); #endif test_fsm::player p2; p2.start(); // for timing #ifdef WIN32 ::QueryPerformanceCounter(&li); #else gettimeofday(&tv1,NULL); #endif for (int i=0;i<100;++i) { p2.process_event(test_fsm::open_close()); p2.process_event(test_fsm::open_close()); p2.process_event(test_fsm::cd_detected()); p2.process_event(test_fsm::play()); for (int j=0;j<100;++j) { p2.process_event(test_fsm::NextSong()); p2.process_event(test_fsm::NextSong()); p2.process_event(test_fsm::PreviousSong()); p2.process_event(test_fsm::PreviousSong()); } p2.process_event(test_fsm::pause()); // go back to Playing p2.process_event(test_fsm::end_pause()); p2.process_event(test_fsm::pause()); p2.process_event(test_fsm::stop()); // event leading to the same state p2.process_event(test_fsm::stop()); p2.process_event(test_fsm::open_close()); p2.process_event(test_fsm::open_close()); } #ifdef WIN32 ::QueryPerformanceCounter(&li2); #else gettimeofday(&tv2,NULL); #endif #ifdef WIN32 std::cout << "msm took in s:" << (double)(li2.QuadPart-li.QuadPart)/res.QuadPart <<"\n" <<std::endl; #else std::cout << "msm took in us:" << mtime(tv1,tv2) <<"\n" <<std::endl; #endif return 0; }
server::server(char *i, char *n, char *e, char *h, char *v, int fl, char *l) { next=rootserver, prev=NULL; if (next) next->prev=this; rootserver=this; ident=strdup(i), name=strdup(n), email=strdup(e), hostname=strdup(h); version=strdup(v), flags=fl, packetdrops=0, location=strdup(l); path=NULL, hops=-1, pcount=-1, lag=-1; alive=mtime(); }
/** Checks the last modified date and if necessary updates the * list of addons. * \param xml The news xml file which contains the data about * the addon list. * \param filename The filename of the news xml file. Only needed * in case of an error (e.g. it might contain a corrupted * url) - the file will be deleted so that on next start * of stk it will be updated again. * \return curl error code (esp. CURLE_OK if no error occurred) */ CURLcode NetworkHttp::loadAddonsList(const XMLNode *xml, const std::string &filename) { std::string addon_list_url(""); Time::TimeType mtime(0); const XMLNode *include = xml->getNode("include"); if(include) { include->get("file", &addon_list_url); int64_t tmp; include->get("mtime", &tmp); mtime = tmp; } if(addon_list_url.size()==0) { file_manager->removeFile(filename); news_manager->addNewsMessage(_("Can't access stkaddons server...")); // Use a curl error code here: return CURLE_COULDNT_CONNECT; } bool download = mtime > UserConfigParams::m_addons_last_updated; if(!download) { std::string filename=file_manager->getAddonsFile("addons.xml"); if(!file_manager->fileExists(filename)) download = true; } Request r(Request::HC_DOWNLOAD_FILE, 9999, false, addon_list_url, "addons.xml"); CURLcode status = download ? downloadFileInternal(&r) : CURLE_OK; if(status==CURLE_OK) { std::string xml_file = file_manager->getAddonsFile("addons.xml"); if(download) UserConfigParams::m_addons_last_updated=Time::getTimeSinceEpoch(); const XMLNode *xml = new XMLNode(xml_file); addons_manager->initOnline(xml); if(UserConfigParams::logAddons()) printf("[addons] Addons manager list downloaded\n"); return status; } // Aborted by STK in progress callback, don't display error message if(status==CURLE_ABORTED_BY_CALLBACK) return status; printf("[addons] Error on download addons.xml: %d\n", status); return status; } // loadAddonsList
/* * The DMA2D device can copy memory to memory, so in this case * we have another frame buffer with just the background in it. * And that is copied from there to the main display. It happens * faster than the tight loop fill but slightly slower than the * register to memory fill. */ void dma2d_bgfill(void) { #ifdef MEMORY_BENCHMARK uint32_t t1, t0; #endif if (DMA2D_ISR & DMA2D_ISR_CEIF) { DMA2D_IFCR |= 0x3F; if (DMA2D_ISR & DMA2D_ISR_CEIF) { printf("Failed to clear configuration error\n"); while (1); } } #ifdef MEMORY_BENCHMARK t0 = mtime(); #endif DMA2D_CR = DMA2D_SET(CR, MODE, DMA2D_CR_MODE_M2M); /* no change in alpha, same color mode, no CLUT */ DMA2D_FGPFCCR = 0x0; DMA2D_FGMAR = (uint32_t) BACKGROUND_FB; DMA2D_FGOR = 0; /* full screen */ DMA2D_OOR = 0; DMA2D_NLR = DMA2D_SET(NLR, PL, 800) | 480; /* 480 lines */ DMA2D_OMAR = (uint32_t) FRAMEBUFFER_ADDRESS; /* kick it off */ DMA2D_CR |= DMA2D_CR_START; while ((DMA2D_CR & DMA2D_CR_START)); if (DMA2D_ISR & DMA2D_ISR_CEIF) { printf("Configuration error!\n"); while (1); } #ifdef MEMORY_BENCHMARK t1 = mtime(); printf("Transfer rate (M2M) %6.2f MB/sec\n", 1464.84 / (float) (t1 - t0)); #endif }
void Link::merge(Link&& other) { if (other.mtime() > mtime()) { if ( ! (other._tsocket == TransportSocket::no_socket()) ) { assert(_tsocket == TransportSocket::no_socket() || _tsocket == other._tsocket); // FIXME: is this possible? What should we actually do then? _tsocket = other._tsocket; } if (other._promise) std::swap(_promise, other._promise); std::swap(_left_id, other._left_id); std::swap(_right_id, other._right_id); std::swap(_mtime, other._mtime); std::swap(_operational, other._operational); } }
bool check_age(struct target * aim, struct name * dependencies) { struct timespec t1 = mtime(aim->name); // target struct timespec t2 = mtime(dependencies->name); // source if (t2.tv_sec == 0){ fprintf(stderr,"./hake: no rule to make %s, needed by %s. Stopping\n", dependencies->name,aim->name); exit(EXIT_FAILURE); } if (t1.tv_sec == 0){ if(verbose > 0) printf("target %s does not exist\n",aim->name); return true; // target does not exist } if(verbose > 0){ printf("target %s made at %u.%u; dependency %s made at %u.%u\n", aim->name,(unsigned int)t1.tv_sec,(unsigned int)t1.tv_nsec, dependencies->name,(unsigned int)t2.tv_sec,(unsigned int)t2.tv_nsec); } if (t1.tv_sec < t2.tv_sec // target is older than source || ((t1.tv_sec == t2.tv_sec) && (t1.tv_nsec < t2.tv_nsec))) return true; return false; }
void sysinterface::receivepong(char *from, char *data, char *pc, char *hops) { int fd; absuser *temp; time_t now; if (sscanf(data,"%d %lu",&fd,&now)!=2) return; if (fd==-1) return; for (temp=rootuser;temp;temp=temp->next) if (temp->fd==fd) { temp->uprintf("\r\nPONG received from %s: %d seconds (%s,%s)\r\n", from, mtime()-now, pc, hops); temp->printprompt(); return; } }
static void register_watch(char* watch) { if(watch_count == MAX_WATCHES) die("Too many watches defined."); Watch* p_watch = watches + (watch_count++); p_watch->path = watch; char* colon = strrchr(watch, ':'); if(colon) { *colon++ = 0; p_watch->sig = action_by_name(colon); } else { p_watch->sig = SIGKILL; } p_watch->recent_mtime = mtime(p_watch->path); }
file_entry file_storage::at(int index) const { TORRENT_ASSERT(index >= 0 && index < int(m_files.size())); file_entry ret; internal_file_entry const& ife = m_files[index]; ret.path = file_path(ife); ret.offset = ife.offset; ret.size = ife.size; ret.file_base = file_base(ife); ret.mtime = mtime(ife); ret.pad_file = ife.pad_file; ret.hidden_attribute = ife.hidden_attribute; ret.executable_attribute = ife.executable_attribute; ret.symlink_attribute = ife.symlink_attribute; if (ife.symlink_index >= 0) ret.symlink_path = symlink(ife); ret.filehash = hash(ife); return ret; }
int poclidek_save_installedcache(struct poclidek_ctx *cctx, struct pkgdir *pkgdir) { time_t mtime_rpmdb, mtime_dbcache; char rpmdb_path[PATH_MAX], dbcache_path[PATH_MAX], dbpath[PATH_MAX]; const char *path; struct poldek_ts *ts = cctx->ctx->ts; /* for short */ if (!pm_dbpath(cctx->ctx->pmctx, dbpath, sizeof(dbpath))) return 1; if (mkrpmdb_path(rpmdb_path, sizeof(rpmdb_path), ts->rootdir, dbpath) == NULL) return 1; mtime_rpmdb = pm_dbmtime(cctx->ctx->pmctx, rpmdb_path); if (mtime_rpmdb > cctx->ts_dbpkgdir) /* db changed outside poldek */ return 1; if (pkgdir_is_type(pkgdir, RPMDBCACHE_PDIRTYPE)) path = pkgdir->idxpath; else path = mkdbcache_path(dbcache_path, sizeof(dbcache_path), ts->cachedir, pkgdir->idxpath); if (path == NULL) return 0; if (mtime_rpmdb <= cctx->ts_dbpkgdir) { /* not touched, check cache */ mtime_dbcache = mtime(path); if (mtime_dbcache && mtime_dbcache >= cctx->ts_dbpkgdir) return 1; } DBGF("path = %s, %s, %d, %d, %d\n", path, pkgdir->idxpath, mtime_rpmdb, pkgdir->ts, mtime_dbcache); n_assert(*path != '\0'); n_assert(strlen(path) > 10); DBGF("%s %s, %d %d\n", ts->cachedir, path, mtime_rpmdb, cctx->ts_dbpkgdir); return pkgdir_save_as(pkgdir, RPMDBCACHE_PDIRTYPE, path, PKGDIR_CREAT_NOPATCH | PKGDIR_CREAT_NOUNIQ | PKGDIR_CREAT_MINi18n | PKGDIR_CREAT_NOFL); }
void SDLview::drawFPS(void) { static double th[4] = {0.0, 0.0, 0.0, 0.0}; static double t1 = 0.0, t2 = 0.0, t; char num_str[128]; t1 = t2; if(Timing) { t2 = mtime(); t = t2 - t1; if(t > 0.0001) t = 1.0 / t; glDisable(GL_LIGHTING); glDisable(GL_TEXTURE_2D); glDisable(GL_DEPTH_TEST); glColor3f(1.0, 1.0, 1.0); glMatrixMode (GL_PROJECTION); glLoadIdentity(); glOrtho(0, w_win, 0, h_win, -10.0, 10.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glRasterPos2f(w_win-100.0, 15.0); sprintf(num_str, "%0.2f FPS", filter(t, th)); DrawStr(num_str); glMatrixMode(GL_MODELVIEW); glEnable(GL_LIGHTING); glEnable(GL_DEPTH_TEST); } count++; }
ulong timeof(char *name, int force) { Symtab *sym; ulong t; if(utfrune(name, '(')) return atimeof(force, name); /* archive */ if(force) return mtime(name); sym = symlook(name, S_TIME, 0); if (sym) return sym->u.value; /* uggh */ t = mkmtime(name, 0); if(t == 0) return 0; symlook(name, S_TIME, (void*)t); /* install time in cache */ return t; }
t_file *annexe_rdata(char *filename, char *path, struct stat buf) { t_file *file; if ((file = (t_file*)malloc(sizeof(*file))) == NULL) return (NULL); if ((file->name = ft_strdup(filename)) == NULL) return (NULL); if (rstat(path, filename, &file, buf) == -1) return (NULL); if (perm(buf.st_mode, &file) == -1) return (NULL); if ((file->date = mtime(&buf.st_mtime)) == NULL) return (NULL); file->rec = NULL; file->path = NULL; file->slink = NULL; file->logerror = NULL; file->time = buf.st_mtime; file->size = buf.st_size; file->link = buf.st_nlink; file->block = buf.st_blocks; return (file); }
bool fal_stats( const String &filename, FileStat &sts ) { String fname = filename; Path::uriToWin( fname ); AutoWString wBuffer( fname ); // First, determine if the file exists if( filename.size() > 0 && filename.getCharAt(filename.length()-1) != '.' ) { WIN32_FIND_DATAW wFindData; HANDLE hFound = FindFirstFileW( wBuffer.w_str(), &wFindData ); if( hFound == INVALID_HANDLE_VALUE ) { if( GetLastError() == ERROR_CALL_NOT_IMPLEMENTED ) { WIN32_FIND_DATAA aFindData; AutoCString cBuffer( fname ); hFound = FindFirstFileA( cBuffer.c_str(), &aFindData ); if ( hFound == INVALID_HANDLE_VALUE ) return false; FindClose( hFound ); // check case sensitive String ffound(aFindData.cFileName); if( fname.subString( fname.length() - ffound.length() ) != ffound ) return false; } else return false; } FindClose( hFound ); // Then, see if the case matches. String ffound(wFindData.cFileName); if( fname.subString( fname.length() - ffound.length() ) != ffound ) return false; } // ok, file exists and with matching case HANDLE temp = CreateFileW( wBuffer.w_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL ); if( (temp == INVALID_HANDLE_VALUE || temp == 0) && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED ) { AutoCString cBuffer( fname ); temp = CreateFile( cBuffer.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL ); } if( temp == INVALID_HANDLE_VALUE ) { // on win 95/98, we can't normally access directory data. DWORD attribs = GetFileAttributesW( wBuffer.w_str() ); if( attribs == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED ) { AutoCString cBuffer( fname ); attribs = GetFileAttributes( cBuffer.c_str() ); } if( attribs == INVALID_FILE_ATTRIBUTES ) { return false; } if( (attribs & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY ) { sts.m_type = FileStat::t_dir; sts.m_attribs = attribs; sts.m_size = 0; sts.m_mtime = new TimeStamp(); sts.m_atime = new TimeStamp(); sts.m_ctime = new TimeStamp(); sts.m_owner = 0; /* user ID of owner */ sts.m_group = 0; /* group ID of owner */ return true; } return false; } BY_HANDLE_FILE_INFORMATION info; memset( &info, 0, sizeof( info ) ); GetFileInformationByHandle( temp, &info ); if( info.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY ) sts.m_type = FileStat::t_dir; else sts.m_type = FileStat::t_normal; FILETIME local_timing; SYSTEMTIME timing; FileTimeToLocalFileTime( &info.ftCreationTime, &local_timing ); FileTimeToSystemTime( &local_timing, &timing ); WinSystemTime mtime( timing ); if ( sts.m_ctime == 0 ) sts.m_ctime = new TimeStamp(); sts.m_ctime->fromSystemTime( mtime ); FileTimeToLocalFileTime( &info.ftLastAccessTime, &local_timing ); FileTimeToSystemTime( &local_timing, &mtime.m_time ); if ( sts.m_atime == 0 ) sts.m_atime = new TimeStamp(); sts.m_atime->fromSystemTime( mtime ); FileTimeToLocalFileTime( &info.ftLastWriteTime, &local_timing ); FileTimeToSystemTime( &local_timing, &mtime.m_time ); if ( sts.m_mtime == 0 ) sts.m_mtime = new TimeStamp(); sts.m_mtime->fromSystemTime( mtime ); sts.m_size = info.nFileSizeHigh; sts.m_size = sts.m_size << 32 | info.nFileSizeLow; sts.m_attribs = info.dwFileAttributes; sts.m_owner = 0; /* user ID of owner */ sts.m_group = 0; /* group ID of owner */ CloseHandle( temp ); return true; }
/* * check the watch. Returns trueish if the watches mtime has changed. */ static int run_watch(Watch* p_watch) { int recent_mtime = p_watch->recent_mtime; p_watch->recent_mtime = mtime(p_watch->path); return recent_mtime != p_watch->recent_mtime; }