MCPcopy Create free account
hub / github.com/coreutils/coreutils / install_file_in_dir

Function install_file_in_dir

src/install.c:799–836  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

797 Return true if successful. */
798
799static bool
800install_file_in_dir (char const *from, char const *to_dir,
801 const struct cp_options *x, bool mkdir_and_install,
802 int *target_dirfd)
803{
804 char const *from_base = last_component (from);
805 char *to_relname;
806 char *to = file_name_concat (to_dir, from_base, &to_relname);
807 bool ret = true;
808
809 if (!target_dirfd_valid (*target_dirfd)
810 && (ret = mkdir_and_install)
811 && (ret = mkancesdirs_safe_wd (from, to, (struct cp_options *) x, true)))
812 {
813 int fd = open (to_dir, O_PATHSEARCH | O_DIRECTORY);
814 if (fd < 0)
815 {
816 error (0, errno, _("cannot open %s"), quoteaf (to));
817 ret = false;
818 }
819 else
820 *target_dirfd = fd;
821 }
822
823 if (ret)
824 {
825 int to_dirfd = *target_dirfd;
826 if (!target_dirfd_valid (to_dirfd))
827 {
828 to_dirfd = AT_FDCWD;
829 to_relname = to;
830 }
831 ret = install_file_in_file (from, to, to_dirfd, to_relname, x);
832 }
833
834 free (to);
835 return ret;
836}
837
838int
839main (int argc, char **argv)

Callers 1

mainFunction · 0.85

Calls 3

target_dirfd_validFunction · 0.85
mkancesdirs_safe_wdFunction · 0.85
install_file_in_fileFunction · 0.85

Tested by

no test coverage detected