xref: /csrg-svn/usr.bin/pascal/libpc/REMOVE.c (revision 62096)
140865Sbostic /*-
2*62096Sbostic  * Copyright (c) 1979, 1993
3*62096Sbostic  *	The Regents of the University of California.  All rights reserved.
440865Sbostic  *
540865Sbostic  * %sccs.include.redist.c%
640865Sbostic  */
71694Smckusick 
840865Sbostic #ifndef lint
9*62096Sbostic static char sccsid[] = "@(#)REMOVE.c	8.1 (Berkeley) 06/06/93";
1040865Sbostic #endif /* not lint */
111694Smckusick 
121694Smckusick #include "h00vars.h"
131694Smckusick 
REMOVE(name,namlim)143025Smckusic REMOVE(name, namlim)
151694Smckusick 
161694Smckusick 	char			*name;
173025Smckusic 	long			namlim;
181694Smckusick {
191694Smckusick 	register int	cnt;
203025Smckusic 	register int	maxnamlen = namlim;
211694Smckusick 	char		namebuf[NAMSIZ];
221694Smckusick 
231694Smckusick 	/*
241694Smckusick 	 * trim trailing blanks, and insure that the name
251694Smckusick 	 * will fit into the file structure
261694Smckusick 	 */
2716512Smckusick 	for (cnt = 0; cnt < maxnamlen; cnt++)
2816512Smckusick 		if (name[cnt] == '\0' || name[cnt] == ' ')
291694Smckusick 			break;
301694Smckusick 	if (cnt >= NAMSIZ) {
313869Smckusic 		ERROR("%s: File name too long\n", name);
321694Smckusick 		return;
331694Smckusick 	}
341694Smckusick 	maxnamlen = cnt;
351694Smckusick 	/*
361694Smckusick 	 * put the name into the buffer with null termination
371694Smckusick 	 */
381694Smckusick 	for (cnt = 0; cnt < maxnamlen; cnt++)
391694Smckusick 		namebuf[cnt] = name[cnt];
401694Smckusick 	namebuf[cnt] = '\0';
411694Smckusick 	/*
421694Smckusick 	 * unlink the file
431694Smckusick 	 */
441694Smckusick 	if (unlink(namebuf)) {
453869Smckusic 		PERROR("Could not remove ", namebuf);
461694Smckusick 		return;
471694Smckusick 	}
481694Smckusick }
49