diff options
Diffstat (limited to 'ldap/systools/pio.c')
-rw-r--r-- | ldap/systools/pio.c | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/ldap/systools/pio.c b/ldap/systools/pio.c new file mode 100644 index 00000000..4d6593c0 --- /dev/null +++ b/ldap/systools/pio.c @@ -0,0 +1,94 @@ +/** BEGIN COPYRIGHT BLOCK + * Copyright 2001 Sun Microsystems, Inc. + * Portions copyright 1999, 2001-2003 Netscape Communications Corporation. + * All rights reserved. + * END COPYRIGHT BLOCK **/ + +#include "pio.h" +#include <ctype.h> +#include <string.h> +#include <stdlib.h> + +int iii_pio_procparse ( + const char *cmd, + int count, + struct iii_pio_parsetab *tb +) +{ + FILE *fp; + char buf[8192]; + int rc = 0; + + fp = popen(cmd,"r"); + + if (fp == NULL) { + return -1; + } + + while (fgets(buf,8192,fp) != NULL && rc >= 0) { + char *rp; + int i; + + rp = strchr(buf,'\n'); + + if (rp) { + *rp = '\0'; + } + + rp = strchr(buf,':'); + +#if defined(__osf__) + if (rp == NULL) { + rp = strchr(buf,'='); + } +#endif + + if (rp == NULL) continue; + + *rp = '\0'; + rp++; + while(isspace(*rp)) rp++; + + for (i = 0; i < count; i++) { + if (strcmp(tb[i].token,buf) == 0) { + rc = (tb[i].fn)(buf,rp); + break; + } + } + } + + pclose(fp); + + return rc; +} + +int iii_pio_getnum ( + const char *cmd, + long *valPtr +) +{ + FILE *fp; + char buf[8192]; + int rc = 0; + + fp = popen(cmd,"r"); + + if (fp == NULL) { + return -1; + } + + if (fgets(buf,8192,fp) == NULL) { + pclose(fp); + return -1; + } + + pclose(fp); + + if (!(isdigit(*buf))) { + return -1; + } + + *valPtr = atol(buf); + + return 0; +} |