Hylafax Developers Mailing List Archives

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

[hylafax-devel] Re: Fwd: File open patch (fwd)



At 09:19 PM 3/19/00 -0800, Tim Rice wrote:
>And looking ath the man page for lstat
>...
>
>Return values
>    On success, stat, lstat, fstat, stat64, lstat64, and fstat64 return 0.
>    On failure, they return -1 and set errno to identify the error.
>...

Ooops! try the third version attached.

- Robert

Index: HylaFAXServer.c+
==================================================================
RCS file: /usr/local/cvsroot/hylafax/hfaxd/HylaFAXServer.c++,
retrieving revision 1.
diff -u -r1.7 HylaFAXServer.c+
--- HylaFAXServer.c++	1999/11/18 12:18:57	1.
+++ HylaFAXServer.c++	2000/03/21 06:17:2
@@ -512,7 +512,25 @
 u_in
 HylaFAXServer::getSequenceNumber(const char* filename, u_int count, fxStr& emsg
 
-    int fd = Sys::open(filename, O_CREAT|O_RDWR|O_EXCL, 0600)
+    struct stat sb
+    int fd
+    int rtn = lstat(filename, &sb)
+    if (rtn != 0 && errno == ENOENT) 
+        fd = Sys::open(filename, O_CREAT | O_RDWR | O_EXCL, 0600)
+    } else if (rtn == 0 && S_ISREG(sb.st_mode)) 
+        fd = Sys::open(filename, O_RDWR, 0600)
+        struct stat sb2
+        if (fd < 0 || fstat(fd, &sb2)) 
+            //XXX some kind of error opening fil
+            fd = -1
+        } else if (sb.st_ino != sb2.st_ino || sb.st_dev != sb2.st_dev) 
+            //XXX something wrong with fil
+            fd = -1
+        
+    } else 
+        //XXX some kind of error opening fil
+        fd = -1
+    
     if (fd < 0) 
         emsg = fxStr::format("Unable to open sequence number file %s; %s."
             filename, strerror(errno))



Home
Report any problems to webmaster@hylafax.org

HylaFAX is a trademark of Silicon Graphics Corporation.
Internet connectivity for hylafax.org is provided by:
VirtuALL Private Host Services