Convert-UUlib

 view release on metacpan or  search on metacpan

uulib/uulib.c  view on Meta::CPAN

  }

  fclose (datei);
  UUCLRBUF (uu_rbuf, datei_buf);

  if (!uu_fast_scanning && *partcount == 0)
    UUMessage (uulib_id, __LINE__, UUMSG_NOTE,
	       uustring (S_NO_DATA_FOUND), filename);

  progress.action = 0;
  if (uu_autocheck) UUCheckGlobalList ();

  return UURET_OK;
}

/*
 * decode to a temporary file. this is well handled by uudecode()
 */

int UUEXPORT
UUDecodeToTemp (uulist *thefile)
{
  return UUDecode (thefile);
}

/*
 * decode file first to temp file, then copy it to a final location
 */

int UUEXPORT
UUDecodeFile (uulist *thefile, char *destname)
{
  FILE *target, *source;
  void *target_buf, *source_buf;
  struct stat finfo;
  int fildes, res;
  size_t bytes;

  if (thefile == NULL)
    return UURET_ILLVAL;

  if ((res = UUDecode (thefile)) != UURET_OK)
    if (res != UURET_NOEND || !uu_desperate)
      return res;

  if (thefile->binfile == NULL) {
    UUMessage (uulib_id, __LINE__, UUMSG_ERROR,
	       uustring (S_NO_BIN_FILE));
    return UURET_IOERR;
  }

  if ((source = fopen (thefile->binfile, "rb")) == NULL) {
    UUMessage (uulib_id, __LINE__, UUMSG_ERROR,
	       uustring (S_NOT_OPEN_FILE),
	       thefile->binfile, strerror (uu_errno = errno));
    return UURET_IOERR;
  }
  UUSETBUF (source, source_buf, uu_rbuf);

  /*
   * for system security, strip setuid/setgid bits from mode
   */

  if ((thefile->mode & 0777) != thefile->mode) {
    UUMessage (uulib_id, __LINE__, UUMSG_NOTE,
	       uustring (S_STRIPPED_SETUID),
	       destname, (int)thefile->mode);
    thefile->mode &= 0777;
  }

  /*
   * Determine the name of the target file according to the rules:
   * 
   * IF (destname!=NULL) THEN filename=destname;
   * ELSE
   *   filename = thefile->filename
   *   IF (FilenameFilter!=NULL) THEN filename=FilenameFilter(filename);
   *   filename = SaveFilePath + filename
   * END
   */

  if (destname)
    strcpy (uugen_fnbuffer, destname);
  else {
    char *fname = UUFNameFilter (thefile->filename ? thefile->filename : "unknown.xxx");
    sprintf (uugen_fnbuffer, "%.1024s%.3071s",
	     uusavepath ? uusavepath : "",
             fname ? fname : "unknown.xxx");
  }

  /*
   * if we don't want to overwrite existing files, check if it's there
   */

  if (!uu_overwrite) {
    if (stat (uugen_fnbuffer, &finfo) == 0) {
      UUMessage (uulib_id, __LINE__, UUMSG_ERROR,
		 uustring (S_TARGET_EXISTS), uugen_fnbuffer);
      fclose (source);
      UUCLRBUF (uu_rbuf, source_buf);
      return UURET_EXISTS;
    }
  }

  if (fstat (fileno(source), &finfo) == -1) {
    UUMessage (uulib_id, __LINE__, UUMSG_ERROR,
	       uustring (S_NOT_STAT_FILE),
	       thefile->binfile, strerror (uu_errno = errno));
    fclose (source);
    UUCLRBUF (uu_rbuf, source_buf);
    return UURET_IOERR;
  }

  /* try rename() shortcut first */
  if (!rename (thefile->binfile, uugen_fnbuffer))
    {
      mode_t mask = 0000; /* there is a slight window here anyway */
#if HAVE_UMASK
      mask = umask (0022); umask (mask);
#endif
      fclose (source);



( run in 2.539 seconds using v1.01-cache-2.11-cpan-97f6503c9c8 )