xref: /original-bsd/usr.bin/pascal/libpc/REMOVE.c (revision 9d44dd09)
1 /* Copyright (c) 1979 Regents of the University of California */
2 
3 static char sccsid[] = "@(#)REMOVE.c 1.3 06/10/81";
4 
5 #include "h00vars.h"
6 
7 REMOVE(name, namlim)
8 
9 	char			*name;
10 	long			namlim;
11 {
12 	register int	cnt;
13 	register int	maxnamlen = namlim;
14 	char		namebuf[NAMSIZ];
15 
16 	/*
17 	 * trim trailing blanks, and insure that the name
18 	 * will fit into the file structure
19 	 */
20 	for (cnt = 0; cnt < maxnamlen; )
21 		if (name[cnt] == '\0' || name[cnt++] == ' ')
22 			break;
23 	if (cnt >= NAMSIZ) {
24 		ERROR("%s: File name too long\n", name);
25 		return;
26 	}
27 	maxnamlen = cnt;
28 	/*
29 	 * put the name into the buffer with null termination
30 	 */
31 	for (cnt = 0; cnt < maxnamlen; cnt++)
32 		namebuf[cnt] = name[cnt];
33 	namebuf[cnt] = '\0';
34 	/*
35 	 * unlink the file
36 	 */
37 	if (unlink(namebuf)) {
38 		PERROR("Could not remove ", namebuf);
39 		return;
40 	}
41 }
42