factor/native/windows/file.c

79 lines
1.5 KiB
C
Raw Normal View History

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());
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);
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));
2006-05-15 00:03:55 -04:00
dpush(make_array_4(dirp,tag_fixnum(0),size,mtime));
2004-12-10 22:12:05 -05:00
}
}
void primitive_read_dir(void)
{
F_STRING *path;
HANDLE dir;
WIN32_FIND_DATA find_data;
2006-05-15 00:03:55 -04:00
F_ARRAY *result;
CELL result_count = 0;
2004-12-10 22:12:05 -05:00
2005-06-16 18:50:49 -04:00
maybe_gc(0);
2004-12-10 22:12:05 -05:00
2006-05-15 00:03:55 -04:00
result = array(ARRAY_TYPE,100,F);
2004-12-10 22:12:05 -05:00
path = untag_string(dpop());
if (INVALID_HANDLE_VALUE != (dir = FindFirstFile(".\\*", &find_data)))
{
2006-05-15 00:03:55 -04:00
do
2004-12-10 22:12:05 -05:00
{
2006-05-15 00:03:55 -04:00
CELL name = tag_object(from_c_string(
find_data.cFileName));
if(result_count == array_capacity(result))
{
result = resize_array(result,
result_count * 2,F);
}
put(AREF(result,result_count),name);
result_count++;
2004-12-10 22:12:05 -05:00
}
while (FindNextFile(dir, &find_data));
CloseHandle(dir);
}
2006-05-15 00:03:55 -04:00
result = resize_array(result,result_count,F);
dpush(tag_object(result));
2004-12-10 22:12:05 -05:00
}
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))
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);
SetCurrentDirectory(pop_c_string());
2004-12-10 22:12:05 -05:00
}