+ if ((lines = guestfs_ls (g, dir)) == NULL) {
+ return -1;
+ }
+
+ for (i = 0; lines[i] != NULL; ++i) {
+ printf ("%s\n", lines[i]);
+ free (lines[i]);
+ }
+ free (lines);
+
+ return 0;
+}
+
+static int
+do_ls_l (const char *dir)
+{
+ char *out;
+
+ if ((out = guestfs_ll (g, dir)) == NULL)
+ return -1;
+
+ printf ("%s", out);
+ free (out);
+
+ return 0;
+}
+
+static int
+do_ls_R (const char *dir)
+{
+ /* This is TMP_TEMPLATE_ON_STACK expanded from fish.h. */
+ const char *tmpdir = guestfs_tmpdir ();
+ char tmpfile[strlen (tmpdir) + 32];
+ sprintf (tmpfile, "%s/virtlsXXXXXX", tmpdir);
+
+ int fd = mkstemp (tmpfile);
+ if (fd == -1) {
+ perror ("mkstemp");
+ exit (EXIT_FAILURE);
+ }
+
+ char buf[BUFSIZ]; /* also used below */
+ snprintf (buf, sizeof buf, "/dev/fd/%d", fd);