From 28ab08cf065ebcbe519f317ccd1d34950f3a5ce1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fredrik=20H=C3=BCbinette=20=28Hubbe=29?= <hubbe@hubbe.net>
Date: Mon, 12 Aug 1996 18:57:13 +0200
Subject: [PATCH] bugfix, no more memory trashes...

Rev: src/modules/files/file.c:1.17
---
 src/modules/files/file.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/src/modules/files/file.c b/src/modules/files/file.c
index d3ada13753..b2b05ebdbc 100644
--- a/src/modules/files/file.c
+++ b/src/modules/files/file.c
@@ -46,6 +46,14 @@
 #include <netdb.h>
 #endif
 
+#ifndef SEEK_SET
+#define SEEK_SET 0
+#endif
+
+#ifndef SEEK_END
+#define SEEK_END 2
+#endif
+
 #define FD (*(int*)(fp->current_storage))
 #define THIS (files + FD)
 
@@ -451,14 +459,12 @@ static void file_open(INT32 args)
   if(!( flags &  (FILE_READ | FILE_WRITE)))
     error("Must open file for at least one of read and write.\n");
 
-  THIS->errno = 0;
-
  retry:
   fd=open(sp[-args].u.string->str,map(flags), 00666);
 
   if(fd >= MAX_OPEN_FILEDESCRIPTORS)
   {
-    THIS->errno=EBADF;
+    /* THIS->errno=EBADF;  THIS is invalid here...*/
     close(fd);
     fd=-1;
   }
@@ -467,13 +473,14 @@ static void file_open(INT32 args)
     if(errno == EINTR)
       goto retry;
 
-    THIS->errno=errno;
+    /* THIS->errno=EBADF;  THIS is invalid here...*/
   }
   else
   {
-    set_close_on_exec(fd,1);
     init_fd(fd,flags);
     FD=fd;
+    THIS->errno = 0;
+    set_close_on_exec(fd,1);
   }
 
   pop_n_elems(args);
@@ -1028,14 +1035,14 @@ static void file_open_socket(INT32 args)
   fd=socket(AF_INET, SOCK_STREAM, 0);
   if(fd >= MAX_OPEN_FILEDESCRIPTORS)
   {
-    THIS->errno = EBADF;
+    /* THIS->errno = EBADF;   THIS is invalid here ..*/
     pop_n_elems(args);
     push_int(0);
     return;
   }
   if(fd < 0)
   {
-    THIS->errno=errno;
+    /* THIS->errno = errno;   THIS is invalid here ..*/
     pop_n_elems(args);
     push_int(0);
     return;
-- 
GitLab