From d84652a447e184c33946a146c7e5518f080c21fc Mon Sep 17 00:00:00 2001 From: Mark Eichin Date: Mon, 2 Oct 1995 19:20:59 +0000 Subject: [PATCH] * prof_init.c (profile_init_path): takes a single string entry that has pathnames seperated by colons, and splits it into file names for profile_init. No provision for quoting colons in pathnames, but shells don't solve that either. * prof_init.c (profile_init): handle multiple input files by grabbing the first one that doesn't return ENOENT. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@6914 dc483132-0cff-0310-8789-dd5450dbe970 --- src/util/profile/ChangeLog | 12 +++++++ src/util/profile/prof_init.c | 62 ++++++++++++++++++++++++++++++++++++ src/util/profile/prof_int.h | 3 ++ 3 files changed, 77 insertions(+) diff --git a/src/util/profile/ChangeLog b/src/util/profile/ChangeLog index b25d40272..72ca7ed7e 100644 --- a/src/util/profile/ChangeLog +++ b/src/util/profile/ChangeLog @@ -1,3 +1,15 @@ +Tue Sep 26 20:00:28 1995 Mark Eichin + + * prof_init.c (profile_init_path): takes a single string entry + that has pathnames seperated by colons, and splits it into + file names for profile_init. No provision for quoting colons in + pathnames, but shells don't solve that either. + +Tue Sep 26 19:23:59 1995 Mark Eichin + + * prof_init.c (profile_init): handle multiple input files by + grabbing the first one that doesn't return ENOENT. + Mon Sep 25 16:42:13 1995 Theodore Y. Ts'o * Makefile.in: Removed "foo:: foo-$(WHAT)" lines from the diff --git a/src/util/profile/prof_init.c b/src/util/profile/prof_init.c index 581605adb..060675cab 100644 --- a/src/util/profile/prof_init.c +++ b/src/util/profile/prof_init.c @@ -40,6 +40,10 @@ errcode_t profile_init(filenames, ret_profile) for (fn = filenames; *fn; fn++) { retval = profile_open_file(*fn, &new_file); + /* if this file is missing, skip to the next */ + if (retval == ENOENT) { + continue; + } if (retval) { profile_release(profile); return retval; @@ -49,11 +53,69 @@ errcode_t profile_init(filenames, ret_profile) else profile->first_file = new_file; last = new_file; + /* since we actually got something, don't loop again */ + /* (at least until we understand what multiple files mean) */ + break; + } + /* if the last file was missing, they all were, so report such */ + if (retval == ENOENT) { + profile_release(profile); + return retval; } *ret_profile = profile; return 0; } +errcode_t profile_init_path(filepath, ret_profile) + const char *filepath; + profile_t *ret_profile; +{ + int n_entries, i; + int ent_len; + char *s, *t; + char **filenames; + errcode_t retval; + + /* count the distinct filename components */ + for(s = filepath, n_entries = 1; *s; s++) { + if (*s == ':') + n_entries++; + } + + /* the array is NULL terminated */ + filenames = (char**) malloc((n_entries+1) * sizeof(char*)); + if (filenames == 0) + return ENOMEM; + + /* measure, copy, and skip each one */ + for(s = filepath, i=0; (t = strchr(s, ':')) || (t=s+strlen(s)); s=t+1, i++) { + ent_len = t-s; + filenames[i] = (char*) malloc(ent_len + 1); + if (filenames[i] == 0) { + /* if malloc fails, free the ones that worked */ + while(--i >= 0) free(filenames[i]); + return ENOMEM; + } + strncpy(filenames[i], s, ent_len); + filenames[i][ent_len] = 0; + if (*t == 0) { + i++; + break; + } + } + /* cap the array */ + filenames[i] = 0; + + retval = profile_init(filenames, ret_profile); + + /* count back down and free the entries */ + while(--i >= 0) free(filenames[i]); + free(filenames); + + return retval; +} + + void profile_release(profile) profile_t profile; { diff --git a/src/util/profile/prof_int.h b/src/util/profile/prof_int.h index 48ec888db..46a7d5a55 100644 --- a/src/util/profile/prof_int.h +++ b/src/util/profile/prof_int.h @@ -131,6 +131,9 @@ extern errcode_t profile_close_file errcode_t profile_init PROTOTYPE ((const char **filenames, profile_t *ret_profile)); +errcode_t profile_init_path + PROTOTYPE ((const char *filepath, profile_t *ret_profile)); + extern void profile_release PROTOTYPE ((profile_t profile)); -- 2.26.2