xref: /csrg-svn/usr.bin/f77/libU77/link_.c (revision 23035)
12532Sdlw /*
2*23035Skre  * Copyright (c) 1980 Regents of the University of California.
3*23035Skre  * All rights reserved.  The Berkeley software License Agreement
4*23035Skre  * specifies the terms and conditions for redistribution.
52532Sdlw  *
6*23035Skre  *	@(#)link_.c	5.1	06/07/85
7*23035Skre  */
8*23035Skre 
9*23035Skre /*
102532Sdlw  * make a link to an existing file
112532Sdlw  *
122532Sdlw  * calling sequence:
132532Sdlw  *	ierror = link(name1, name2)
142532Sdlw  * where:
152532Sdlw  *	name1 is the pathname of an existing file
162532Sdlw  *	name2 is a pathname to be linked to file name1
172532Sdlw  *	ierror will be 0 if successful; a system error code otherwise.
182532Sdlw  */
192532Sdlw 
202532Sdlw #include "../libI77/f_errno.h"
2112144Sdlw #include <sys/param.h>
2212144Sdlw #ifndef	MAXPATHLEN
2312144Sdlw #define MAXPATHLEN	128
2412144Sdlw #endif
252532Sdlw 
262532Sdlw long link_(name1, name2, n1len, n2len)
272532Sdlw char *name1, *name2;
282532Sdlw long n1len, n2len;
292532Sdlw {
3012144Sdlw 	char buf1[MAXPATHLEN];
3112144Sdlw 	char buf2[MAXPATHLEN];
322532Sdlw 
332532Sdlw 	if (n1len >= sizeof buf1 || n2len >= sizeof buf2)
342532Sdlw 		return((long)(errno=F_ERARG));
352532Sdlw 	g_char(name1, n1len, buf1);
362532Sdlw 	g_char(name2, n2len, buf2);
3712144Sdlw 	if (buf1[0] == '\0' || buf2[0] == '\0')
382532Sdlw 		return((long)(errno=F_ERARG));
392532Sdlw 	if (link(buf1, buf2) != 0)
402532Sdlw 		return((long)errno);
412532Sdlw 	return(0L);
422532Sdlw }
43