home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / mrl1.zip / kill.c < prev    next >
C/C++ Source or Header  |  1996-01-18  |  1KB  |  47 lines

  1. #include "mrl.h"
  2. #include <malloc.h>
  3. #include <stdio.h>
  4. #include <io.h>
  5. #include <sys/types.h>
  6. #include <fcntl.h>
  7. #include <dirent.h>
  8.  
  9. int 
  10. Kill (const char *dir, const unsigned int leave)
  11. {
  12.   int todo = mmsgs - leave;
  13.   unsigned int counter = mmin;
  14.   int i;
  15.   char *tmp, *tmp2;
  16.   if (!(tmp = malloc (MAXNAMLEN)))
  17.     { WriteLog(logname," Malloc error in Kill",'!');return -1;}
  18.   if (!(tmp2 = malloc (MAXNAMLEN + 20)))
  19.     { WriteLog(logname," Malloc error in Kill",'!');return -1;} 
  20.   if (leave >= mmsgs)
  21.     return 0;            /* NothinG toDo ! */
  22.   while (todo > 0)
  23.     {
  24.       CreName (tmp, dir, counter);
  25.       i = open (tmp, O_RDONLY);
  26.       if (i != -1)        /* kill it! */
  27.     {
  28.       close (i);
  29.           sprintf(tmp2,"Deleting %s",tmp);
  30.           WriteLog(logname,tmp2,'*');
  31.       if (unlink (tmp))
  32.         {
  33.           sprintf (tmp2, " Cannot delete %s", tmp);
  34.           perror (tmp2);
  35.               WriteLog(logname,tmp2,'!');
  36.         }
  37.       todo--;
  38.     }
  39.       counter++;
  40.     }
  41.   sprintf(tmp2,"%d messages deleted.",mmsgs-leave);
  42.   WriteLog(logname,tmp2,':');
  43.   free (tmp);
  44.   free (tmp2);
  45.   return 0;
  46. }
  47.