mv'ing files from a C program

Clifford C. Skolnick cliffs at gaffa.East.Sun.COM
Fri Nov 16 07:59:33 AEST 1990


In article <22 at mixcom.UUCP> ggvvgg at mixcom.UUCP (Dave Fenske) writes:
>Is there an easy way to do an 'mv' from a C program?
>
>I just want to be able to move a recently read file into another directory,
>and wish to avoid having to write it there.  Using the 'system' call is
>not deemed wiable for this application.
>
>DF

Do it like "mv"

int mv(oldpath, newpath)
char *oldpath, *newpath;
{
	int ret;

	if (ret = link(oldpath, newpath))
		return(ret); /* an error has occured */

	if (ret = unlink(oldpath))
		return(ret); /* gee, another error */

	return(0);
}
--
Cliff Skolnick - Technical Consultant | (716) 385-5049 | cliffs at east.sun.com
           [I only work for Sun, I do not speak for them]

         "The floggings will continue until morale improves"



More information about the Comp.unix.questions mailing list