2004-12-10 22:12:05 -05:00
|
|
|
#include "../factor.h"
|
|
|
|
|
|
|
|
void primitive_stat(void)
|
|
|
|
{
|
|
|
|
F_STRING *path;
|
|
|
|
WIN32_FILE_ATTRIBUTE_DATA st;
|
|
|
|
|
2005-06-16 18:50:49 -04:00
|
|
|
maybe_gc(0);
|
2004-12-10 22:12:05 -05:00
|
|
|
path = untag_string(dpop());
|
|
|
|
|
2005-12-12 18:51:45 -05:00
|
|
|
if(!GetFileAttributesEx(to_c_string(path,true), GetFileExInfoStandard, &st))
|
2004-12-10 22:12:05 -05:00
|
|
|
{
|
|
|
|
dpush(F);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CELL dirp = tag_boolean(st.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
|
2005-01-16 17:58:28 -05:00
|
|
|
CELL size = tag_bignum(s48_long_long_to_bignum(
|
2005-03-21 20:59:30 -05:00
|
|
|
(s64)st.nFileSizeLow | (s64)st.nFileSizeHigh << 32));
|
2004-12-11 15:02:34 -05:00
|
|
|
CELL mtime = tag_integer((int)
|
2005-03-21 20:59:30 -05:00
|
|
|
((*(s64*)&st.ftLastWriteTime - EPOCH_OFFSET) / 10000000));
|
2004-12-10 22:12:05 -05:00
|
|
|
dpush(
|
|
|
|
cons(dirp,
|
|
|
|
cons(tag_fixnum(0),
|
|
|
|
cons(size,
|
|
|
|
cons(mtime, F)))));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void primitive_read_dir(void)
|
|
|
|
{
|
|
|
|
F_STRING *path;
|
|
|
|
HANDLE dir;
|
|
|
|
WIN32_FIND_DATA find_data;
|
|
|
|
CELL result = F;
|
|
|
|
|
2005-06-16 18:50:49 -04:00
|
|
|
maybe_gc(0);
|
2004-12-10 22:12:05 -05:00
|
|
|
|
|
|
|
path = untag_string(dpop());
|
|
|
|
if (INVALID_HANDLE_VALUE != (dir = FindFirstFile(".\\*", &find_data)))
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
CELL name = tag_object(from_c_string(find_data.cFileName));
|
|
|
|
result = cons(name, result);
|
|
|
|
}
|
|
|
|
while (FindNextFile(dir, &find_data));
|
|
|
|
CloseHandle(dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
dpush(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
void primitive_cwd(void)
|
|
|
|
{
|
|
|
|
char buf[MAX_PATH];
|
|
|
|
|
2005-06-16 18:50:49 -04:00
|
|
|
maybe_gc(0);
|
2004-12-10 22:12:05 -05:00
|
|
|
if(!GetCurrentDirectory(MAX_PATH, buf))
|
2005-05-01 19:40:44 -04:00
|
|
|
io_error();
|
2004-12-10 22:12:05 -05:00
|
|
|
|
|
|
|
box_c_string(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
void primitive_cd(void)
|
|
|
|
{
|
2005-06-16 18:50:49 -04:00
|
|
|
maybe_gc(0);
|
2004-12-10 22:12:05 -05:00
|
|
|
SetCurrentDirectory(unbox_c_string());
|
|
|
|
}
|