slang-users mailing list

[2004 Date Index] [2004 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

[slang-users] Additions to s-lang


Greetings folks,

I've just discovered the s-lang stat_is() function for determining file
permissions and decided to use in my extended dired mode for Jed, but
discovered that it lacks the ability to check read/write/execute
permissions for files. 

Although it would be possible to do this my masking the st_mode field of
the structure returned by stat_file, I thought it would be more
platform-independent to use stat_is, so I've extended it for the purpose so
that it now accepts "usr_r", "usr_w" & "usr_x" parameters, along with
similar ones for 'grp_' and 'oth_'.

I've appended a diff listing for slposdir.c in s-lang 1.4.9 to this mail,
but I've only tested these mods on Windows, which doesn't really have group
and other permissions in this way, so I've fudged things a bit and don't
know if it will work properly (i.e. in the non-windows-fudged version of
the code) on other platforms.

Regards

John Skilleter

--- ..\..\slang-1.4.9\src\slposdir.c	Sun Mar 23 07:06:40 2003
+++ slposdir.c	Sat Jun 26 23:16:51 2004
@@ -260,10 +260,104 @@
 # else
 #   define S_ISSOCK(m) 0
 # endif
 #endif
 
+// [JMS] <<<
+// Added support for usr/grp/other read/write/execute permission checks
+
+#ifndef S_ISIRUSR
+# ifdef S_IRUSR
+#   define S_ISIRUSR(m) (((m) & S_IRUSR) == S_IRUSR)
+# else
+#   define S_ISIRUSR(m) 0
+# endif
+#endif
+
+#ifndef S_ISIWUSR
+# ifdef S_IWUSR
+#   define S_ISIWUSR(m) (((m) & S_IWUSR) == S_IWUSR)
+# else
+#   define S_ISIWUSR(m) 0
+# endif
+#endif
+
+#ifndef S_ISIXUSR
+# ifdef S_IXUSR
+#   define S_ISIXUSR(m) (((m) & S_IXUSR) == S_IXUSR)
+# else
+#   define S_ISIXUSR(m) 0
+# endif
+#endif
+
+#ifdef WIN32
+// Windows doesn't have file access permissions in the same way as Unix
+// so we'll approximate them by assuming that the group and other 
+// permissions are the same as the user ones - this might lead to
problems....
+
+#define S_ISIRGRP S_ISIRUSR
+#define S_ISIWGRP S_ISIWUSR
+#define S_ISIXGRP S_ISIXUSR
+
+#define S_ISIROTH S_ISIRUSR
+#define S_ISIWOTH S_ISIWUSR
+#define S_ISIXOTH S_ISIXUSR
+
+#else
+
+#ifndef S_ISIRGRP
+# ifdef S_IRGRP
+#   define S_ISIRGRP(m) (((m) & S_IRGRP) == S_IRGRP)
+# else
+#   define S_ISIRGRP(m) 0
+# endif
+#endif
+
+#ifndef S_ISIWGRP
+# ifdef S_IWGRP
+#   define S_ISIWGRP(m) (((m) & S_IWGRP) == S_IWGRP)
+# else
+#   define S_ISIWGRP(m) 0
+# endif
+#endif
+
+#ifndef S_ISIXGRP
+# ifdef S_IXGRP
+#   define S_ISIXGRP(m) (((m) & S_IXGRP) == S_IXGRP)
+# else
+#   define S_ISIXGRP(m) 0
+# endif
+#endif
+
+#ifndef S_ISIROTH
+# ifdef S_IROTH
+#   define S_ISIROTH(m) (((m) & S_IROTH) == S_IROTH)
+# else
+#   define S_ISIROTH(m) 0
+# endif
+#endif
+
+#ifndef S_ISIWOTH
+# ifdef S_IWOTH
+#   define S_ISIWOTH(m) (((m) & S_IWOTH) == S_IWOTH)
+# else
+#   define S_ISIWOTH(m) 0
+# endif
+#endif
+
+#ifndef S_ISIXOTH
+# ifdef S_IXOTH
+#   define S_ISIXOTH(m) (((m) & S_IXOTH) == S_IXOTH)
+# else
+#   define S_ISIXOTH(m) 0
+# endif
+#endif
+
+#endif
+
+// [JMS] >>>
+ 
 static char stat_is_cmd (char *what, int *mode_ptr)
 {
    int ret;
    int st_mode = *mode_ptr;
 
@@ -272,10 +366,24 @@
    else if (!strcmp (what, "blk")) ret = S_ISBLK(st_mode);
    else if (!strcmp (what, "chr")) ret = S_ISCHR(st_mode);
    else if (!strcmp (what, "dir")) ret = S_ISDIR(st_mode);
    else if (!strcmp (what, "reg")) ret = S_ISREG(st_mode);
    else if (!strcmp (what, "lnk")) ret = S_ISLNK(st_mode);
+	
+	// [JMS] Added support for usr/grp/other read/write/execute permission
checks
+	
+	else if (!strcmp (what, "usr_r")) ret = S_ISIRUSR(st_mode);
+	else if (!strcmp (what, "usr_w")) ret = S_ISIWUSR(st_mode);
+	else if (!strcmp (what, "usr_x")) ret = S_ISIXUSR(st_mode);
+
+	else if (!strcmp (what, "grp_r")) ret = S_ISIRGRP(st_mode);
+	else if (!strcmp (what, "grp_w")) ret = S_ISIWGRP(st_mode);
+	else if (!strcmp (what, "grp_x")) ret = S_ISIXGRP(st_mode);
+
+	else if (!strcmp (what, "oth_r")) ret = S_ISIROTH(st_mode);
+	else if (!strcmp (what, "oth_w")) ret = S_ISIWOTH(st_mode);
+	else if (!strcmp (what, "oth_x")) ret = S_ISIXOTH(st_mode);
    else
      {
 	SLang_verror (SL_INVALID_PARM, "stat_is: Unrecognized type: %s", what);
 	return -1;
      }

-----------------------------------------
John Skilleter - john@xxxxxxxxxxxxxxxx & elsewhere
'DOS is best spelt backwards!'
    http://www.skilleter.org.uk
    http://www.roada.org.uk
-----------------------------------------



_______________________________________________
To unsubscribe, visit http://jedsoft.org/slang/mailinglists.html


[2004 date index] [2004 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]