+
+ r= asprintf(&cmd, "xwd -silent -id 0x%lx", (unsigned long)id); eassert(r>=0);
+ FILE *f= popen(cmd,"r"); eassert(f);
+
+ int need_alloc=1;
+ size_t used=0;
+ for (;;) {
+ size_t allow= snapshot_alloc - used;
+ if (!allow) {
+ snapshot_alloc <<= 1;
+ need_alloc= 1;
+ fprintf(stderr,"PAGING snapshot grow %ld\n", (long)snapshot_alloc);
+ continue;
+ }
+ if (need_alloc) {
+ *output= realloc(*output, sizeof(**output) + snapshot_alloc);
+ eassert(*output);
+ need_alloc= 0;
+ }
+ size_t got= fread((*output)->d, 1, allow, f);
+ if (got==0) break;
+ used += got;
+ }
+ check_pclose(f,cmd);
+
+ (*output)->len= used;
+ snapshot_alloc= used+1;
+ *output= realloc(*output, sizeof(**output) + snapshot_alloc);
+ eassert(*output);
+