Convert-UUlib
view release on metacpan or search on metacpan
uulib/uulib.c view on Meta::CPAN
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);
UUCLRBUF (uu_rbuf, source_buf);
#if HAVE_CHMOD
chmod (uugen_fnbuffer, thefile->mode & ~mask);
#endif
goto skip_copy;
}
progress.action = 0;
_FP_strncpy (progress.curfile,
(strlen(uugen_fnbuffer)>255)?
(uugen_fnbuffer+strlen(uugen_fnbuffer)-255):uugen_fnbuffer,
256);
progress.partno = 0;
progress.numparts = 1;
progress.fsize = (long) ((finfo.st_size)?finfo.st_size:-1);
progress.foffset = 0;
progress.percent = 0;
progress.action = UUACT_COPYING;
if ((fildes = open (uugen_fnbuffer,
O_WRONLY | O_CREAT | O_BINARY | O_TRUNC,
(uu_ignmode)?0666:thefile->mode)) == -1) {
progress.action = 0;
UUMessage (uulib_id, __LINE__, UUMSG_ERROR,
uustring (S_NOT_OPEN_TARGET),
uugen_fnbuffer, strerror (uu_errno = errno));
fclose (source);
UUCLRBUF (uu_rbuf, source_buf);
return UURET_IOERR;
}
if ((target = fdopen (fildes, "wb")) == NULL) {
progress.action = 0;
UUMessage (uulib_id, __LINE__, UUMSG_ERROR,
uustring (S_IO_ERR_TARGET),
uugen_fnbuffer, strerror (uu_errno = errno));
fclose (source);
UUCLRBUF (uu_rbuf, source_buf);
close (fildes);
return UURET_IOERR;
}
UUSETBUF (target, target_buf, uu_wbuf);
while (!feof (source)) {
if (UUBUSYPOLL(ftell(source),progress.fsize)) {
UUMessage (uulib_id, __LINE__, UUMSG_NOTE,
uustring (S_DECODE_CANCEL));
fclose (source);
UUCLRBUF (uu_rbuf, source_buf);
fclose (target);
UUCLRBUF (uu_wbuf, target_buf);
unlink (uugen_fnbuffer);
return UURET_CANCEL;
}
bytes = fread (uugen_inbuffer, 1, 1024, source);
if (ferror (source) || (bytes == 0 && !feof (source))) {
progress.action = 0;
UUMessage (uulib_id, __LINE__, UUMSG_ERROR,
uustring (S_READ_ERROR),
thefile->binfile, strerror (uu_errno = errno));
( run in 0.685 second using v1.01-cache-2.11-cpan-39bf76dae61 )