converted a bunch more functions to use a fd instead of a FILE*
[abartlet/samba.git/.git] / source3 / printing / print_svid.c
index 21e8eeb643973d71ee2b2fda3ba0a35d55d9405c..301f38867195bfd4936ed66f76783f0a9f3c2e2d 100644 (file)
@@ -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);
 }