home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 2 BBS
/
02-BBS.zip
/
mrl1.zip
/
scan.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-09-12
|
1KB
|
57 lines
#include <stdlib.h>
#include <malloc.h>
#include <io.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <dirent.h>
#include <stdio.h>
#include <string.h>
#include "mrl.h"
int Scan(const char *dir)
{
DIR *mdir;
struct dirent *pol;
unsigned char *tmp;
if(!(tmp=malloc(MAXNAMLEN)))
{ WriteLog(logname," Malloc error in Scan",'!');return -1;}
if(!(mdir=opendir(dir)))
{
sprintf(tmp,"opendir %s failed",dir);
WriteLog(logname,tmp,'!');
free(tmp);
return -1;}
rewinddir(mdir);
while((pol=readdir(mdir)))
{
strupr(pol->d_name);
if (!strcmp("LASTREAD",pol->d_name))
{ /*Read Last-read pointer in low-hi byte order */
int i;
strcpy(tmp,dir);
strcat(tmp,"\\");
strcat(tmp,pol->d_name);
i=open(tmp,O_RDONLY|O_BINARY);
if(i!=-1) {
if(-1!=read(i,tmp,2)) toINT(tmp,&mlast);
close(i);
}
}
if (strstr(pol->d_name,".MSG"))
{
mmsgs++;
strncpy(tmp,pol->d_name,strlen(pol->d_name)-4);
*(tmp+strlen(pol->d_name)-4)='\0';
if(atoi(tmp)>mmax) {
mmax=atoi(tmp);
}
if((atoi(tmp)<mmin)&&(atoi(tmp)!=0)) mmin=atoi(tmp);
}
}
closedir(mdir);
free(tmp);
return 0;
}