scc_maybe.c: Added kludge for the Macintosh, since fopen() doesn't set
authorTheodore Tso <tytso@mit.edu>
Tue, 11 Nov 1997 01:45:42 +0000 (01:45 +0000)
committerTheodore Tso <tytso@mit.edu>
Tue, 11 Nov 1997 01:45:42 +0000 (01:45 +0000)
errno, although open() does.

git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@10272 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/krb5/ccache/stdio/ChangeLog
src/lib/krb5/ccache/stdio/scc_maybe.c

index 4e4aba9ecc9b3771765e447eaadad6201203c052..f8351fb8d51cfd679ffbec2022d5c28dac13e204 100644 (file)
@@ -1,3 +1,8 @@
+Wed Oct 29 15:57:31 1997  Theodore Y. Ts'o  <tytso@mit.edu>
+
+       * scc_maybe.c: Added kludge for the Macintosh, since fopen()
+               doesn't set errno, although open() does.
+
 Thu Sep 25 21:04:47 1997  Tom Yu  <tlyu@mit.edu>
 
        * scc_maybe.c (krb5_scc_open_file): Replace HAS_SETVBUF with
index 1f93922d4dd9884ff9c3ecf0042c613d717eff59..5b3544c345efa8db338700c2368482f5e4fada00 100644 (file)
 #include "scc.h"
 #include "k5-int.h"
 
+#ifdef _MACINTOSH
+/*
+ * Kludge for the Macintosh, since fopen doesn't set errno, but open
+ * does...
+ */
+static FILE *my_fopen(char *path, char *mode)
+{
+       int     fd, open_flags;
+       FILE    *f;
+
+       f = fopen(path, mode);
+       if (f)
+               return f;
+       /*
+        * OK, fopen failed; let's try to figure out why....
+        */
+       if (strchr(mode, '+'))
+               open_flags = O_RDWR;
+       else if (strchr(mode, 'w') || strchr(mode, 'a'))
+               open_flags = O_WRONLY;
+       else
+               open_flags = O_RDONLY;
+       if (strchr(mode, 'a'))
+               open_flags  |= O_APPEND;
+
+       fd = open(path, open_flags);
+       if (fd == -1)
+               return NULL;
+       /*
+        * fopen failed, but open succeeded?   W*E*I*R*D.....
+        */
+       close(fd);
+       errno = KRB5_CC_IO;
+       
+       return NULL;
+}
+#endif
+
 krb5_error_code
 krb5_scc_close_file (context, id)
    krb5_context context;
@@ -77,7 +115,6 @@ krb5_scc_open_file (context, id, mode)
     krb5_os_context os_ctx = (krb5_os_context) context->os_context;
     krb5_scc_data *data = (krb5_scc_data *) id->data;
     char fvno_bytes[2];                /* In nework byte order */
-    krb5_ui_2 scc_vno;
     krb5_ui_2 scc_tag;
     krb5_ui_2 scc_taglen;
     krb5_ui_2 scc_hlen;
@@ -125,7 +162,11 @@ krb5_scc_open_file (context, id, mode)
     }
 #endif
 
+#ifdef _MACINTOSH
+    f = my_fopen (data->filename, open_flag);
+#else
     f = fopen (data->filename, open_flag);
+#endif    
     if (!f)
        return krb5_scc_interpret (context, errno);
 #ifdef HAVE_SETVBUF
@@ -151,7 +192,6 @@ krb5_scc_open_file (context, id, mode)
     }
     if (mode == SCC_OPEN_AND_ERASE) {
        /* write the version number */
-       int errsave;
 
        data->file = f;
        data->version = context->scc_default_format;