#include <stdio.h>

extern int skip2ctb(FILE *, unsigned char, unsigned char);

/*-------------------------*/
/* find a literal packet, go past the header, and copy out the data */
/* maybe return mode and filename later */
int getlit(FILE * inf, FILE * outf)
{
  int len, i;
  unsigned char dbuf[4096], t;

  i = skip2ctb(inf, 0xac, 0xfc);
  fgetc(inf);                   /* mode, text or binary */
  t = fgetc(inf);
  i -= t + 2;
  fread(dbuf, 1, t, inf);       /* fn */
#if 0
  dbuf[t] = 0;
  fprintf(stderr, "fn=%s\n", dbuf);
#endif
  fread(dbuf, 1, 4, inf);       /* timestamp */
  i -= 4;
  while (i) {
    len = fread(dbuf, 1, i > 4096 ? 4096 : i, inf);
    if (len <= 0)
      return -1;
    i -= len;
    fwrite(dbuf, 1, len, outf);
  }
  return 0;
}
