void settime(int islocal, int afd, char *rp) { int n, f; Dir dir[2]; char timebuf[64]; static int timeset; if(timeset) return; print("time..."); if(islocal){ /* * set the time from the real time clock */ f = open("#r/rtc", ORDWR); if(f >= 0){ if((n = read(f, timebuf, sizeof(timebuf)-1)) > 0){ timebuf[n] = '\0'; timeset = 1; } close(f); }else do{ strcpy(timebuf, "yymmddhhmm[ss]"); outin("\ndate/time ", timebuf, sizeof(timebuf)); }while((timeset=lusertime(timebuf)) <= 0); } if(timeset == 0){ /* * set the time from the access time of the root */ f = open(timeserver, ORDWR); if(f < 0) return; if(mount(f, afd, "/tmp", MREPL, rp) < 0){ warning("settime mount"); close(f); return; } close(f); if(stat("/tmp", statbuf, sizeof statbuf) < 0) fatal("stat"); convM2D(statbuf, sizeof statbuf, &dir[0], (char*)&dir[1]); sprint(timebuf, "%ld", dir[0].atime); unmount(0, "/tmp"); } f = open("#c/time", OWRITE); if(write(f, timebuf, strlen(timebuf)) < 0) warning("can't set #c/time"); close(f); print("\n"); }
static int setlocaltime(char* timebuf, int s){ int n, f, t; t=0; f = open("#r/rtc", ORDWR); if(f >= 0){ if((n = read(f, timebuf, s-1)) > 0){ timebuf[n] = '\0'; t = 1; } close(f); }else do{ strcpy(timebuf, "yymmddhhmm[ss]"); outin("\ndate/time ", timebuf, s); }while((t=lusertime(timebuf)) <= 0); return t; }