Category : C Source Code
Archive   : GTOLS101.ZIP
Filename : PDIRECT.C

 
Output of file : PDIRECT.C contained in archive : GTOLS101.ZIP
/*
* PDIRECT.C
* 1991-12-14
*
* Lee Daniel Crocker [email protected] (uunet!mport!lee)
* 5506 Camden Ave #D3 [email protected]
* San Jose, CA 95124
*
* Attempt to smooth over portability issues in reading directories
* on various operating systems. Currently implemented only for
* MSDOS and Unix. Implementations for other systems are welcome.
*/

#include "pdirect.h"

#if defined(MSDOS)

int
dir_open(Directory *dsp, char *dname)
{
int l, c;
unsigned r;

strcpy(dsp->path, dname);
l = strlen(dsp->path);
if ((c = dsp->path[l-1]) != '/' && c != '\\' && c != ':') {
dsp->path[l++] = '\\';
dsp->path[l] = '\0';
}
dsp->basep = dsp->path + l;

strcpy(dsp->basep, "*.*");
r = _dos_findfirst(dsp->path,
(_A_NORMAL|_A_RDONLY|_A_SUBDIR), &dsp->dta);
if (r == 0) {
dsp->first_time = 1;
}
return (int)r;
}

int
dir_next(Directory *dsp, DirEntry *dep)
{
unsigned r, fdate, ftime;
struct tm st;

if (dsp->first_time) {
dsp->first_time = 0;
r = 0;
} else {
r = _dos_findnext(&dsp->dta);
}
if (r == 0) {
dep->d_mode = dsp->dta.ff_attrib;
dep->d_size = dsp->dta.ff_fsize;
ftime = dsp->dta.ff_ftime;
fdate = dsp->dta.ff_fdate;

st.tm_sec = (int)((ftime & 0x001F) << 1);
st.tm_min = (int)((ftime & 0x07E0) >> 5);
st.tm_hour = (int)((ftime & 0xF800) >> 11);
st.tm_mday = (int)(fdate & 0x001F);
st.tm_mon = (int)((fdate & 0x01E0) >> 5);
st.tm_year = (int)(((fdate & 0xFE00) >> 9) + 80);

dep->d_time = mktime(&st);
strcpy(dep->d_name, dsp->dta.ff_name);
}
return (int)r;
}

void
dir_close(Directory *dsp)
{
return;
}

#elif defined(UNIX)

int
dir_open(Directory *dsp, char *dname)
{
int l;

strcpy(dsp->path, dname);
l = strlen(dsp->path);
if (dsp->path[l-1] != '/') {

dsp->path[l++] = '/';
dsp->path[l] = '\0';
}
dsp->basep = dsp->path + l;

return (dsp->dp = opendir(dname)) == NULL;
}

int
dir_next(Directory *dsp, DirEntry *dep)
{
int r;
struct dirent *sdp;
struct stat st;

if ((sdp = readdir(dsp->dp)) != NULL) {
strcpy(dep->d_name, sdp->d_name);
strcpy(dsp->basep, dep->d_name);

if ((r = stat(dsp->path, &st)) != 0) {
return 1;
} else {
dep->d_mode = st.st_mode;
dep->d_size = st.st_size;
dep->d_time = st.st_mtime;
}
return 0;
} else {
return 1;
}
}

void
dir_close(Directory *dsp)
{
closedir(dsp->dp);
}

#else /* Not MSDOS or UNIX */

#error PDIRECT not ported to this environment.

#endif


  3 Responses to “Category : C Source Code
Archive   : GTOLS101.ZIP
Filename : PDIRECT.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/