[Libsysio-commit] HEAD: libsysio/src init.c
Brought to you by:
lward
From: Lee W. <lw...@us...> - 2004-11-29 23:55:16
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1404/src Modified Files: init.c Log Message: Ok, round 3 with the _sysio_boot function. Every time I add a new little option, I'm going to break the Cray crt0 build. New deal, then. Now, _sysio_boot takes a name and value pair. We call it repeatedly for different pairs, then. To support legacy, the name/value pairs are: "namespace" and the buffer is the argument "cwd" and the deferred, initial path is the argument Since it's now 2 calls, I suggest "namespace" first, then "cwd" to preserve the older behavior. As previously, _sysio_boot still returns 0 on success or a, negated, error number. Now, though, you know which failed :-) You decide if it's fatal. I've also added a new pair identified by "tracing" that enables tracing if configured for it. The value is a readable string, expected to parse as a number by strtol. Then, it should turn into a 0 or positive. Zero, being off and positive being on. Index: init.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/init.c,v retrieving revision 1.19 retrieving revision 1.20 diff -u -w -b -B -p -r1.19 -r1.20 --- init.c 19 Nov 2004 17:49:54 -0000 1.19 +++ init.c 29 Nov 2004 23:55:01 -0000 1.20 @@ -89,6 +89,17 @@ int _sysio_tracing = 0; #define IGNORE_WHITE " \t\r\n" /* + * Check if long overflows integer range. + */ +#if LONG_MAX <= INT_MAX +#define _irecheck(_l, _e) \ + ((_l) == LONG_MAX && (_e) == ERANGE) +#else +#define _irecheck(_l, _e) \ + ((_l) > INT_MAX) +#endif + +/* * Sysio library initialization. Must be called before anything else in the * library. */ @@ -682,17 +693,6 @@ do_open(char *args) int err; struct file *fil; -/* - * Check if long overflows integer range. - */ -#if LONG_MAX <= INT_MAX -#define _irecheck(_l, _e) \ - ((_l) == LONG_MAX && (_e) == ERANGE) -#else -#define _irecheck(_l, _e) \ - ((_l) > INT_MAX) -#endif - len = strlen(args); if (_sysio_get_args(args, v) - args != (ssize_t )len || !(v[0].ovi_value && v[1].ovi_value && v[2].ovi_value)) @@ -735,8 +735,6 @@ do_open(char *args) if (pno) P_RELE(pno); return err; - -#undef _irecheck } /* @@ -769,30 +767,41 @@ do_command(char *buf) return -EINVAL; } +#if SYSIO_TRACING /* - * Given a command sequence buffer, parse it and run the given - * commands + * Set/Unset tracing. */ -int -_sysio_boot(struct _sysio_boot_ctl *ctl) +static int +_sysio_boot_tracing(const char *arg) +{ + long l; + char *cp; + + l = 0; + if (arg) { + l = strtol(arg, (char **)&cp, 0); + if (*cp || !(l == 0 || l == 1)) + return -EINVAL; + } + _sysio_tracing = (int )l; + return 0; +} +#endif + +/* + * Initialize the namespace. + */ +static int +_sysio_boot_namespace(const char *arg) { - const char *buf; char c, *tok; ssize_t len; int err; unsigned count; - -#if SYSIO_TRACING - _sysio_tracing = ctl->tracing; -#endif - - buf = ctl->buf; - if (!buf) - buf = ""; /* * Allocate token buffer. */ - len = strlen(buf); + len = strlen(arg); tok = malloc(len ? len : 1); if (!tok) return -ENOMEM; @@ -802,9 +811,9 @@ _sysio_boot(struct _sysio_boot_ctl *ctl) /* * Discard leading white space. */ - while ((c = *buf) != '\0' && + while ((c = *arg) != '\0' && !(c == '{' || strchr(IGNORE_WHITE, c) == NULL)) - buf++; + arg++; if (c == '\0') break; if (c != '{') { @@ -815,13 +824,13 @@ _sysio_boot(struct _sysio_boot_ctl *ctl) * Get the command. */ *tok = '\0'; - buf = - (char *)_sysio_get_token(buf + 1, + arg = + (char *)_sysio_get_token(arg + 1, 0, "}", IGNORE_WHITE, tok); - if (!buf) { + if (!arg) { err = -EINVAL; break; } @@ -841,10 +850,55 @@ _sysio_boot(struct _sysio_boot_ctl *ctl) strerror(-err)); #endif free(tok); -#if DEFER_INIT_CWD - if (err) return err; - _sysio_init_cwd = ctl->path; +} + +#if DEFER_INIT_CWD +/* + * Set deferred initial working directory. + */ +static int +_sysio_boot_cwd(const char *arg) +{ + + _sysio_init_cwd = arg; + return 0; +} #endif - return err; + +/* + * Given an identifier and it's arguments, perform optional initializations. + */ +int +_sysio_boot(const char *opt, const char *arg) +{ + struct option_value_info vec[] = { +#if SYSIO_TRACING + { "trace", NULL }, /* tracing? */ +#endif + { "namespace", NULL }, /* init namespace? */ +#if DEFER_INIT_CWD + { "cwd", NULL }, /* init working dir */ +#endif + { NULL, NULL } + }; + struct option_value_info *v; + unsigned u; + static int (*f[])(const char *) = { +#if SYSIO_TRACING + _sysio_boot_tracing, +#endif + _sysio_boot_namespace, +#if DEFER_INIT_CWD + _sysio_boot_cwd, +#endif + NULL /* can't happen */ + }; + + for (v = vec, u = 0; v->ovi_name; v++, u++) + if (strcmp(v->ovi_name, opt) == 0) + break; + if (!v->ovi_name) + return -EINVAL; + return (*f[u])(arg); } |