Path: utzoo!attcan!uunet!mcvax!ukc!stl!stc!root44!gwc
From: gwc@root.co.uk (Geoff Clare)
Newsgroups: comp.sys.hp
Subject: Re: Compatible HP-UX 5.1 function "rename" from Berkley 4.3
Summary: Here's a simpler one
Message-ID: <641@root44.co.uk>
Date: 27 Sep 88 13:12:18 GMT
References: <908@arctic.nprdc.arpa> <541@hptsug2.HP.COM>
Reply-To: gwc@root.co.uk (Geoff Clare)
Organization: UniSoft Ltd, London, England
Lines: 37

In article <541@hptsug2.HP.COM> taylor@limbo.ptp.hp.com (Dave Taylor) writes:
>A while back, while working on porting some BSD code to HP-UX,
>I also had need for the rename() command.  What I ended up
>doing was reading the BSD man page and attempting to duplicate
>the behaviour of the command as much as possible -- I have
>attached this routine below.  
>
>Note: This comes to you with no warrantee or guarantee --- it
>worked for the application I was porting, but your milage may
>vary...
>						-- Dave Taylor
>  [ code deleted ]
>

Dave's version seems unnecessarily complex to me.  Here's the one I use:

extern int errno;

rename(src, dest)
char *src, *dest;
{
	if (link(src, dest) != 0)
		return -1;
	if (unlink(src) != 0)
	{
		int err = errno;
		(void) unlink(dest);
		errno = err;
		return -1;
	}
	return 0;
}

-- 

Geoff Clare    UniSoft Limited, Saunderson House, Hayne Street, London EC1A 9HH
gwc@root.co.uk   ...!mcvax!ukc!root44!gwc   +44-1-606-7799  FAX: +44-1-726-2750