* init.c (scm_boot_guile): Don't return the value of
[bpt/guile.git] / libguile / filesys.c
index c81ee5e..1f65c88 100644 (file)
@@ -42,6 +42,7 @@
 #include "_scm.h"
 #include "genio.h"
 #include "smob.h"
+#include "feature.h"
 
 #include "filesys.h"
 \f
@@ -60,7 +61,7 @@
 #include <unistd.h>
 #endif
 
-#ifdef HAVE_LIBC_H
+#ifdef LIBC_H_WITH_UNISTD_H
 #include <libc.h>
 #endif
 
@@ -155,16 +156,12 @@ SCM_CONST_LONG (scm_O_SYNC, "O_SYNC", O_SYNC);
  */
 
 SCM_PROC (s_sys_chown, "chown", 3, 0, 0, scm_sys_chown);
-#ifdef __STDC__
-SCM 
-scm_sys_chown (SCM path, SCM owner, SCM group)
-#else
+
 SCM 
 scm_sys_chown (path, owner, group)
      SCM path;
      SCM owner;
      SCM group;
-#endif
 {
   int val;
 
@@ -182,15 +179,11 @@ scm_sys_chown (path, owner, group)
 
 
 SCM_PROC (s_sys_chmod, "chmod", 2, 0, 0, scm_sys_chmod);
-#ifdef __STDC__
-SCM 
-scm_sys_chmod (SCM port_or_path, SCM mode)
-#else
+
 SCM 
 scm_sys_chmod (port_or_path, mode)
      SCM port_or_path;
      SCM mode;
-#endif
 {
   int rv;
   SCM_ASSERT (SCM_INUMP (mode), mode, SCM_ARG2, s_sys_chmod);
@@ -210,14 +203,10 @@ scm_sys_chmod (port_or_path, mode)
 }
 
 SCM_PROC (s_umask, "umask", 0, 1, 0, scm_umask);
-#ifdef __STDC__
-SCM 
-scm_umask (SCM mode)
-#else
+
 SCM 
 scm_umask (mode)
      SCM mode;
-#endif
 {
   mode_t mask;
   if (SCM_UNBNDP (mode))
@@ -238,16 +227,14 @@ scm_umask (mode)
  */
 long scm_tc16_fd;
 
-#ifdef __STDC__
-static int 
-scm_fd_print (SCM sexp, SCM port, int writing)
-#else
+
+static int scm_fd_print SCM_P ((SCM sexp, SCM port, scm_print_state *pstate));
+
 static int 
-scm_fd_print (sexp, port, writing)
+scm_fd_print (sexp, port, pstate)
      SCM sexp;
      SCM port;
-     int writing;
-#endif
+     scm_print_state *pstate;
 {
   scm_gen_puts (scm_regular_string, "#<fd ", port);
   scm_intprint (SCM_CDR (sexp), 10, port);
@@ -255,14 +242,12 @@ scm_fd_print (sexp, port, writing)
   return 1;
 }
 
-#ifdef __STDC__
-static scm_sizet 
-scm_fd_free (SCM p)
-#else
+
+static scm_sizet scm_fd_free SCM_P ((SCM p));
+
 static scm_sizet 
 scm_fd_free (p)
      SCM p;
-#endif
 {
   SCM flags;
 
@@ -276,15 +261,11 @@ scm_fd_free (p)
 
 static scm_smobfuns fd_smob = {scm_mark0, scm_fd_free, scm_fd_print, 0};
 
-#ifdef __STDC__
-SCM
-scm_intern_fd (int fd, int flags)
-#else
+
 SCM
 scm_intern_fd (fd, flags)
      int fd;
      int flags;
-#endif
 {
   SCM it;
   SCM_NEWCELL (it);
@@ -298,16 +279,12 @@ scm_intern_fd (fd, flags)
 \f
 
 SCM_PROC (s_sys_open, "open", 3, 0, 0, scm_sys_open);
-#ifdef __STDC__
-SCM
-scm_sys_open (SCM path, SCM flags, SCM mode)
-#else
+
 SCM
 scm_sys_open (path, flags, mode)
      SCM path;
      SCM flags;
      SCM mode;
-#endif
 {
   int fd;
   SCM sfd;
@@ -331,15 +308,11 @@ scm_sys_open (path, flags, mode)
 
 
 SCM_PROC (s_sys_create, "create", 2, 0, 0, scm_sys_create);
-#ifdef __STDC__
-SCM
-scm_sys_create (SCM path, SCM mode)
-#else
+
 SCM
 scm_sys_create (path, mode)
      SCM path;
      SCM mode;
-#endif
 {
   int fd;
   SCM sfd;
@@ -362,14 +335,10 @@ scm_sys_create (path, mode)
 
 
 SCM_PROC (s_sys_close, "close", 1, 0, 0, scm_sys_close);
-#ifdef __STDC__
-SCM
-scm_sys_close (SCM sfd)
-#else
+
 SCM
 scm_sys_close (sfd)
      SCM sfd;
-#endif
 {
   int fd;
   int got;
@@ -387,15 +356,11 @@ scm_sys_close (sfd)
 
 
 SCM_PROC (s_sys_write_fd, "write-fd", 2, 0, 0, scm_sys_write_fd);
-#ifdef __STDC__
-SCM
-scm_sys_write_fd (SCM sfd, SCM buf)
-#else
+
 SCM
 scm_sys_write_fd (sfd, buf)
      SCM sfd;
      SCM buf;
-#endif
 {
   SCM answer;
   int fd;
@@ -414,17 +379,13 @@ scm_sys_write_fd (sfd, buf)
 
 
 SCM_PROC (s_sys_read_fd, "read-fd", 2, 2, 0, scm_sys_read_fd);
-#ifdef __STDC__
-SCM
-scm_sys_read_fd (SCM sfd, SCM buf, SCM offset, SCM length)
-#else
+
 SCM
 scm_sys_read_fd (sfd, buf, offset, length)
      SCM sfd;
      SCM buf;
      SCM offset;
      SCM length;
-#endif
 {
   SCM answer;
   int fd;
@@ -465,16 +426,12 @@ scm_sys_read_fd (sfd, buf, offset, length)
 }
 
 SCM_PROC (s_sys_lseek, "lseek", 2, 1, 0, scm_sys_lseek);
-#ifdef __STDC__
-SCM
-scm_sys_lseek (SCM sfd, SCM offset, SCM whence)
-#else
+
 SCM
 scm_sys_lseek (sfd, offset, whence)
      SCM sfd;
      SCM offset;
      SCM whence;
-#endif
 {
   SCM answer;
   int fd;
@@ -505,15 +462,11 @@ scm_sys_lseek (sfd, offset, whence)
 
 
 SCM_PROC (s_sys_dup, "dup", 1, 1, 0, scm_sys_dup);
-#ifdef __STDC__
-SCM
-scm_sys_dup (SCM oldfd, SCM newfd)
-#else
+
 SCM
 scm_sys_dup (oldfd, newfd)
      SCM oldfd;
      SCM newfd;
-#endif
 {
   SCM answer;
   int fd;
@@ -539,17 +492,25 @@ scm_sys_dup (oldfd, newfd)
 \f
 /* {Files}
  */
-#ifdef __STDC__
-static SCM 
-scm_stat2scm (struct stat *stat_temp)
-#else
+
+SCM_SYMBOL (scm_sym_regular, "regular");
+SCM_SYMBOL (scm_sym_directory, "directory");
+SCM_SYMBOL (scm_sym_symlink, "symlink");
+SCM_SYMBOL (scm_sym_block_special, "block-special");
+SCM_SYMBOL (scm_sym_char_special, "char-special");
+SCM_SYMBOL (scm_sym_fifo, "fifo");
+SCM_SYMBOL (scm_sym_sock, "socket");
+SCM_SYMBOL (scm_sym_unknown, "unknown");
+
+static SCM scm_stat2scm SCM_P ((struct stat *stat_temp));
+
 static SCM 
 scm_stat2scm (stat_temp)
      struct stat *stat_temp;
-#endif
 {
-  SCM ans = scm_make_vector (SCM_MAKINUM (13), SCM_UNSPECIFIED, SCM_BOOL_F);
+  SCM ans = scm_make_vector (SCM_MAKINUM (15), SCM_UNSPECIFIED, SCM_BOOL_F);
   SCM *ve = SCM_VELTS (ans);
+  
   ve[0] = scm_ulong2num ((unsigned long) stat_temp->st_dev);
   ve[1] = scm_ulong2num ((unsigned long) stat_temp->st_ino);
   ve[2] = scm_ulong2num ((unsigned long) stat_temp->st_mode);
@@ -575,26 +536,74 @@ scm_stat2scm (stat_temp)
 #else
   ve[12] = SCM_BOOL_F;
 #endif
+  {
+    int mode = stat_temp->st_mode;
+    
+    if (S_ISREG (mode))
+      ve[13] = scm_sym_regular;
+    else if (S_ISDIR (mode))
+      ve[13] = scm_sym_directory;
+    else if (S_ISLNK (mode))
+      ve[13] = scm_sym_symlink;
+    else if (S_ISBLK (mode))
+      ve[13] = scm_sym_block_special;
+    else if (S_ISCHR (mode))
+      ve[13] = scm_sym_char_special;
+    else if (S_ISFIFO (mode))
+      ve[13] = scm_sym_fifo;
+    else if (S_ISSOCK (mode))
+      ve[13] = scm_sym_sock;
+    else
+      ve[13] = scm_sym_unknown;
+
+    ve[14] = SCM_MAKINUM ((~S_IFMT) & mode);
+
+    /* the layout of the bits in ve[14] is intended to be portable.
+       If there are systems that don't follow the usual convention,
+       the following could be used:
+
+       tmp = 0;
+       if (S_ISUID & mode) tmp += 1;
+       tmp <<= 1;
+       if (S_IRGRP & mode) tmp += 1;
+       tmp <<= 1;
+       if (S_ISVTX & mode) tmp += 1;
+       tmp <<= 1;
+       if (S_IRUSR & mode) tmp += 1;
+       tmp <<= 1;
+       if (S_IWUSR & mode) tmp += 1;
+       tmp <<= 1;
+       if (S_IXUSR & mode) tmp += 1;
+       tmp <<= 1;
+       if (S_IWGRP & mode) tmp += 1;
+       tmp <<= 1;
+       if (S_IXGRP & mode) tmp += 1;
+       tmp <<= 1;
+       if (S_IROTH & mode) tmp += 1;
+       tmp <<= 1;
+       if (S_IWOTH & mode) tmp += 1;
+       tmp <<= 1;
+       if (S_IXOTH & mode) tmp += 1; 
+
+       ve[14] = SCM_MAKINUM (tmp);
+       
+       */
+  }  
 
   return ans;
 }
 
 SCM_PROC (s_sys_stat, "stat", 1, 0, 0, scm_sys_stat);
-#ifdef __STDC__
-SCM 
-scm_sys_stat (SCM fd_or_path)
-#else
+
 SCM 
 scm_sys_stat (fd_or_path)
      SCM fd_or_path;
-#endif
 {
   int rv = 1;
   struct stat stat_temp;
 
   if (SCM_INUMP (fd_or_path))
     {
-      SCM_ASSERT (SCM_OPFPORTP (fd_or_path), fd_or_path, SCM_ARG1, s_sys_stat);
       rv = SCM_INUM (fd_or_path);
       SCM_SYSCALL (rv = fstat (rv, &stat_temp));
     }
@@ -616,7 +625,10 @@ scm_sys_stat (fd_or_path)
 
     }
   if (rv != 0)
-    scm_syserror (s_sys_stat);
+    scm_syserror_msg (s_sys_stat, "%s: %S",
+                     scm_listify (scm_makfrom0str (strerror (errno)),
+                                  fd_or_path,
+                                  SCM_UNDEFINED));
   return scm_stat2scm (&stat_temp);
 }
 
@@ -626,15 +638,11 @@ scm_sys_stat (fd_or_path)
  */
 
 SCM_PROC (s_sys_link, "link", 2, 0, 0, scm_sys_link);
-#ifdef __STDC__
-SCM 
-scm_sys_link (SCM oldpath, SCM newpath)
-#else
+
 SCM 
 scm_sys_link (oldpath, newpath)
      SCM oldpath;
      SCM newpath;
-#endif
 {
   int val;
 
@@ -653,15 +661,11 @@ scm_sys_link (oldpath, newpath)
 
 
 SCM_PROC (s_sys_rename, "rename-file", 2, 0, 0, scm_sys_rename);
-#ifdef __STDC__
-SCM 
-scm_sys_rename (SCM oldname, SCM newname)
-#else
+
 SCM 
 scm_sys_rename (oldname, newname)
      SCM oldname;
      SCM newname;
-#endif
 {
   int rv;
   SCM_ASSERT (SCM_NIMP (oldname) && SCM_STRINGP (oldname), oldname, SCM_ARG1, s_sys_rename);
@@ -690,14 +694,10 @@ scm_sys_rename (oldname, newname)
 
 
 SCM_PROC(s_sys_delete_file, "delete-file", 1, 0, 0, scm_sys_delete_file);
-#ifdef __STDC__
-SCM 
-scm_sys_delete_file (SCM str)
-#else
+
 SCM 
 scm_sys_delete_file (str)
      SCM str;
-#endif
 {
   int ans;
   SCM_ASSERT (SCM_NIMP (str) && SCM_STRINGP (str), str, SCM_ARG1, s_sys_delete_file);
@@ -709,15 +709,11 @@ scm_sys_delete_file (str)
 
 
 SCM_PROC (s_sys_mkdir, "mkdir", 1, 1, 0, scm_sys_mkdir);
-#ifdef __STDC__
-SCM 
-scm_sys_mkdir (SCM path, SCM mode)
-#else
+
 SCM 
 scm_sys_mkdir (path, mode)
      SCM path;
      SCM mode;
-#endif
 {
 #ifdef HAVE_MKDIR
   int rv;
@@ -746,14 +742,10 @@ scm_sys_mkdir (path, mode)
 
 
 SCM_PROC (s_sys_rmdir, "rmdir", 1, 0, 0, scm_sys_rmdir);
-#ifdef __STDC__
-SCM 
-scm_sys_rmdir (SCM path)
-#else
+
 SCM 
 scm_sys_rmdir (path)
      SCM path;
-#endif
 {
 #ifdef HAVE_RMDIR
   int val;
@@ -777,14 +769,10 @@ scm_sys_rmdir (path)
 long scm_tc16_dir;
 
 SCM_PROC (s_sys_opendir, "opendir", 1, 0, 0, scm_sys_opendir);
-#ifdef __STDC__
-SCM 
-scm_sys_opendir (SCM dirname)
-#else
+
 SCM 
 scm_sys_opendir (dirname)
      SCM dirname;
-#endif
 {
   DIR *ds;
   SCM dir;
@@ -794,7 +782,7 @@ scm_sys_opendir (dirname)
   SCM_SYSCALL (ds = opendir (SCM_CHARS (dirname)));
   if (ds == NULL)
     scm_syserror (s_sys_opendir);
-  SCM_CAR (dir) = scm_tc16_dir | SCM_OPN;
+  SCM_SETCAR (dir, scm_tc16_dir | SCM_OPN);
   SCM_SETCDR (dir, ds);
   SCM_ALLOW_INTS;
   return dir;
@@ -802,14 +790,10 @@ scm_sys_opendir (dirname)
 
 
 SCM_PROC (s_sys_readdir, "readdir", 1, 0, 0, scm_sys_readdir);
-#ifdef __STDC__
-SCM 
-scm_sys_readdir (SCM port)
-#else
+
 SCM 
 scm_sys_readdir (port)
      SCM port;
-#endif
 {
   struct dirent *rdent;
   SCM_DEFER_INTS;
@@ -826,14 +810,10 @@ scm_sys_readdir (port)
 
 
 SCM_PROC (s_rewinddir, "rewinddir", 1, 0, 0, scm_rewinddir);
-#ifdef __STDC__
-SCM 
-scm_rewinddir (SCM port)
-#else
+
 SCM 
 scm_rewinddir (port)
      SCM port;
-#endif
 {
   SCM_ASSERT (SCM_NIMP (port) && SCM_OPDIRP (port), port, SCM_ARG1, s_rewinddir);
   rewinddir ((DIR *) SCM_CDR (port));
@@ -843,14 +823,10 @@ scm_rewinddir (port)
 
 
 SCM_PROC (s_sys_closedir, "closedir", 1, 0, 0, scm_sys_closedir);
-#ifdef __STDC__
-SCM 
-scm_sys_closedir (SCM port)
-#else
+
 SCM 
 scm_sys_closedir (port)
      SCM port;
-#endif
 {
   int sts;
 
@@ -864,36 +840,32 @@ scm_sys_closedir (port)
   SCM_SYSCALL (sts = closedir ((DIR *) SCM_CDR (port)));
   if (sts != 0)
     scm_syserror (s_sys_closedir);
-  SCM_CAR (port) = scm_tc16_dir;
+  SCM_SETCAR (port, scm_tc16_dir);
   SCM_ALLOW_INTS;
   return SCM_UNSPECIFIED;
 }
 
 
 
-#ifdef __STDC__
-static int 
-scm_dir_print (SCM sexp, SCM port, int writing)
-#else
+
+static int scm_dir_print SCM_P ((SCM sexp, SCM port, scm_print_state *pstate));
+
 static int 
-scm_dir_print (sexp, port, writing)
+scm_dir_print (sexp, port, pstate)
      SCM sexp;
      SCM port;
-     int writing;
-#endif
+     scm_print_state *pstate;
 {
   scm_prinport (sexp, port, "directory");
   return 1;
 }
 
-#ifdef __STDC__
-static scm_sizet 
-scm_dir_free (SCM p)
-#else
+
+static scm_sizet scm_dir_free SCM_P ((SCM p));
+
 static scm_sizet 
 scm_dir_free (p)
      SCM p;
-#endif
 {
   if (SCM_OPENP (p))
     closedir ((DIR *) SCM_CDR (p));
@@ -908,14 +880,10 @@ static scm_smobfuns dir_smob = {scm_mark0, scm_dir_free, scm_dir_print, 0};
 
 
 SCM_PROC (s_sys_chdir, "chdir", 1, 0, 0, scm_sys_chdir);
-#ifdef __STDC__
-SCM 
-scm_sys_chdir (SCM str)
-#else
+
 SCM 
 scm_sys_chdir (str)
      SCM str;
-#endif
 {
   int ans;
 
@@ -929,13 +897,9 @@ scm_sys_chdir (str)
 
 
 SCM_PROC (s_sys_getcwd, "getcwd", 0, 0, 0, scm_sys_getcwd);
-#ifdef __STDC__
-SCM 
-scm_sys_getcwd (void)
-#else
+
 SCM 
 scm_sys_getcwd ()
-#endif
 {
 #ifdef HAVE_GETCWD
   char *rv;
@@ -967,15 +931,13 @@ scm_sys_getcwd ()
 
 \f
 
-#ifdef __STDC__
-static void
-fill_select_type (SELECT_TYPE * set, SCM list)
-#else
+
+static void fill_select_type SCM_P ((SELECT_TYPE * set, SCM list));
+
 static void
 fill_select_type (set, list)
      SELECT_TYPE * set;
      SCM list;
-#endif
 {
   while (list != SCM_EOL)
     {
@@ -991,15 +953,13 @@ fill_select_type (set, list)
     }
 }
 
-#ifdef __STDC__
-static SCM 
-retrieve_select_type (SELECT_TYPE * set, SCM list)
-#else
+
+static SCM retrieve_select_type SCM_P ((SELECT_TYPE * set, SCM list));
+
 static SCM 
 retrieve_select_type (set, list)
      SELECT_TYPE * set;
      SCM list;
-#endif
 {
   SCM answer;
   answer = SCM_EOL;
@@ -1028,11 +988,11 @@ retrieve_select_type (set, list)
 }
 
 
+/* {Checking for events}
+ */
+
 SCM_PROC (s_sys_select, "select", 3, 2, 0, scm_sys_select);
-#ifdef __STDC__
-SCM
-scm_sys_select (SCM reads, SCM writes, SCM excepts, SCM secs, SCM msecs)
-#else
+
 SCM
 scm_sys_select (reads, writes, excepts, secs, msecs)
      SCM reads;
@@ -1040,7 +1000,6 @@ scm_sys_select (reads, writes, excepts, secs, msecs)
      SCM excepts;
      SCM secs;
      SCM msecs;
-#endif
 {
 #ifdef HAVE_SELECT
   struct timeval timeout;
@@ -1080,9 +1039,9 @@ scm_sys_select (reads, writes, excepts, secs, msecs)
   SCM_DEFER_INTS;
   sreturn = select (SELECT_SET_SIZE,
                    &read_set, &write_set, &except_set, time_p);
-  SCM_ALLOW_INTS;
   if (sreturn < 0)
     scm_syserror (s_sys_select);
+  SCM_ALLOW_INTS;
   return scm_listify (retrieve_select_type (&read_set, reads),
                      retrieve_select_type (&write_set, writes),
                      retrieve_select_type (&except_set, excepts),
@@ -1094,20 +1053,127 @@ scm_sys_select (reads, writes, excepts, secs, msecs)
 #endif
 }
 
+/* Check if FILE has characters waiting to be read.  */
+
+#ifdef __IBMC__
+# define MSDOS
+#endif
+#ifdef MSDOS
+# ifndef GO32
+#  include <io.h>
+#  include <conio.h>
+
+int 
+scm_input_waiting_p (f, caller)
+     FILE *f;
+     char *caller;
+{
+  if (feof (f))
+    return 1;
+  if (fileno (f) == fileno (stdin) && (isatty (fileno (stdin))))
+    return kbhit ();
+  return -1;
+}
+
+# endif
+#else
+# ifdef _DCC
+#  include <ioctl.h>
+# else
+#  ifndef AMIGA
+#   ifndef vms
+#    ifdef MWC
+#     include <sys/io.h>
+#    else
+#     ifndef THINK_C
+#      ifndef ARM_ULIB
+#       include <sys/ioctl.h>
+#      endif
+#     endif
+#    endif
+#   endif
+#  endif
+# endif
+
+int
+scm_input_waiting_p (f, caller)
+     FILE *f;
+     char *caller;
+{
+  /* Can we return an end-of-file character? */
+  if (feof (f))
+    return 1;
+
+  /* Do we have characters in the stdio buffer? */
+# ifdef FILE_CNT_FIELD
+  if (f->FILE_CNT_FIELD > 0)
+    return 1;
+# else
+#  ifdef FILE_CNT_GPTR
+  if (f->_gptr != f->_egptr)
+    return 1;
+# else
+#   ifdef FILE_CNT_READPTR
+  if (f->_IO_read_end != f->_IO_read_ptr)
+    return 1;
+#   else
+  Configure.in could not guess the name of the correct field in a FILE *.
+  This function needs to be ported to your system.
+  It should return zero iff no characters are waiting to be read.;
+#   endif
+#  endif
+# endif
+
+  /* Is the file prepared to deliver input? */
+# ifdef HAVE_SELECT
+  {
+    struct timeval timeout;
+    SELECT_TYPE read_set;
+    SELECT_TYPE write_set;
+    SELECT_TYPE except_set;
+    int fno = fileno ((FILE *)f);
+
+    FD_ZERO (&read_set);
+    FD_ZERO (&write_set);
+    FD_ZERO (&except_set);
+
+    FD_SET (fno, &read_set);
+
+    timeout.tv_sec = 0;
+    timeout.tv_usec = 0;
+
+    SCM_DEFER_INTS;
+    if (select (SELECT_SET_SIZE,
+               &read_set, &write_set, &except_set, &timeout)
+       < 0)
+      scm_syserror (caller);
+    SCM_ALLOW_INTS;
+    return FD_ISSET (fno, &read_set);
+  }
+# else
+# ifdef FIONREAD
+  {
+    long remir;
+    ioctl(fileno(f), FIONREAD, &remir);
+    return remir;
+  }
+#  else    
+  scm_misc_error ("char-ready?", "Not fully implemented\n");
+#  endif
+# endif
+}
+#endif
+
 \f
 /* {Symbolic Links} 
  */
 
 SCM_PROC (s_sys_symlink, "symlink", 2, 0, 0, scm_sys_symlink);
-#ifdef __STDC__
-SCM
-scm_sys_symlink(SCM oldpath, SCM newpath)
-#else
+
 SCM
 scm_sys_symlink(oldpath, newpath)
      SCM oldpath;
      SCM newpath;
-#endif
 {
 #ifdef HAVE_SYMLINK
   int val;
@@ -1127,14 +1193,10 @@ scm_sys_symlink(oldpath, newpath)
 
 
 SCM_PROC (s_sys_readlink, "readlink", 1, 0, 0, scm_sys_readlink);
-#ifdef __STDC__
-SCM
-scm_sys_readlink(SCM path)
-#else
+
 SCM
 scm_sys_readlink(path)
   SCM path;
-#endif
 {
 #ifdef HAVE_READLINK
   scm_sizet rv;
@@ -1165,14 +1227,10 @@ scm_sys_readlink(path)
 
 
 SCM_PROC (s_sys_lstat, "lstat", 1, 0, 0, scm_sys_lstat);
-#ifdef __STDC__
-SCM
-scm_sys_lstat(SCM str)
-#else
+
 SCM
 scm_sys_lstat(str)
   SCM str;
-#endif
 {
 #ifdef HAVE_LSTAT
   int rv;
@@ -1181,7 +1239,10 @@ scm_sys_lstat(str)
   SCM_ASSERT(SCM_NIMP(str) && SCM_STRINGP(str), str, (char *)SCM_ARG1, s_sys_lstat);
   SCM_SYSCALL(rv = lstat(SCM_CHARS(str), &stat_temp));
   if (rv != 0)
-    scm_syserror (s_sys_lstat);
+    scm_syserror_msg (s_sys_lstat, "%s: %S",
+                     scm_listify (scm_makfrom0str (strerror (errno)),
+                                  str,
+                                  SCM_UNDEFINED));
   return scm_stat2scm(&stat_temp);
 #else 
   scm_sysmissing (s_sys_lstat);
@@ -1192,15 +1253,11 @@ scm_sys_lstat(str)
 
 
 SCM_PROC (s_sys_copy_file, "copy-file", 2, 0, 0, scm_sys_copy_file);
-#ifdef __STDC__
-SCM
-scm_sys_copy_file (SCM oldfile, SCM newfile)
-#else
+
 SCM
 scm_sys_copy_file (oldfile, newfile)
      SCM oldfile;
      SCM newfile;
-#endif
 {
   int oldfd, newfd;
   int n;
@@ -1241,89 +1298,11 @@ scm_sys_copy_file (oldfile, newfile)
 }
 
 \f
-#ifdef __STDC__
-void
-scm_init_filesys (void)
-#else
+
 void
 scm_init_filesys ()
-#endif
 {
-  /* File type/permission bits.  */
-#ifdef S_IRUSR
-  scm_sysintern ("S_IRUSR", SCM_MAKINUM (S_IRUSR));
-#endif
-#ifdef S_IWUSR
-  scm_sysintern ("S_IWUSR", SCM_MAKINUM (S_IWUSR));
-#endif
-#ifdef S_IXUSR
-  scm_sysintern ("S_IXUSR", SCM_MAKINUM (S_IXUSR));
-#endif
-#ifdef S_IRWXU
-  scm_sysintern ("S_IRWXU", SCM_MAKINUM (S_IRWXU));
-#endif
-
-#ifdef S_IRGRP
-  scm_sysintern ("S_IRGRP", SCM_MAKINUM (S_IRGRP));
-#endif
-#ifdef S_IWGRP
-  scm_sysintern ("S_IWGRP", SCM_MAKINUM (S_IWGRP));
-#endif
-#ifdef S_IXGRP
-  scm_sysintern ("S_IXGRP", SCM_MAKINUM (S_IXGRP));
-#endif
-#ifdef S_IRWXG
-  scm_sysintern ("S_IRWXG", SCM_MAKINUM (S_IRWXG));
-#endif
-
-#ifdef S_IROTH
-  scm_sysintern ("S_IROTH", SCM_MAKINUM (S_IROTH));
-#endif
-#ifdef S_IWOTH
-  scm_sysintern ("S_IWOTH", SCM_MAKINUM (S_IWOTH));
-#endif
-#ifdef S_IXOTH
-  scm_sysintern ("S_IXOTH", SCM_MAKINUM (S_IXOTH));
-#endif
-#ifdef S_IRWXO
-  scm_sysintern ("S_IRWXO", SCM_MAKINUM (S_IRWXO));
-#endif
-
-#ifdef S_ISUID
-  scm_sysintern ("S_ISUID", SCM_MAKINUM (S_ISUID));
-#endif
-#ifdef S_ISGID
-  scm_sysintern ("S_ISGID", SCM_MAKINUM (S_ISGID));
-#endif
-#ifdef S_ISVTX
-  scm_sysintern ("S_ISVTX", SCM_MAKINUM (S_ISVTX));
-#endif
-
-#ifdef S_IFMT
-  scm_sysintern ("S_IFMT", SCM_MAKINUM (S_IFMT));
-#endif
-#ifdef S_IFDIR
-  scm_sysintern ("S_IFDIR", SCM_MAKINUM (S_IFDIR));
-#endif
-#ifdef S_IFCHR
-  scm_sysintern ("S_IFCHR", SCM_MAKINUM (S_IFCHR));
-#endif
-#ifdef S_IFBLK
-  scm_sysintern ("S_IFBLK", SCM_MAKINUM (S_IFBLK));
-#endif
-#ifdef S_IFREG
-  scm_sysintern ("S_IFREG", SCM_MAKINUM (S_IFREG));
-#endif
-#ifdef S_IFLNK
-  scm_sysintern ("S_IFLNK", SCM_MAKINUM (S_IFLNK));
-#endif
-#ifdef S_IFSOCK
-  scm_sysintern ("S_IFSOCK", SCM_MAKINUM (S_IFSOCK));
-#endif
-#ifdef S_IFIFO
-  scm_sysintern ("S_IFIFO", SCM_MAKINUM (S_IFIFO));
-#endif
-
+  scm_add_feature ("i/o-extensions");
 
   scm_tc16_fd = scm_newsmob (&fd_smob);
   scm_tc16_dir = scm_newsmob (&dir_smob);