summaryrefslogtreecommitdiff
path: root/source3/printing
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2000-04-16 11:00:21 +0000
committerAndrew Tridgell <tridge@samba.org>2000-04-16 11:00:21 +0000
commit19f946ba6fe442544ac9b0f71bcd33112fc79995 (patch)
tree1f26158879ef7eba4670d0811871077e921dc65b /source3/printing
parent83170b36c5511b000e36ad0d3a1d9b73a73d2046 (diff)
downloadsamba-19f946ba6fe442544ac9b0f71bcd33112fc79995.tar.gz
samba-19f946ba6fe442544ac9b0f71bcd33112fc79995.tar.bz2
samba-19f946ba6fe442544ac9b0f71bcd33112fc79995.zip
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)
Diffstat (limited to 'source3/printing')
-rw-r--r--source3/printing/print_svid.c83
1 files changed, 41 insertions, 42 deletions
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);
}