Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!iuvax!cica!gatech!udel!mmdf From: HELMER%SDNET.BITNET@vm1.nodak.edu (Guy Helmer) Newsgroups: comp.os.minix Subject: Re: Replacement for rename()? Message-ID: <20510@louie.udel.EDU> Date: 26 Jul 89 13:22:36 GMT Sender: mmdf@udel.EDU Lines: 69 Thos Sumner writes: >In article <20454@louie.udel.EDU>, HELMER%SDNET.BITNET@vm1.nodak.edu (Guy > Helmer) writes: >> I've ported David Clunie's yacc to MINIX successfully except for >> one problem: no obvious working replacement for rename() > > system -- issue a shell command (Section 3, Unix User's Manual) > mv -- move or rename files (Section 1, Unix User's Manual) >thus > system("mv "); > Ugh... Not exactly the beautiful, simple, fast executing trick I was looking forward to seeing... >> I've tried using link(oldname, newname); unlink(oldname);, >> but link() apparently doesn't like to work over mount points even >> if the new file and old file are to exist on the same file system. > >I find this confusing: going over mount points appears to be the essence >of different file systems. What do you mean here? It is correct for >links (i.e. hard as opposed to symbolic links) not to connect between >file systems. > Under minix, link("/tmp/oldfile", "/tmp/newfile") doesn't work for me. When I tried it, this path traversed a mount point on my system, but I (apparently incorrectly) hoped that it would still work. I don't have V7 docs nor do I have real un*x to try this out, so I don't really know what is supposed to work. >> The only thing that seems to be left to do is the equivalent >> of 'cp ' and then unlink(oldname). Does anyone >I presume this should be "" --------^^^^^^^ >> have a better suggestion? Thanks in advance. > >The latter sequence is about equivalent to _mv_ for the case where >the two names refer to different filesystems (mv also sets the time >and date info on the new copy). Of course, as written the example >is mixing program execution (cp) and library call (unlink). I was thinking of writing code to do the equivalent of a 'cp', and then do the unlink(). I'm trying to avoid fork() and exec() like the plague :-) ; yacc really doesn't need to be any slower. I have a new thought, though; would link() work if I did something like this: getcwd(curpath); chdir("/tmp"); link("oldname", "newname"); unlink("oldname"); chdir(curpath); It seems to me like this would be the best replacement possible for rename on Minix. > > > Thos Sumner Internet: thos@cca.ucsf.edu > (The I.G.) UUCP: ...ucbvax!ucsfcgl!cca.ucsf!thos > BITNET: thos@ucsfcca > > U.S. Mail: Thos Sumner, Computer Center, Rm U-76, UCSF > San Francisco, CA 94143-0704 USA > >OS|2 -- an Operating System for puppets. > >#include