From: Theodore Tso Date: Tue, 11 Nov 1997 01:45:42 +0000 (+0000) Subject: scc_maybe.c: Added kludge for the Macintosh, since fopen() doesn't set X-Git-Tag: krb5-1.1-beta1~958 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=f9ec66d08b60dd5b39980f6fb433f15ff3a9ad26;p=krb5.git scc_maybe.c: Added kludge for the Macintosh, since fopen() doesn't set errno, although open() does. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@10272 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/krb5/ccache/stdio/ChangeLog b/src/lib/krb5/ccache/stdio/ChangeLog index 4e4aba9ec..f8351fb8d 100644 --- a/src/lib/krb5/ccache/stdio/ChangeLog +++ b/src/lib/krb5/ccache/stdio/ChangeLog @@ -1,3 +1,8 @@ +Wed Oct 29 15:57:31 1997 Theodore Y. Ts'o + + * 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 * scc_maybe.c (krb5_scc_open_file): Replace HAS_SETVBUF with diff --git a/src/lib/krb5/ccache/stdio/scc_maybe.c b/src/lib/krb5/ccache/stdio/scc_maybe.c index 1f93922d4..5b3544c34 100644 --- a/src/lib/krb5/ccache/stdio/scc_maybe.c +++ b/src/lib/krb5/ccache/stdio/scc_maybe.c @@ -29,6 +29,44 @@ #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;