home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 4
/
DATAFILE_PDCD4.iso
/
unix
/
unixlib36d
/
src
/
stdio
/
c
/
rename
< prev
next >
Wrap
Text File
|
1994-03-08
|
823b
|
48 lines
static char sccs_id[] = "@(#) rename.c 1.1 " __DATE__ " HJR";
/* rename.c (c) Copyright 1990 H.Rogers */
#include <stdio.h>
#ifdef ARCH
#include <ctype.h>
#endif
extern int link (char *, char *);
extern int unlink (char *);
__STDIOLIB__
int
rename (const char *old, const char *new)
{
#ifdef ARCH /* case insensitive matching */
{
register const char *s1 = old, *s2 = new;
register int c1, c2;
while (c1 = *s1++, c2 = *s2++)
{
if (isupper (c1))
c1 = _tolower (c1);
if (isupper (c2))
c2 = _tolower (c2);
if (c1 != c2)
break;
}
if (c1 != c2)
unlink ((char *) new);
}
#else
if (!strcmp (old, new))
return (0);
unlink ((char *) new);
#endif
if (link ((char *) old, (char *) new))
return (-1);
#ifndef ARCH
unlink ((char *) old);
#endif
return (0);
}