2004-12-10 22:12:05 -05:00
|
|
|
#include "../factor.h"
|
2004-07-24 00:54:57 -04:00
|
|
|
|
2004-08-29 23:30:54 -04:00
|
|
|
void primitive_stat(void)
|
|
|
|
{
|
|
|
|
struct stat sb;
|
2004-12-10 21:46:42 -05:00
|
|
|
F_STRING* path;
|
2004-10-12 23:49:43 -04:00
|
|
|
|
2005-06-16 18:50:49 -04:00
|
|
|
maybe_gc(0);
|
2004-10-12 23:49:43 -04:00
|
|
|
|
|
|
|
path = untag_string(dpop());
|
2005-12-12 18:51:45 -05:00
|
|
|
if(stat(to_c_string(path,true),&sb) < 0)
|
2004-08-29 23:30:54 -04:00
|
|
|
dpush(F);
|
|
|
|
else
|
|
|
|
{
|
2004-08-30 00:36:44 -04:00
|
|
|
CELL dirp = tag_boolean(S_ISDIR(sb.st_mode));
|
|
|
|
CELL mode = tag_fixnum(sb.st_mode & ~S_IFMT);
|
2005-01-16 17:58:28 -05:00
|
|
|
CELL size = tag_bignum(s48_long_long_to_bignum(sb.st_size));
|
2004-08-29 23:30:54 -04:00
|
|
|
CELL mtime = tag_integer(sb.st_mtime);
|
2004-09-03 18:49:04 -04:00
|
|
|
dpush(cons(
|
2004-08-30 00:36:44 -04:00
|
|
|
dirp,
|
2004-09-03 18:49:04 -04:00
|
|
|
cons(
|
2004-08-30 00:36:44 -04:00
|
|
|
mode,
|
2004-09-03 18:49:04 -04:00
|
|
|
cons(
|
2004-08-30 00:36:44 -04:00
|
|
|
size,
|
2004-09-03 18:49:04 -04:00
|
|
|
cons(
|
|
|
|
mtime,F)))));
|
2004-08-29 23:30:54 -04:00
|
|
|
}
|
|
|
|
}
|
2004-08-30 00:36:44 -04:00
|
|
|
|
|
|
|
void primitive_read_dir(void)
|
|
|
|
{
|
2004-12-10 21:46:42 -05:00
|
|
|
F_STRING* path;
|
2004-10-12 23:49:43 -04:00
|
|
|
DIR* dir;
|
2004-08-30 00:36:44 -04:00
|
|
|
CELL result = F;
|
2004-10-12 23:49:43 -04:00
|
|
|
|
2005-06-16 18:50:49 -04:00
|
|
|
maybe_gc(0);
|
2004-10-12 23:49:43 -04:00
|
|
|
|
|
|
|
path = untag_string(dpop());
|
2005-12-12 18:51:45 -05:00
|
|
|
dir = opendir(to_c_string(path,true));
|
2004-08-30 00:36:44 -04:00
|
|
|
if(dir != NULL)
|
|
|
|
{
|
|
|
|
struct dirent* file;
|
|
|
|
|
2004-10-12 23:49:43 -04:00
|
|
|
while((file = readdir(dir)) != NULL)
|
2004-08-30 00:36:44 -04:00
|
|
|
{
|
|
|
|
CELL name = tag_object(from_c_string(
|
|
|
|
file->d_name));
|
2004-09-03 18:49:04 -04:00
|
|
|
result = cons(name,result);
|
2004-08-30 00:36:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
closedir(dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
dpush(result);
|
|
|
|
}
|
2004-09-04 03:06:53 -04:00
|
|
|
|
|
|
|
void primitive_cwd(void)
|
|
|
|
{
|
|
|
|
char wd[MAXPATHLEN];
|
2005-06-16 18:50:49 -04:00
|
|
|
maybe_gc(0);
|
2005-06-08 04:49:05 -04:00
|
|
|
if(getcwd(wd,MAXPATHLEN) == NULL)
|
2005-05-01 14:30:53 -04:00
|
|
|
io_error();
|
2004-09-19 17:39:28 -04:00
|
|
|
box_c_string(wd);
|
2004-09-04 03:06:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void primitive_cd(void)
|
|
|
|
{
|
2005-06-16 18:50:49 -04:00
|
|
|
maybe_gc(0);
|
2004-09-19 17:39:28 -04:00
|
|
|
chdir(unbox_c_string());
|
2004-09-04 03:06:53 -04:00
|
|
|
}
|
2004-12-10 22:12:05 -05:00
|
|
|
|