Copy one file to another for the UUCP package.
Copyright (C) 1991, 1992 Ian Lance Taylor
This file is part of the Taylor UUCP package.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
The author of the program may be contacted at ian@airs.com or
c/o Infinity Development Systems, P.O. Box 520, Waltham, MA 02254.
const char copy_rcsid
[] = "$Id: copy.c,v 1.1 1993/08/04 19:30:44 jtc Exp $";
/* Copy one file to another. */
fcopy_file (zfrom
, zto
, fpublic
, fmkdirs
)
efrom
= fopen (zfrom
, BINREAD
);
ulog (LOG_ERROR
, "fopen (%s): %s", zfrom
, strerror (errno
));
fret
= fcopy_open_file (efrom
, zto
, fpublic
, fmkdirs
);
fcopy_open_file (efrom
, zto
, fpublic
, fmkdirs
)
eto
= esysdep_fopen (zto
, fpublic
, FALSE
, fmkdirs
);
while ((c
= fread (ab
, sizeof (char), sizeof ab
, efrom
)) != 0)
if (fwrite (ab
, sizeof (char), (size_t) c
, eto
) != c
)
ulog (LOG_ERROR
, "fwrite: %s", strerror (errno
));
ulog (LOG_ERROR
, "fclose: %s", strerror (errno
));
fcopy_file (zfrom
, zto
, fpublic
, fmkdirs
)
ofrom
= open (zfrom
, O_RDONLY
| O_NOCTTY
, 0);
ulog (LOG_ERROR
, "open (%s): %s", zfrom
, strerror (errno
));
fret
= fcopy_open_file (ofrom
, zto
, fpublic
, fmkdirs
);
fcopy_open_file (ofrom
, zto
, fpublic
, fmkdirs
)
/* These file mode arguments are from the UNIX version of sysdep.h;
each system dependent header file will need their own
oto
= creat (zto
, fpublic
? IPUBLIC_FILE_MODE
: IPRIVATE_FILE_MODE
);
if (errno
== ENOENT
&& fmkdirs
)
if (! fsysdep_make_dirs (zto
, fpublic
))
fpublic
? IPUBLIC_FILE_MODE
: IPRIVATE_FILE_MODE
);
ulog (LOG_ERROR
, "open (%s): %s", zto
, strerror (errno
));
while ((c
= read (ofrom
, ab
, sizeof ab
)) > 0)
if (write (oto
, ab
, (size_t) c
) != c
)
ulog (LOG_ERROR
, "write: %s", strerror (errno
));
ulog (LOG_ERROR
, "close: %s", strerror (errno
));
ulog (LOG_ERROR
, "read: %s", strerror (errno
));