1999-09-14 09:32:05 -04:00
|
|
|
/* Here is stuff for interfacing to directories.
|
|
|
|
** Copyright (c) 1993, 1994 by Olin Shivers.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2001-08-08 05:21:20 -04:00
|
|
|
#include <errno.h>
|
1999-09-14 09:32:05 -04:00
|
|
|
|
|
|
|
/* Make sure our exports match up w/the implementation: */
|
2001-08-08 05:21:20 -04:00
|
|
|
#include "scheme48.h"
|
1999-09-14 09:32:05 -04:00
|
|
|
#include "dirstuff1.h"
|
|
|
|
|
2001-08-08 05:21:20 -04:00
|
|
|
s48_value open_dir(s48_value sch_dirname)
|
1999-09-14 09:32:05 -04:00
|
|
|
{
|
2001-08-08 05:21:20 -04:00
|
|
|
char *fname;
|
|
|
|
struct dirent *dirent;
|
|
|
|
DIR *d;
|
|
|
|
s48_value dirlist = S48_NULL;
|
|
|
|
|
2002-02-14 09:00:27 -05:00
|
|
|
S48_DECLARE_GC_PROTECT(1);
|
2001-08-08 05:21:20 -04:00
|
|
|
|
2002-02-14 09:00:27 -05:00
|
|
|
S48_GC_PROTECT_1(dirlist);
|
2001-08-08 05:21:20 -04:00
|
|
|
|
|
|
|
if( NULL == (d = opendir(s48_extract_string (sch_dirname))) )
|
|
|
|
s48_raise_os_error_1 (errno, sch_dirname);
|
|
|
|
|
|
|
|
while( NULL != (dirent = readdir(d)) ) {
|
|
|
|
if((strcmp(dirent->d_name,".") == 0) || (strcmp(dirent->d_name,"..") == 0))
|
|
|
|
continue;
|
1999-09-14 09:32:05 -04:00
|
|
|
|
2002-02-14 09:00:27 -05:00
|
|
|
dirlist = s48_cons (s48_enter_string (dirent->d_name),
|
|
|
|
dirlist);
|
1999-09-14 09:32:05 -04:00
|
|
|
|
2001-08-08 05:21:20 -04:00
|
|
|
}
|
|
|
|
if (closedir(d) == -1)
|
|
|
|
s48_raise_os_error_1 (errno, sch_dirname);
|
|
|
|
|
|
|
|
S48_GC_UNPROTECT ();
|
|
|
|
return dirlist;
|
1999-09-14 09:32:05 -04:00
|
|
|
}
|
2001-09-07 11:56:02 -04:00
|
|
|
|
|
|
|
void s48_init_dirstuff (){
|
|
|
|
S48_EXPORT_FUNCTION(open_dir);
|
|
|
|
}
|