xref: /csrg-svn/usr.bin/f77/libU77/rename_.c (revision 47944)
1*47944Sbostic /*-
2*47944Sbostic  * Copyright (c) 1980 The Regents of the University of California.
3*47944Sbostic  * All rights reserved.
412026Sdlw  *
5*47944Sbostic  * %sccs.include.proprietary.c%
623045Skre  */
723045Skre 
8*47944Sbostic #ifndef lint
9*47944Sbostic static char sccsid[] = "@(#)rename_.c	5.2 (Berkeley) 04/12/91";
10*47944Sbostic #endif /* not lint */
11*47944Sbostic 
1223045Skre /*
1312026Sdlw  * rename a file atomically
1412026Sdlw  *
1512026Sdlw  * synopsis:
1612026Sdlw  *	integer function rename (from, to)
1712026Sdlw  *	character*(*) from, to
1812026Sdlw  *
1912026Sdlw  * where:
2012026Sdlw  *	return value will be zero normally, an error number otherwise.
2112026Sdlw  */
2212026Sdlw 
2312026Sdlw #include "../libI77/f_errno.h"
2412145Sdlw #include <sys/param.h>
2512145Sdlw #ifndef	MAXPATHLEN
2612145Sdlw #define MAXPATHLEN	128
2712145Sdlw #endif
2812026Sdlw 
2912026Sdlw long
rename_(from,to,frlen,tolen)3012026Sdlw rename_ (from, to, frlen, tolen)
3112026Sdlw char	*from, *to;
3212026Sdlw long	frlen, tolen;
3312026Sdlw {
3412145Sdlw 	char	frbuf[MAXPATHLEN];
3512145Sdlw 	char	tobuf[MAXPATHLEN];
3612026Sdlw 
3712026Sdlw 	if (frlen <= 0 || tolen <= 0 || *from == ' ' || *to == ' ')
3812026Sdlw 		return ((long)(errno = F_ERARG));
3912026Sdlw 	if (frlen >= sizeof frbuf || tolen >= sizeof tobuf)
4012026Sdlw 		return ((long)(errno = F_ERARG));
4112026Sdlw 	g_char (from, frlen, frbuf);
4212026Sdlw 	g_char (to, tolen, tobuf);
4312026Sdlw 	if (rename (from, to) != 0)
4412026Sdlw 		return ((long)errno);
4512026Sdlw 	return (0L);
4612026Sdlw }
47