static int IsDATNewer (char *IniFile, char *DatFile) { int ihandle, dhandle, result; struct ftime itime, dtime; ihandle = open (IniFile, O_RDONLY); if (ihandle == -1) return FALSE; dhandle = open (DatFile, O_RDONLY); if (dhandle == -1) { close (ihandle); return FALSE; } if (getftime (ihandle, &itime) == -1) return CloseFiles (ihandle, dhandle); if (getftime (dhandle, &dtime) == -1) return CloseFiles (ihandle, dhandle); if (dtime.ft_year > itime.ft_year) result = TRUE; else if (dtime.ft_year < itime.ft_year) result = FALSE; else if (dtime.ft_month > itime.ft_month) result = TRUE; else if (dtime.ft_month < itime.ft_month) result = FALSE; else if (dtime.ft_day > itime.ft_day) result = TRUE; else if (dtime.ft_day < itime.ft_day) result = FALSE; else if (dtime.ft_hour > itime.ft_hour) result = TRUE; else if (dtime.ft_hour < itime.ft_hour) result = FALSE; else if (dtime.ft_min > itime.ft_min) result = TRUE; else if (dtime.ft_min < itime.ft_min) result = FALSE; else if (dtime.ft_tsec > itime.ft_tsec) result = TRUE; else result = FALSE; CloseFiles (ihandle, dhandle); return result; }
void truncate(char *fname) { #ifdef __TURBOC__ struct ftime Ftime; #else unsigned short date, time; #endif fd = open(fname, O_WRONLY); #ifdef __TURBOC__ /* Save the time/date */ getftime(fd, &Ftime); #else GETFTIME(fd, (FTIME_T *)&date, (FTIME_T *)&time); #endif chsize(fd, 0L); /* Truncate the file */ #ifdef __TURBOC__ /* Restore the time/date */ setftime(fd, &Ftime); #else SETFTIME(fd, (FTIME_T)date, (FTIME_T)time); #endif close(fd); }
int check_filetime(const char *fn, FILETIME *ft) { FILETIME t0; if (getftime (fn, &t0) && CompareFileTime(&t0, ft) > 0) { *ft = t0; return TRUE; } return FALSE; }
int main( int argc, char **argv ) { glutInit( &argc, argv ); glutInitWindowSize( 600, 600 ); /* glutInitDisplayMode must be called before glutCreateWindow, flags are prefixed with GLUT_ not GL */ glutInitDisplayMode( GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE ); glutCreateWindow( "Depth Buffer" ); glutDisplayFunc( display ); /* register glutPostRedisplay for continuous animation */ glutIdleFunc(glutPostRedisplay); lasttime = getftime(); glutMainLoop( ); }
void display( void ) { int width, height; double finishtime, delta_t; static float angle = 0; width = glutGet(GLUT_WINDOW_WIDTH); height = glutGet(GLUT_WINDOW_HEIGHT); glClearColor( 0.5, 0.5, 0.5, 1.0 ); /* combine the clearing flags for more efficient operation */ glClear( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT ); glViewport(0, 0, width, height); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); gluPerspective( 90, (float)width/(float)height, 1, 12 ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); gluLookAt( 0, 4, 4, 0, 0, 0, 0, 1, 0 ); glEnable( GL_DEPTH_TEST ); glRotated( angle, 1, 0, 0 ); glColor3f( 1, 0, 0 ); glutSolidSphere( 1, 20, 20 ); glColor3f( 0.8, 0.8, 0 ); glutWireSphere( 1, 20, 20 ); glColor3f( 0, 0, 1 ); glutSolidTorus( 1, 2, 40, 40 ); glDisable( GL_DEPTH_TEST ); glutSwapBuffers(); finishtime = getftime(); delta_t = finishtime - lasttime; angle = fmodf(angle + 10*delta_t, 360); lasttime = finishtime; }
int main(int argc, char *argv[]) { int fd0, fd1; #ifdef __TURBOC__ struct ftime Ftime; #else unsigned date, time; #endif if (3 > argc) { puts("Usage: SETIMETO old_filename new_filename"); return EXIT_FAILURE; } if (-1 == (fd0 = open(argv[1], O_RDONLY))) { printf("Unable to open %s\n", argv[1]); return EXIT_FAILURE; } #ifdef __TURBOC__ /* Save the time/date */ getftime(fd0, &Ftime); #else GETFTIME(fd0, &date, &time); #endif if (-1 == (fd1 = open(argv[2], O_WRONLY))) { printf("Unable to open %s\n", argv[2]); return EXIT_FAILURE; } #ifdef __TURBOC__ /* Set the time/date */ setftime(fd1, &Ftime); #else SETFTIME(fd1, date, time); #endif close(fd0); close(fd1); return EXIT_SUCCESS; }
void copydate(const char *srcfile, const char *dstfile) { int srchandle=open(srcfile,O_RDONLY); if(srchandle<0) { fprintf(stderr,"%s: could not open %s\n",PROGNAME,srcfile); exit(5); } struct ftime dt; if(getftime(srchandle,&dt)) { fprintf(stderr,"%s: could get date of %s\n",PROGNAME,srcfile); exit(5); } close(srchandle); int dsthandle=open(dstfile,O_RDONLY); if(srchandle<0) { fprintf(stderr,"%s: could not open %s\n",PROGNAME,dstfile); exit(5); } if(setftime(dsthandle,&dt)) { fprintf(stderr,"%s: could set date of %s\n",PROGNAME,dstfile); exit(5); } close(dsthandle); }
long FName::TimeStamp() { #ifdef WIN32 HANDLE f=CreateFile(Str,GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL); if (f==INVALID_HANDLE_VALUE) return -1; FILETIME ft; GetFileTime(f,NULL,NULL,&ft); WORD Date,Time; FileTimeToDosDateTime(&ft,&Date,&Time); CloseHandle(f); return Time+(Date<<16); #else int hand; union Time { ftime ft; unsigned long dw; } ft; if ((hand=open(Str,O_RDONLY))<0) return -1; getftime(hand,&ft.ft); close(hand); return ft.dw; #endif }
int YMODEMCLASS::WriteHeaderBlock (void) { ftime ft ; struct tm t ; char drive[10] ; char dir[50] ; char name[256] ; char ext[10] ; long fileLength ; int i ; fltr_state = WAIT_ACK ; lpBuffer[0] = SOH ; lpBuffer[1] = 0 ; lpBuffer[2] = 0xff ; for (i=3; i<133; i++) ; lpBuffer[i] = 0 ; if (fileCount>0) { fnsplit (filename, drive, dir, name, ext) ; strcat (name,ext) ; fileLength = SetFilePointer (hFile, 0, 2) ; SetFilePointer (hFile, 0, 0) ; getftime(hFile, &ft) ; t.tm_sec = ft.ft_tsec*2 ; t.tm_min = ft.ft_min ; t.tm_hour= ft.ft_hour ; t.tm_mday= ft.ft_day ; t.tm_mon = ft.ft_month - 1 ; t.tm_year= ft.ft_year +80 ; t.tm_isdst= FALSE ; putenv("TZ=GMT0GMT") ; tzset() ; sprintf (lpBuffer+3, "%s%c%ld %lo 0", filename, 0x00, fileLength, mktime(&t)) ; } else lpBuffer[3] = '\0' ; nTransSize = 132 ; if (fCRC) { nTransSize = 133 ; int vCRC = CalcCRC16(&lpBuffer[DATA_OFFSET], 128) ; lpBuffer[CHK_OFFSET] = HIBYTE (vCRC) ; lpBuffer[CHK_OFFSET+1] =LOBYTE(vCRC) ; } else lpBuffer[CHK_OFFSET] = CheckSum (&lpBuffer[DATA_OFFSET]) ; CommPutBuffer (oiConn, (BYTE*)lpBuffer, nTransSize) ; if (Status) { lstrcpy(lpStatus->filename, name) ; lpStatus->filesize = fileLength ; lpStatus->error = lErrorCount ; lpStatus->blocksize +=128 ; lpStatus->UpdateStatusWindow () ; if (lpStatus->transferStop) return (FT_LOCALCANCEL) ; } if (fileCount<=0) return (FT_FILEEND) ; else return (FT_SUCCESS) ; }
//analyza PPP logu -> ziskani IP adresy //!!JdS: 2003/12/7 { // Rewritten so that 'ppplogtime' can also be initialized when // using BOOTP via a dial-up connection. See also ArachneTCPIP(). //!!JdS: 2003/12/7 } int PPPlog(void) { int f,i,j; char *p; struct ftime ft; struct time d_time; struct date d_date; f=sopen("PPP.LOG",O_RDONLY|O_TEXT,SH_COMPAT, S_IREAD); if (f>=0) { if (ipmode==MODE_PPP) { long l=a_filelength(f); int plen; char buf[LOGLEN]; if (l>LOGLEN) l=LOGLEN; lseek(f,-l,SEEK_END); i=read(f,buf,(int)l); buf[i]='\0'; //puts(buf); j=0; p=configvariable(&ARACHNEcfg,"IP_Grab",NULL); if (!p) p="IP address set to"; plen=strlen(p); while(j<i) { if (!strncmp(&buf[j],p,plen)) { char tecka=0; p=strchr(&buf[j],'\n'); if (p) *p='\0'; outs(&buf[j]); i=0; j+=plen; while(buf[j]==' ')j++; while(i<19 && (buf[j+i]>='0' && buf[j+i]<='9' || buf[j+i]=='.' && tecka<3)) { myIPstr[i]=buf[j+i]; if (myIPstr[i]=='.') tecka++; i++; } myIPstr[i]='\0'; my_ip_addr = resolve(myIPstr); break; } j++; } } //determine time online: if (my_ip_addr || ipmode==MODE_BOOTP) { getftime(f, &ft); d_date.da_year=ft.ft_year+1980; /* current year */ d_date.da_day=ft.ft_day; /* day of the month */ d_date.da_mon=ft.ft_month; /* month (1 = Jan) */ d_time.ti_min=ft.ft_min; /* minutes */ d_time.ti_hour=ft.ft_hour; /* hours */ d_time.ti_hund=0; /* hundredths of seconds */ d_time.ti_sec=ft.ft_tsec*2; /* seconds */ //ppplogtime is by default zero... ppplogtime = dostounix(&d_date, &d_time); } close(f); return(my_ip_addr || ipmode==MODE_BOOTP); } //puts(MSG_NOIP); return(0); }
void do_one_file(const char *iname, char *oname) { int r; struct stat st; memset(&st, 0, sizeof(st)); #if (HAVE_LSTAT) r = lstat(iname, &st); #else r = stat(iname, &st); #endif if (r != 0) { if (errno == ENOENT) throw FileNotFoundException(iname, errno); else throwIOException(iname, errno); } if (!(S_ISREG(st.st_mode))) throwIOException("not a regular file -- skipped"); #if defined(__unix__) // no special bits may be set if ((st.st_mode & (S_ISUID | S_ISGID | S_ISVTX)) != 0) throwIOException("file has special permissions -- skipped"); #endif if (st.st_size <= 0) throwIOException("empty file -- skipped"); if (st.st_size < 512) throwIOException("file is too small -- skipped"); if (!mem_size_valid_bytes(st.st_size)) throwIOException("file is too large -- skipped"); if ((st.st_mode & S_IWUSR) == 0) { bool skip = true; if (opt->output_name) skip = false; else if (opt->to_stdout) skip = false; else if (opt->backup) skip = false; if (skip) throwIOException("file is write protected -- skipped"); } InputFile fi; fi.st = st; fi.sopen(iname, O_RDONLY | O_BINARY, SH_DENYWR); #if (USE_FTIME) struct ftime fi_ftime; memset(&fi_ftime, 0, sizeof(fi_ftime)); if (opt->preserve_timestamp) { if (getftime(fi.getFd(), &fi_ftime) != 0) throwIOException("cannot determine file timestamp"); } #endif // open output file OutputFile fo; if (opt->cmd == CMD_COMPRESS || opt->cmd == CMD_DECOMPRESS) { if (opt->to_stdout) { if (!fo.openStdout(1, opt->force ? true : false)) throwIOException("data not written to a terminal; Use '-f' to force."); } else { char tname[ACC_FN_PATH_MAX+1]; if (opt->output_name) strcpy(tname,opt->output_name); else { if (!maketempname(tname, sizeof(tname), iname, ".upx")) throwIOException("could not create a temporary file name"); } if (opt->force >= 2) { #if (HAVE_CHMOD) r = chmod(tname, 0777); IGNORE_ERROR(r); #endif r = unlink(tname); IGNORE_ERROR(r); } int flags = O_CREAT | O_WRONLY | O_BINARY; if (opt->force) flags |= O_TRUNC; else flags |= O_EXCL; int shmode = SH_DENYWR; #if defined(__MINT__) flags |= O_TRUNC; shmode = O_DENYRW; #endif // cannot rely on open() because of umask //int omode = st.st_mode | 0600; int omode = 0600; if (!opt->preserve_mode) omode = 0666; fo.sopen(tname,flags,shmode,omode); // open succeeded - now set oname[] strcpy(oname,tname); } } // handle command PackMaster pm(&fi, opt); if (opt->cmd == CMD_COMPRESS) pm.pack(&fo); else if (opt->cmd == CMD_DECOMPRESS) pm.unpack(&fo); else if (opt->cmd == CMD_TEST) pm.test(); else if (opt->cmd == CMD_LIST) pm.list(); else if (opt->cmd == CMD_FILEINFO) pm.fileInfo(); else throwInternalError("invalid command"); // copy time stamp if (opt->preserve_timestamp && oname[0] && fo.isOpen()) { #if (USE_FTIME) r = setftime(fo.getFd(), &fi_ftime); IGNORE_ERROR(r); #elif (USE__FUTIME) struct _utimbuf u; u.actime = st.st_atime; u.modtime = st.st_mtime; r = _futime(fo.getFd(), &u); IGNORE_ERROR(r); #endif } // close files fo.closex(); fi.closex(); // rename or delete files if (oname[0] && !opt->output_name) { // FIXME: .exe or .cof etc. if (!opt->backup) { #if (HAVE_CHMOD) r = chmod(iname, 0777); IGNORE_ERROR(r); #endif File::unlink(iname); } else { // make backup char bakname[ACC_FN_PATH_MAX+1]; if (!makebakname(bakname, sizeof(bakname), iname)) throwIOException("could not create a backup file name"); File::rename(iname,bakname); } File::rename(oname,iname); } // copy file attributes if (oname[0]) { oname[0] = 0; const char *name = opt->output_name ? opt->output_name : iname; UNUSED(name); #if (USE_UTIME) // copy time stamp if (opt->preserve_timestamp) { struct utimbuf u; u.actime = st.st_atime; u.modtime = st.st_mtime; r = utime(name, &u); IGNORE_ERROR(r); } #endif #if (HAVE_CHMOD) // copy permissions if (opt->preserve_mode) { r = chmod(name, st.st_mode); IGNORE_ERROR(r); } #endif #if (HAVE_CHOWN) // copy the ownership if (opt->preserve_ownership) { r = chown(name, st.st_uid, st.st_gid); IGNORE_ERROR(r); } #endif } UiPacker::uiConfirmUpdate(); }
static int inner_copy( const char *src, const char *dst, int replaceOk) { int in = -1, out = -1; // file handles int result = -1; // default to error int bufsize = 0; void *buf = NULL; for(bufsize=0x4000; buf == NULL && bufsize >= 128; bufsize /= 2) buf = malloc(bufsize); if (buf==NULL) { /* no errors allowed here! */ static char dummy[4]; buf = dummy; bufsize = 4; } in = open(src,O_RDONLY|O_BINARY); if (in >= 0) { out = open(dst, O_BINARY | O_CREAT | O_RDWR | (replaceOk ? O_TRUNC : O_EXCL), S_IREAD|S_IWRITE); if (out >= 0) { int lastwrite, nbytes; while ((nbytes = read(in, buf, bufsize)) > 0) { lastwrite = write(out, buf, nbytes); if (lastwrite==-1) break; } if (lastwrite>=0) { #ifdef _WIN32 struct _timeb ftime; #else struct ftime ftime; #endif getftime(in,&ftime); setftime(out,&ftime); result = 0; } else mydir_errno = WRITE_ERROR; close(out); // put this here so if fail 'cause of existence, // we don't remove the unreplaced file! // also, the file must be closed to remove if (result) remove(dst); } else { mydir_errno = DST_OPEN_ERROR; switch(errno) { case EEXIST: mydir_errno = DST_ALREADY_EXIST; break; } } close(in); } else { mydir_errno = SRC_OPEN_ERROR; switch(errno) { case ENOENT: mydir_errno = SRC_NO_EXIST; break; } } assert(buf); if (bufsize != 4) free(buf); return result; }
int scan(char *filename) { struct tifile *ff; int handle; longint fdrtotalbytes; longint totalbytes; longint databytes; struct fdrstruc *fdr; char name[14]; word oldsize; struct ftime ftime; byte type,len; SAY printf("Scanning file %s\n",filename); if (!openti(filename,&handle)) { tierror(filename); return 0; } ff=&tifiles[handle]; getftime(ff->doshandle,&ftime); // Check FDR structure. fdr=&ff->fdr; type=fdr->flags; len=fdr->reclen; if (!validatename(fdr->name)) { if (fix) { getname(fdr->name,name); memcpy(fdr->name,name+2,10); } } if (!(type&F_PROGRAM) && len==0) { printf("Invalid record length (0)\n"); if (fix) { if (fdr->recspersec==1) len=255; // good guess for xxx/FIX else if (fdr->recspersec>1) len=256/fdr->recspersec; // very approx else len=80; // pure guess // For fixed files, we can tell what the record size is: // * EOF offset is exact multiple // * (256*secsused-EOF)/fixrecs is almost it if (!(type&F_VARIABLE) && fdr->fixrecs) { len=(256L*(swapbytes(fdr->secsused)+1)-fdr->eof) / fdr->fixrecs; if (fdr->eof) while (len%fdr->eof) len--; } if (!len) len=80; printf("\tAssume %d bytes?\n",len); if (getyesorno()) fdr->reclen=len; } } fdrtotalbytes=tigetfilesize(handle); totalbytes=tigetrealfilesize(handle); if ((fdrtotalbytes+255)/256!=totalbytes/256) { printf("File size mismatch in %s\n",filename); printf("TI Emulator! v5.0- probably made this error.\n"); if (fix) { if ((type&F_VARIABLE) && !(type&F_PROGRAM)) // xxx/VAR { fdr->fixrecs=totalbytes/256; fdr->secsused=swapbytes(fdr->fixrecs); } else if (type&F_PROGRAM) // program { // On a program file, most likely the FDR is // correct while the filesize is wrong. Sheesh! // if (fdrtotalbytes<totalbytes) if (!ff->doad) trunc(handle,swapbytes(fdr->secsused)); else ; else { fdr->secsused=swapbytes(totalbytes/256); fdr->eof=totalbytes&255; } } else if (!(type&F_VARIABLE)) // xxx/FIX { // reclen is assumed to be legal from above // oldsize=fdr->secsused; fdr->secsused=swapbytes( (fdr->fixrecs+fdr->recspersec-1)/fdr->recspersec); if (oldsize==fdr->secsused && !ff->doad) trunc(handle,swapbytes(oldsize)); } } } if (fix) { // printf("Fixing...\n"); if (!writetifdr(handle)) printf("Error! Couldn't write header!\n"); else setftime(ff->doshandle,&ftime); } closeti(handle); return 1; }