long change_mint(char *now,char *to) { long ok1,ok2; ok1 = Frename(0,additnam,now); if (ok1 == 0) ok2 = Frename(0,to,additnam); if (ok1) printf("rename from additional failed: %d\n",ok1); if (ok2) printf("rename to additional failed: %d\n",ok2); return end_ren(ok1|ok2,now,to); }
long change_auto(char *now, char *to) { long ok1,ok2; ok1 = Frename(0,autonam,now); /* existing auto to what's in it */ if (ok1 == 0) ok2 = Frename(0,to,autonam); /* given auto.ext to auto */ if (ok1) printf("rename from auto failed: %d\n",ok1); if (ok2) printf("rename to auto failed: %d\n",ok2); return end_ren(ok1|ok2,now,to); }
ex_rename() { #if DISKFLAG char fromfile[13],frompath[80]; char tofile[13],topath[80]; int hand,saveMP; if (midiplexer) saveMP=MPoff(); fromfile[0]=0; /* uses drive and path from most recent disk function */ if (getfile(frompath,fromfile,ALL_EXT,RENFRMTITL)>0) { graf_mouse(BEE_MOUSE); hand= Fopen(frompath,0); if (hand<0) big_alert(1,BADOPEN1,fromfile,BADOPEN2); else { Fclose(hand); graf_mouse(ARROWMOUSE); strcpy(tofile,fromfile); if (getfile(topath,tofile,ALL_EXT,RENTOTITL)>0) { graf_mouse(BEE_MOUSE); if (Frename(0,frompath,topath)) big_alert(1,BADRENAME1,tofile,BADRENAME2); } } } /* end if got a file from file selector */ graf_mouse(ARROWMOUSE); if (midiplexer&&saveMP) MPon(); #endif } /* end ex_rename() */
int x_rename(const char *oldname, const char *newname) { #if USE_gemdos return xerror((int) gemdos(86, 0, oldname, newname)); #else return xerror(Frename(0, oldname, newname)); #endif }
int __rename(const char *_oldname, const char *_newname) { char oldnamebuf[PATH_MAX], newnamebuf[PATH_MAX]; int rval, r; long xattr; struct stat oldstat; struct stat newstat; char* oldname = (char*) _oldname; char* newname = (char*) _newname; if (_oldname == NULL || _newname == NULL) { __set_errno (EFAULT); return -1; } if (!__libc_unix_names) { oldname = oldnamebuf; newname = newnamebuf; _unx2dos(_oldname, oldname, sizeof (oldnamebuf)); _unx2dos(_newname, newname, sizeof (newnamebuf)); } xattr = __sys_stat (newname, &newstat, 1, 0); if (xattr == 0) xattr = __sys_stat (oldname, &oldstat, 1, 0); if (xattr == 0) { /* Find some errors. FIXME: That should be done conditionally when the kernel can do that. */ /* First check: new is a directory and old isn't. */ if (S_ISDIR (newstat.st_mode) && !S_ISDIR (oldstat.st_mode)) { __set_errno (EISDIR); return -1; } /* Check if newname is a non-empty directory? What will currently happen then? This should result in ENOTEMPTY. */ /* Check for same file. */ if (newstat.st_dev == oldstat.st_dev && newstat.st_ino == oldstat.st_ino) { /* Same file. */ __set_errno (EEXIST); return -1; } } rval = Frename(0, oldname, newname); if (rval == 0) return 0; if (rval != -EXDEV && rval != -ENOENT && rval != -ENOTDIR) { if (!strcmp(newname, oldname)) { /* on inode-less filesystems do at least catch rename("foo", "foo"); */ __set_errno (EEXIST); return -1; } if (!(r = Fdelete (newname))) rval = Frename(0, oldname, newname); /* kludge for kernel versions that suffer from `too much DOS' :) i.e. * still look at the files write permission instead of the directories * even on real filesystems and when running in the MiNT domain: * if it says EACCES and the dest.dir exists try the old link/unlink way... */ if (rval == -EACCES && r != -ENOTDIR) { if (!(rval = Flink (oldname, newname))) { if ((r = Fdelete (oldname)) && r != -ENOENT && r != -ENOTDIR) { (void) Fdelete (newname); } else { rval = 0; /* alright that did it! */ } } else if (rval == -ENOSYS) { rval = -EACCES; /* filesystem doesn't know link()... */ } } } if (rval < 0) { if ((rval == -ENOTDIR) && (xattr != -ENOSYS) && (_enoent(__sys_stat (oldname, &oldstat, 1, 0) ? oldname : newname))) rval = -ENOENT; __set_errno (-rval); rval = -1; } return rval; }
WORD wrfile( char *fstr ) { REG int ret, retmsg; int inhand,outhand; int time[2]; DMABUFFER *mydta, *saved; char *buffer; long copysiz, bufsiz, wrsiz, tmpsiz; int crted,sttime; char buf[2]; crted = 0; sttime = 1; retmsg = TRUE; rename = 0; open: /* open the source file */ if ( ( inhand = (WORD)Fopen(fixsrc, 0) ) < 0 ) { /* seek error or drive not ready */ /* if ( (inhand == E_SEEK) || (inhand == EDRVNR) ) return( FALSE ); */ /* skip */ if ( ( ret = fill_string( fixsrc, CNTOPEN ) ) == 1 ) { updatnum(NUMFILE, --numfiles); return SKIP; } else if (ret == 2) /* retry */ goto open; else /* abort */ goto ww_3; } if ( !ch_undo() || f_cancel ) /* user want to stop */ { Fclose( inhand ); ww_3: f_abort = 1; return( FALSE ); } saved = (DMABUFFER *)Fgetdta(); Fsetdta(mydta=(DMABUFFER *)malloc( (long)sizeof(DMABUFFER))); if ( Fsfirst( fixsrc, 0x37 ) ) { retmsg = SKIP; if ( do1_alert( RDERROR ) == 2 ) /* abort */ { f_abort = 1; retmsg = FALSE; } goto y2; } copysiz = mydta->d_fsize; buffer = (char *)malloc( copysiz ); if ( buffer ) { bufsiz = copysiz; } else { for (bufsiz = 128*1024L; bufsiz >= 1024L; bufsiz /= 2) { if ((buffer = (char *)malloc( bufsiz )) != 0) break; } if (!buffer) goto y2; } Fdatime( &time, inhand, 0 ); /* read the time and date */ rechkd: switch(chkdf(fstr, CPFILE)) { case CHECK: goto rechkd; case SKIP: retmsg = SKIP; goto y1; case QUIT: f_abort = 1; retmsg = FALSE; goto y1; case FALSE: retmsg = FALSE; goto y1; } /* if it is move operation, then try rename first */ if ( opcode == OP_MOVE ) { /* if same name and path, don't do it */ if ( strcmp( fixsrc, fixdst ) ) goto y22; Fclose( inhand ); if ( Frename(0, fixsrc, fixdst) >= 0 ) { inhand = (WORD)Fopen( fixdst, 0 ); if ( !p_timedate ) /* get the new time and date */ { time[0] = Tgettime(); time[1] = Tgetdate(); Fdatime( &time, inhand, 1 ); } y22: rename = 1; goto y1; } else inhand = (WORD)Fopen( fixsrc, 0 ); } while ( copysiz >= 0 ) /* let it passes through for zero file */ { tmpsiz = (copysiz > bufsiz) ? bufsiz : copysiz; if (Fread(inhand, tmpsiz, buffer) < 0) { retmsg = SKIP; if ( crted ) Fdelete( fixdst ); if (do1_alert( RDERROR ) == 2) { /* abort */ f_abort = 1; retmsg = FALSE; } goto y1; /* skip */ } create: if ( sttime ) { sttime = 0; if ((outhand = (WORD)Fcreate(fixdst, mydta->d_fattr&7)) < 0) { if ( ( ret = fill_string( fixdst, CNTCRTFL ) ) == 2 ) goto create; else if (ret == 3) /* abort */ { f_abort = 1; retmsg = FALSE; } else retmsg = SKIP; goto y1; } crted = 1; } if ((wrsiz = Fwrite(outhand, tmpsiz, buffer)) < 0) { retmsg = SKIP; Fclose(outhand); Fdelete(fixdst); if (do1_alert( WRERROR ) == 2) { /* abort */ f_abort = 1; retmsg = FALSE; } goto y1; } /* check if there are sufficent memory */ if (wrsiz != tmpsiz) { /* not sufficent memory ??*/ f_abort = 1; retmsg = FALSE; Fclose(outhand); Fdelete(fixdst); buf[0] = *fixdst; buf[1] = 0; fill_string( buf, STDISKFU ); goto y1; } copysiz -= tmpsiz; if ( !copysiz ) break; } if ( p_timedate ) Fdatime( &time, outhand, 1 ); y0: Fclose(outhand); y1: free(buffer); y2: updatnum(NUMFILE, --numfiles); Fsetdta(saved); y3: Fclose(inhand); free(mydta); if ( ( opcode == OP_MOVE ) && ( retmsg == TRUE ) ) upfdesk( fixsrc, fixdst ); return(retmsg); }
/* do_rename() * ==================================================================== */ void do_rename( int curb, int curc ) { int berror; olddma = Fgetdta(); Fsetdta( &newdma ); /* Point to OUR buffer */ /* Get SOURCE */ if( cstate ) /* Protection On or Off */ { /* Memory Protection */ if( bstate ) { /* Source is MINT.PRG - Memory Protection */ strcpy( Source, OnPath ); } else { /* Source is MINT.PRX - Memory Protection */ strcpy( Source, OffPath ); } } else { /* No Memory Protection */ if( bstate ) { /* Source is MINTNP.PRG - No Memory Protection */ strcpy( Source, NPOnPath ); } else { /* Source is MINTNP.PRX - No Memory Protection */ strcpy( Source, NPOffPath ); } } /* Get Destination - Turn ON or OFF */ if( curb ) { /* Turn ON MultiTOS */ /* Get Destination */ if( curc ) { /* Memory Protection */ /* Destination is MINT.PRG - Memory Protection */ strcpy( Destination, OnPath ); } else { /* No Memory Protection */ /* Destination is MINTNP.PRG - No Memory Protection */ strcpy( Destination, NPOnPath ); } /* Do the Renaming - TURN ON MULTITOS */ berror = Frename( 0, Source, Destination ); if( berror ) { if( berror == -13 ) /* write protected */ form_alert( 1, NoWrite ); else { /* Unable to Turn On MultiTOS */ form_alert( 1, NoOn ); } } else form_alert( 1, RebootText ); } else { /* Turn Off MultiTOS */ /* Get Destination */ if( curc ) { /* Destination is MINT.PRX - Memory Protection */ strcpy( Destination, OffPath ); } else { /* Destination is MINTNP.PRX - No Memory Protection */ strcpy( Destination, NPOffPath ); } /* Turn Off MultiTOS - */ berror = Frename( 0, Source, Destination ); if( berror ) { if( berror == -13 ) /* write protected */ form_alert( 1, NoWrite2 ); else { /* Unable to Turn off MultiTOS */ form_alert( 1, NoOff ); } } else form_alert( 1, RebootText ); } Fsetdta( olddma ); /* Point to OLD buffer */ }