diff options
author | Keith Vetter <keithv@fusion.com> | 1995-03-23 03:46:07 +0000 |
---|---|---|
committer | Keith Vetter <keithv@fusion.com> | 1995-03-23 03:46:07 +0000 |
commit | eac84f862cc258b9515196d9c30777a7e261b872 (patch) | |
tree | 45c2c3b91e7903102ac2ce80fe06fc02d14a94af /src/lib/krb5/os/realm_dom.c | |
parent | c9075ac0ff51b881fe1d836948f8a648b3cc9708 (diff) | |
download | krb5-eac84f862cc258b9515196d9c30777a7e261b872.tar.gz krb5-eac84f862cc258b9515196d9c30777a7e261b872.tar.xz krb5-eac84f862cc258b9515196d9c30777a7e261b872.zip |
Work around of fscanf which is not available in a windows DLL
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@5202 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/lib/krb5/os/realm_dom.c')
-rw-r--r-- | src/lib/krb5/os/realm_dom.c | 59 |
1 files changed, 57 insertions, 2 deletions
diff --git a/src/lib/krb5/os/realm_dom.c b/src/lib/krb5/os/realm_dom.c index 4550bfbca0..be25e8d020 100644 --- a/src/lib/krb5/os/realm_dom.c +++ b/src/lib/krb5/os/realm_dom.c @@ -51,6 +51,56 @@ extern char *krb5_trans_file; +#ifdef _WINDOWS +/* + * Windows DLL can't use the fscanf routine. We need fscanf to read + * in the host and realm. Read_2str with read_1str duplicate the needed + * functionality. See also host_realm.c + */ +static int +read_1str (FILE *fp, char *buf, int buflen) { + int c; + + while (1) { + c = fgetc (fp); /* Past leading whitespace */ + if (c == EOF) + return 0; + if (! isspace (c)) + break; + } + + while (1) { + if (buflen > 0) { /* Store the character */ + *buf++ = (char) c; + --buflen; + } + if (buflen <= 0) /* Fscanf stops scanning... */ + break; /* ...when buffer is full */ + + c = fgetc (fp); /* Get next character */ + if (c == EOF || isspace (c)) + break; + } + + if (buflen) /* Make ASCIIZ if room */ + *buf = '\0'; + + return 1; +} + +static int +read_2str (FILE *fp, char *b1, int l1, char *b2, int l2) { + int n; + + n = read_1str (fp, b1, l1); /* Read first string */ + if (!n) return EOF; + n = read_1str (fp, b2, l2); /* Read second string */ + if (!n) return 1; + return 2; +} + +#endif /* _WINDOWS */ + krb5_error_code INTERFACE krb5_get_realm_domain(context, realm, domain) krb5_context context; @@ -82,8 +132,13 @@ krb5_get_realm_domain(context, realm, domain) (void) sprintf(scanstring, "%%%ds %%%ds", sizeof(trans_host)-1,sizeof(trans_realm)-1); while (1) { - if ((scanval = fscanf(trans_file, scanstring, - trans_host, trans_realm)) != 2) { + #ifdef _WINDOWS + scanval = read_2str (trans_file, trans_host, sizeof(trans_host)-1, + trans_realm, sizeof(trans_realm)-1); + #else + scanval = fscanf(trans_file, scanstring, trans_host, trans_realm)); + #endif + if (scanval != 2) { if (scanval == EOF) { fclose(trans_file); if (realmlist != NULL) { |