From 19f946ba6fe442544ac9b0f71bcd33112fc79995 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 16 Apr 2000 11:00:21 +0000 Subject: converted a bunch more functions to use a fd instead of a FILE* to support some of this I added the following functions in util_file.c file_lines_pload : load lines from a pipe file_pload : load a pipe into memory (This used to be commit a09470817c5b21dba42f9ef4ce5e8b768a254c0b) --- source3/printing/print_svid.c | 83 +++++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 42 deletions(-) (limited to 'source3/printing') diff --git a/source3/printing/print_svid.c b/source3/printing/print_svid.c index 21e8eeb643..301f388671 100644 --- a/source3/printing/print_svid.c +++ b/source3/printing/print_svid.c @@ -47,50 +47,49 @@ static printer_t *printers = NULL; static void populate_printers(void) { - FILE *fp; - - if ((fp = sys_popen("/usr/bin/lpstat -v", "r", False)) != NULL) { - char buf[BUFSIZ]; - - while (fgets(buf, sizeof (buf), fp) != NULL) { - printer_t *ptmp; - char *name, *tmp; - - /* eat "system/device for " */ - if (((tmp = strchr(buf, ' ')) == NULL) || - ((tmp = strchr(++tmp, ' ')) == NULL)) - continue; - - /* - * In case we're only at the "for ". - */ - - if(!strncmp("for ",++tmp,4)) - { - tmp=strchr(tmp, ' '); - tmp++; - } - name = tmp; - - /* truncate the ": ..." */ - if ((tmp = strchr(name, ':')) != NULL) - *tmp = '\0'; - - /* add it to the cache */ - if ((ptmp = malloc(sizeof (*ptmp))) != NULL) { - ZERO_STRUCTP(ptmp); - if((ptmp->name = strdup(name)) == NULL) - DEBUG(0,("populate_printers: malloc fail in strdup !\n")); - ptmp->next = printers; - printers = ptmp; - } else { - DEBUG(0,("populate_printers: malloc fail for ptmp\n")); - } + char **lines; + int i; + + lines = file_lines_pload("/usr/bin/lpstat -v", NULL); + if (!lines) return; + + for (i=0;lines[i];i++) { + printer_t *ptmp; + char *name, *tmp; + char *buf = lines[i]; + + /* eat "system/device for " */ + if (((tmp = strchr(buf, ' ')) == NULL) || + ((tmp = strchr(++tmp, ' ')) == NULL)) + continue; + + /* + * In case we're only at the "for ". + */ + + if(!strncmp("for ",++tmp,4)) { + tmp=strchr(tmp, ' '); + tmp++; + } + name = tmp; + + /* truncate the ": ..." */ + if ((tmp = strchr(name, ':')) != NULL) + *tmp = '\0'; + + /* add it to the cache */ + if ((ptmp = malloc(sizeof (*ptmp))) != NULL) { + ZERO_STRUCTP(ptmp); + if((ptmp->name = strdup(name)) == NULL) + DEBUG(0,("populate_printers: malloc fail in strdup !\n")); + ptmp->next = printers; + printers = ptmp; + } else { + DEBUG(0,("populate_printers: malloc fail for ptmp\n")); } - sys_pclose(fp); - } else { - DEBUG(0,( "Unable to run lpstat!\n")); } + + file_lines_free(lines); } -- cgit