xref: /csrg-svn/usr.bin/f77/libU77/chmod_.c (revision 23006)
111928Sdlw /*
2*23006Skre  * Copyright (c) 1980 Regents of the University of California.
3*23006Skre  * All rights reserved.  The Berkeley software License Agreement
4*23006Skre  * specifies the terms and conditions for redistribution.
511928Sdlw  *
6*23006Skre  *	@(#)chmod_.c	5.1	06/07/85
7*23006Skre  */
8*23006Skre 
9*23006Skre /*
1011928Sdlw  * chmod - change file mode bits
1111928Sdlw  *
1211928Sdlw  * synopsis:
1311928Sdlw  *	integer function chmod (fname, mode)
1411928Sdlw  *	character*(*) fname, mode
1511928Sdlw  */
1611928Sdlw 
1711928Sdlw #include "../libI77/f_errno.h"
1812142Sdlw #include <sys/param.h>
1912142Sdlw #ifndef	MAXPATHLEN
2012142Sdlw #define MAXPATHLEN	128
2112142Sdlw #endif
2211928Sdlw 
2311928Sdlw long chmod_(name, mode, namlen, modlen)
2411928Sdlw char	*name, *mode;
2511928Sdlw long	namlen, modlen;
2611928Sdlw {
2712142Sdlw 	char	nambuf[MAXPATHLEN];
2811928Sdlw 	char	modbuf[32];
2911928Sdlw 	int	retcode;
3011928Sdlw 
3111928Sdlw 	if (namlen >= sizeof nambuf || modlen >= sizeof modbuf)
3211928Sdlw 		return((long)(errno=F_ERARG));
3311928Sdlw 	g_char(name, namlen, nambuf);
3411928Sdlw 	g_char(mode, modlen, modbuf);
3511928Sdlw 	if (nambuf[0] == '\0')
3611928Sdlw 		return((long)(errno=ENOENT));
3711928Sdlw 	if (modbuf[0] == '\0')
3811928Sdlw 		return((long)(errno=F_ERARG));
3911928Sdlw 	if (fork())
4011928Sdlw 	{
4111928Sdlw 		if (wait(&retcode) == -1)
4211928Sdlw 			return((long)errno);
4311928Sdlw 		return((long)retcode);
4411928Sdlw 	}
4511928Sdlw 	else
4611928Sdlw 		execl("/bin/chmod", "chmod", modbuf, nambuf, (char *)0);
4711928Sdlw }
48