home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 2 BBS
/
02-BBS.zip
/
mrl1.zip
/
kill.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-01-18
|
1KB
|
47 lines
#include "mrl.h"
#include <malloc.h>
#include <stdio.h>
#include <io.h>
#include <sys/types.h>
#include <fcntl.h>
#include <dirent.h>
int
Kill (const char *dir, const unsigned int leave)
{
int todo = mmsgs - leave;
unsigned int counter = mmin;
int i;
char *tmp, *tmp2;
if (!(tmp = malloc (MAXNAMLEN)))
{ WriteLog(logname," Malloc error in Kill",'!');return -1;}
if (!(tmp2 = malloc (MAXNAMLEN + 20)))
{ WriteLog(logname," Malloc error in Kill",'!');return -1;}
if (leave >= mmsgs)
return 0; /* NothinG toDo ! */
while (todo > 0)
{
CreName (tmp, dir, counter);
i = open (tmp, O_RDONLY);
if (i != -1) /* kill it! */
{
close (i);
sprintf(tmp2,"Deleting %s",tmp);
WriteLog(logname,tmp2,'*');
if (unlink (tmp))
{
sprintf (tmp2, " Cannot delete %s", tmp);
perror (tmp2);
WriteLog(logname,tmp2,'!');
}
todo--;
}
counter++;
}
sprintf(tmp2,"%d messages deleted.",mmsgs-leave);
WriteLog(logname,tmp2,':');
free (tmp);
free (tmp2);
return 0;
}