diff --git a/main/gbx/gbx_c_file.c b/main/gbx/gbx_c_file.c index 7e266ab84..32fd9fd28 100644 --- a/main/gbx/gbx_c_file.c +++ b/main/gbx/gbx_c_file.c @@ -32,9 +32,11 @@ #include #include #include +#include #include #include "gb_common.h" +#include "gb_common_buffer.h" #include "gb_list.h" #include "gb_file.h" @@ -366,34 +368,23 @@ BEGIN_PROPERTY(Stat_Auth) END_PROPERTY -#if 0 -BEGIN_METHOD(CFILE_access, GB_INTEGER who; GB_INTEGER access) - bool ret; - int access = VARGOPT(access, GB_STAT_READ); - int who = VARG(who); - int mode = THIS_STAT->info.mode; +BEGIN_PROPERTY(Stat_Device) - if ((access & GB_STAT_READ) == 0) - mode &= ~(S_IRUSR | S_IRGRP | S_IROTH); - if ((access & GB_STAT_WRITE) == 0) - mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH); - if ((access & GB_STAT_EXEC) == 0) - mode &= ~(S_IXUSR | S_IXGRP | S_IXOTH); - - switch(who) + dev_t dev = THIS_STAT->info.device; + int len; + + if (dev == 0) + GB_ReturnNull(); + else { - case GB_STAT_USER: ret = mode & S_IRWXU; break; - case GB_STAT_GROUP: ret = mode & S_IRWXG; break; - case GB_STAT_OTHER: ret = mode & S_IRWXO; break; - default: ret = FALSE; break; + len = sprintf(COMMON_buffer, "/%s/%d:%d", THIS_STAT->info.chrdev ? "char" : "block", major(dev), minor(dev)); + GB_ReturnNewString(COMMON_buffer, len); } - GB_ReturnBoolean(ret); - -END_METHOD -#endif +END_PROPERTY +//-------------------------------------------------------------------------- static void return_perm(CSTAT *_object, int rf, int wf, int xf) { @@ -413,25 +404,25 @@ static void return_perm(CSTAT *_object, int rf, int wf, int xf) } -BEGIN_PROPERTY(CFILE_perm_user) +BEGIN_PROPERTY(StatPerm_User) return_perm(THIS_STAT, S_IRUSR, S_IWUSR, S_IXUSR); END_PROPERTY -BEGIN_PROPERTY(CFILE_perm_group) +BEGIN_PROPERTY(StatPerm_Group) return_perm(THIS_STAT, S_IRGRP, S_IWGRP, S_IXGRP); END_PROPERTY -BEGIN_PROPERTY(CFILE_perm_other) +BEGIN_PROPERTY(StatPerm_Other) return_perm(THIS_STAT, S_IROTH, S_IWOTH, S_IXOTH); END_PROPERTY -BEGIN_METHOD(CFILE_perm_get, GB_STRING user) +BEGIN_METHOD(StatPerm_get, GB_STRING user) char *who; char *user = GB_ToZeroString(ARG(user)); @@ -743,7 +734,7 @@ BEGIN_METHOD(File_RealPath, GB_STRING path) END_METHOD -//--------------------------------------------------------------------------- +//-------------------------------------------------------------------------- BEGIN_PROPERTY(Stream_Handle) @@ -1073,10 +1064,10 @@ GB_DESC StatPermDesc[] = { GB_DECLARE_VIRTUAL(".Stat.Perm"), - GB_METHOD("_get", "s", CFILE_perm_get, "(UserOrGroup)s"), - GB_PROPERTY_READ("User", "s", CFILE_perm_user), - GB_PROPERTY_READ("Group", "s", CFILE_perm_group), - GB_PROPERTY_READ("Other", "s", CFILE_perm_other), + GB_METHOD("_get", "s", StatPerm_get, "(UserOrGroup)s"), + GB_PROPERTY_READ("User", "s", StatPerm_User), + GB_PROPERTY_READ("Group", "s", StatPerm_Group), + GB_PROPERTY_READ("Other", "s", StatPerm_Other), GB_END_DECLARE }; @@ -1106,6 +1097,7 @@ GB_DESC StatDesc[] = GB_PROPERTY_READ("Path", "s", Stat_Path), GB_PROPERTY_READ("Link", "s", Stat_Link), GB_PROPERTY_READ("Auth", "s", Stat_Auth), + GB_PROPERTY_READ("Device", "s", Stat_Device), GB_END_DECLARE }; diff --git a/main/share/gambas.h b/main/share/gambas.h index 7c2cb2a22..45fc9d8d9 100644 --- a/main/share/gambas.h +++ b/main/share/gambas.h @@ -935,7 +935,10 @@ typedef int64_t size; uid_t uid; gid_t gid; - char hidden; + dev_t device; + unsigned hidden : 1; + unsigned blkdev : 1; + unsigned chrdev : 1; } GB_FILE_STAT; diff --git a/main/share/gb_file_temp.h b/main/share/gb_file_temp.h index 4f826d153..7fe8ea2e1 100644 --- a/main/share/gb_file_temp.h +++ b/main/share/gb_file_temp.h @@ -546,6 +546,9 @@ void FILE_stat(const char *path, FILE_STAT *info, bool follow) info->hidden = (*FILE_get_name(path) == '.'); info->uid = buf.st_uid; info->gid = buf.st_gid; + info->device = buf.st_dev; + info->blkdev = S_ISBLK(buf.st_mode); + info->chrdev = S_ISCHR(buf.st_mode); } char *FILE_mode_to_string(mode_t mode)