Convert-UUlib

 view release on metacpan or  search on metacpan

uulib/uunconc.c  view on Meta::CPAN

      count += UUDecodeLine (save[tf], oline + count, method);
    if (count) {
      if (method == BH_ENCODED) {
	if (UUbhwrite (oline, 1, count, dataout) != count) {
	  UUMessage (uunconc_id, __LINE__, UUMSG_ERROR,
		     uustring (S_WR_ERR_TEMP),
		     strerror (uu_errno = errno));
	  return UURET_IOERR;
	}
      }
      else if (fwrite (oline, 1, count, dataout) != count) {
	UUMessage (uunconc_id, __LINE__, UUMSG_ERROR,
		   uustring (S_WR_ERR_TEMP),
		   strerror (uu_errno = errno));
	return UURET_IOERR;
      }
    }
  }
  return UURET_OK;
}

/*
 * this function decodes the file into a temporary file
 */

int
UUDecode (uulist *data)
{
  int state=BEGIN, part=-1, res=0, hb;
  unsigned long rsize, dsize, numbytes;
  FILE *datain, *dataout;
  void *datain_buf, *dataout_buf;
  unsigned char r[8];
  char *mode, *ntmp;
  uufile *iter;
  size_t bytes;
#ifdef HAVE_MKSTEMP
  int tmpfd;
  const char *tmpprefix = "uuXXXXXX";
  char *tmpdir = NULL;
#endif /* HAVE_MKSTEMP */

  if (data == NULL || data->thisfile == NULL)
    return UURET_ILLVAL;

  if (data->state & UUFILE_TMPFILE)
    return UURET_OK;

  if (data->state & UUFILE_NODATA)
    return UURET_NODATA;

  if (data->state & UUFILE_NOBEGIN && !uu_desperate)
    return UURET_NODATA;

  if (data->uudet == PT_ENCODED)
    mode = "wt";	/* open text files in text mode */
  else
    mode = "wb";	/* otherwise in binary          */

#ifdef HAVE_MKSTEMP
  if ((getuid()==geteuid()) && (getgid()==getegid())) {
	  tmpdir=getenv("TMPDIR");
  }

  if (!tmpdir) {
	  tmpdir = "/tmp";
  }
  data->binfile = malloc(strlen(tmpdir)+strlen(tmpprefix)+2);

  if (!data->binfile) {
#else
  if ((data->binfile = tempnam (NULL, "uu")) == NULL) {
#endif /* HAVE_MKSTEMP */
    UUMessage (uunconc_id, __LINE__, UUMSG_ERROR,
	       uustring (S_NO_TEMP_NAME));
    return UURET_NOMEM;
  }

#ifdef HAVE_MKSTEMP
  strcpy(data->binfile, tmpdir);
  strcat(data->binfile, "/");
  strcat(data->binfile, tmpprefix);

  if ((tmpfd = mkstemp(data->binfile)) == -1 || 
	  (dataout = fdopen(tmpfd, mode)) == NULL) {
#else
  if ((dataout = fopen (data->binfile, mode)) == NULL) {
#endif /* HAVE_MKSTEMP */
    /*
     * we couldn't create a temporary file. Usually this means that TMP
     * and TEMP aren't set
     */
    UUMessage (uunconc_id, __LINE__, UUMSG_ERROR,
	       uustring (S_WR_ERR_TARGET),
	       data->binfile, strerror (uu_errno = errno));
#ifdef HAVE_MKSTEMP
	if (tmpfd != -1) {
		unlink(data->binfile);
		close(tmpfd);
    }
#endif /* HAVE_MKSTEMP */
    _FP_free (data->binfile);
    data->binfile = NULL;
    uu_errno = errno;
    return UURET_IOERR;
  }
  UUSETBUF (dataout, dataout_buf, uu_wbuf);

  /*
   * we don't have begin lines in Base64 or plain text files.
   */
  if (data->uudet == B64ENCODED || data->uudet == QP_ENCODED ||
      data->uudet == PT_ENCODED)
    state = DATA;

  /*
   * If we know that the file does not have a begin, we simulate
   * it in desperate mode
   */

  if ((data->state & UUFILE_NOBEGIN) && uu_desperate)



( run in 1.050 second using v1.01-cache-2.11-cpan-5735350b133 )