[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#441595: [Dev-luatex] (fwd) Bug#441595: not all libraries are customized, there is room for improvement




Hi Hilmar,

On 11/28/2010 01:54 PM, Hilmar Preusse wrote:

luafilesystem: that local patch will go away soon (it is possible
   to slide the new functions in elsewhere, where they are not
   interfering with the upstream).

The patch is still in the lualib used by luatex. Did you made already
a decision if that code is needed (and should be pushed upstream to
the lua project)?

Thank you for reminding me, I had completely forgotten about this :(

I now am in the process of upgrading luatex to use luafilesystem 1.5.0,
and I will move most of the extra functionality to a different source
file, as I wrote above.

Nevertheless, there are two change sets that will remain in my version
of the lfs.c file: one portability bug fix and one extension. Both of
these are interesting enough to go upstream, in my opinion.

The portability fix is in get_dir(), where the stock lfs version
assumes a glibc-style runtime library that calls malloc() automatically
inside getcwd(). I got a compilation failure report on that, for
the Sun Studio compiler on Solaris 10 Sparc.

The extension is an extra field thats is retunred by lfs.attributes(),
named 'permissions'. This represents the file permissions as a simple
9-letter string (it uses "r", "w", and "x" only).

Best wishes,
Taco

--- lfs.c.orig	2010-11-28 15:19:45.000000000 +0100
+++ lfs.c	2010-11-28 15:43:19.000000000 +0100
@@ -128,16 +128,19 @@
 ** If unable to get the current directory, it returns nil
 **  and a string describing the error
 */
+#ifndef PATH_MAX
+#define PATH_MAX 4096
+#endif
+
 static int get_dir (lua_State *L) {
-  char *path;
-  if ((path = getcwd(NULL, 0)) == NULL) {
+  char path[PATH_MAX];
+  if (getcwd((char *)path, PATH_MAX) == NULL) {
     lua_pushnil(L);
     lua_pushstring(L, getcwd_error);
     return 2;
   }
   else {
     lua_pushstring(L, path);
-    free(path);
     return 1;
   }
 }
@@ -669,6 +672,46 @@
 #endif
 }
 
+ /*
+** Convert the inode protection mode to a permission list.
+*/
+
+#ifdef _WIN32
+static const char *perm2string (unsigned short mode) {
+  static char perms[10] = "---------\0";
+  int i;
+  for (i=0;i<9;i++) perms[i]='-';  
+  if (mode  & _S_IREAD) 
+   { perms[0] = 'r'; perms[3] = 'r'; perms[6] = 'r'; }
+  if (mode  & _S_IWRITE) 
+   { perms[1] = 'w'; perms[4] = 'w'; perms[7] = 'w'; }
+  if (mode  & _S_IEXEC) 
+   { perms[2] = 'x'; perms[5] = 'x'; perms[8] = 'x'; }
+  return perms;
+}
+#else
+static const char *perm2string (mode_t mode) {
+  static char perms[10] = "---------\0";
+  int i;
+  for (i=0;i<9;i++) perms[i]='-';
+  if (mode & S_IRUSR) perms[0] = 'r';
+  if (mode & S_IWUSR) perms[1] = 'w';
+  if (mode & S_IXUSR) perms[2] = 'x';
+  if (mode & S_IRGRP) perms[3] = 'r';
+  if (mode & S_IWGRP) perms[4] = 'w';
+  if (mode & S_IXGRP) perms[5] = 'x';
+  if (mode & S_IROTH) perms[6] = 'r';
+  if (mode & S_IWOTH) perms[7] = 'w';
+  if (mode & S_IXOTH) perms[8] = 'x';
+  return perms;
+}
+#endif
+
+/* permssions string */
+static void push_st_perm (lua_State *L, STAT_STRUCT *info) {
+    lua_pushstring (L, perm2string (info->st_mode));
+}
+
 typedef void (*_push_function) (lua_State *L, STAT_STRUCT *info);
 
 struct _stat_members {
@@ -688,6 +731,7 @@
 	{ "modification", push_st_mtime },
 	{ "change",       push_st_ctime },
 	{ "size",         push_st_size },
+ 	{ "permissions",  push_st_perm },
 #ifndef _WIN32
 	{ "blocks",       push_st_blocks },
 	{ "blksize",      push_st_blksize },

Reply to: