Ignore:
Timestamp:
Mar 26, 2018, 10:25:56 PM (7 years ago)
Author:
bird
Message:

kmkbuiltin: funnel output thru output.c (usually via err.c).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/kmkbuiltin/cp_utils.c

    r3148 r3192  
    8787
    8888int
    89 copy_file(const FTSENT *entp, int dne, int changed_only, int *pcopied)
     89copy_file(PKMKBUILTINCTX pCtx, const FTSENT *entp, int dne, int changed_only, int *pcopied)
    9090{
    9191        static char buf[MAXBSIZE];
     
    103103
    104104        if ((from_fd = open(entp->fts_path, O_RDONLY | O_BINARY, 0)) == -1) {
    105                 warn("open: %s", entp->fts_path);
     105                warn(pCtx, "open: %s", entp->fts_path);
    106106                return (1);
    107107        }
     
    120120                /* compare the files first if requested */
    121121                if (changed_only) {
    122                         if (cmp_fd_and_file(from_fd, entp->fts_path, to.p_path,
     122                        if (cmp_fd_and_file(pCtx, from_fd, entp->fts_path, to.p_path,
    123123                                            1 /* silent */, 0 /* lflag */,
    124124                                            0 /* special */) == OK_EXIT) {
     
    129129                                close(from_fd);
    130130                                if ((from_fd = open(entp->fts_path, O_RDONLY | O_BINARY, 0)) == -1) {
    131                                         warn("open: %s", entp->fts_path);
     131                                        warn(pCtx, "open: %s", entp->fts_path);
    132132                                        return (1);
    133133                                }
     
    138138                if (nflag) {
    139139                        if (vflag)
    140                                 printf("%s not overwritten\n", to.p_path);
     140                                kmk_builtin_ctx_printf(pCtx, 0, "%s not overwritten\n", to.p_path);
    141141                        return (0);
    142142                } else if (iflag) {
     
    148148                        if (checkch != 'y' && checkch != 'Y') {
    149149                                (void)close(from_fd);
    150                                 (void)fprintf(stderr, "not overwritten\n");
     150                                kmk_builtin_ctx_printf(pCtx, 1, "not overwritten\n");
    151151                                return (1);
    152152                        }
     
    167167
    168168        if (to_fd == -1) {
    169                 warn("open: %s", to.p_path);
     169                warn(pCtx, "open: %s", to.p_path);
    170170                (void)close(from_fd);
    171171                return (1);
     
    185185                if ((p = mmap(NULL, (size_t)fs->st_size, PROT_READ,
    186186                    MAP_SHARED, from_fd, (off_t)0)) == MAP_FAILED) {
    187                         warn("mmap: %s", entp->fts_path);
     187                        warn(pCtx, "mmap: %s", entp->fts_path);
    188188                        rval = 1;
    189189                } else {
     
    195195                                if (info) {
    196196                                        info = 0;
    197                                         (void)fprintf(stderr,
     197                                        kmk_builtin_ctx_printf(pCtx, 1,
    198198                                                "%s -> %s %3d%%\n",
    199199                                                entp->fts_path, to.p_path,
     
    205205                        }
    206206                        if (wcount != (ssize_t)wresid) {
    207                                 warn("write[%zd != %zu]: %s", wcount, wresid, to.p_path);
     207                                warn(pCtx, "write[%zd != %zu]: %s", wcount, wresid, to.p_path);
    208208                                rval = 1;
    209209                        }
    210210                        /* Some systems don't unmap on close(2). */
    211211                        if (munmap(p, fs->st_size) < 0) {
    212                                 warn("munmap: %s", entp->fts_path);
     212                                warn(pCtx, "munmap: %s", entp->fts_path);
    213213                                rval = 1;
    214214                        }
     
    225225                                if (info) {
    226226                                        info = 0;
    227                                         (void)fprintf(stderr,
     227                                        kmk_builtin_ctx_printf(pCtx, 1,
    228228                                                "%s -> %s %3d%%\n",
    229229                                                entp->fts_path, to.p_path,
     
    235235                        }
    236236                        if (wcount != (ssize_t)wresid) {
    237                                 warn("write[%zd != %zu]: %s", wcount, wresid, to.p_path);
     237                                warn(pCtx, "write[%zd != %zu]: %s", wcount, wresid, to.p_path);
    238238                                rval = 1;
    239239                                break;
     
    241241                }
    242242                if (rcount < 0) {
    243                         warn("read: %s", entp->fts_path);
     243                        warn(pCtx, "read: %s", entp->fts_path);
    244244                        rval = 1;
    245245                }
     
    253253         */
    254254
    255         if (pflag && setfile(fs, to_fd))
     255        if (pflag && setfile(pCtx, fs, to_fd))
    256256                rval = 1;
    257257        (void)close(from_fd);
    258258        if (close(to_fd)) {
    259                 warn("close: %s", to.p_path);
     259                warn(pCtx, "close: %s", to.p_path);
    260260                rval = 1;
    261261        }
     
    264264
    265265int
    266 copy_link(const FTSENT *p, int exists)
     266copy_link(PKMKBUILTINCTX pCtx, const FTSENT *p, int exists)
    267267{
    268268        int len;
     
    270270
    271271        if ((len = readlink(p->fts_path, llink, sizeof(llink) - 1)) == -1) {
    272                 warn("readlink: %s", p->fts_path);
     272                warn(pCtx, "readlink: %s", p->fts_path);
    273273                return (1);
    274274        }
    275275        llink[len] = '\0';
    276276        if (exists && unlink(to.p_path)) {
    277                 warn("unlink: %s", to.p_path);
     277                warn(pCtx, "unlink: %s", to.p_path);
    278278                return (1);
    279279        }
    280280        if (symlink(llink, to.p_path)) {
    281                 warn("symlink: %s", llink);
    282                 return (1);
    283         }
    284         return (pflag ? setfile(p->fts_statp, -1) : 0);
    285 }
    286 
    287 int
    288 copy_fifo(struct stat *from_stat, int exists)
     281                warn(pCtx, "symlink: %s", llink);
     282                return (1);
     283        }
     284        return (pflag ? setfile(pCtx, p->fts_statp, -1) : 0);
     285}
     286
     287int
     288copy_fifo(PKMKBUILTINCTX pCtx, struct stat *from_stat, int exists)
    289289{
    290290        if (exists && unlink(to.p_path)) {
    291                 warn("unlink: %s", to.p_path);
     291                warn(pCtx, "unlink: %s", to.p_path);
    292292                return (1);
    293293        }
    294294        if (mkfifo(to.p_path, from_stat->st_mode)) {
    295                 warn("mkfifo: %s", to.p_path);
    296                 return (1);
    297         }
    298         return (pflag ? setfile(from_stat, -1) : 0);
    299 }
    300 
    301 int
    302 copy_special(struct stat *from_stat, int exists)
     295                warn(pCtx, "mkfifo: %s", to.p_path);
     296                return (1);
     297        }
     298        return (pflag ? setfile(pCtx, from_stat, -1) : 0);
     299}
     300
     301int
     302copy_special(PKMKBUILTINCTX pCtx, struct stat *from_stat, int exists)
    303303{
    304304        if (exists && unlink(to.p_path)) {
    305                 warn("unlink: %s", to.p_path);
     305                warn(pCtx, "unlink: %s", to.p_path);
    306306                return (1);
    307307        }
    308308        if (mknod(to.p_path, from_stat->st_mode, from_stat->st_rdev)) {
    309                 warn("mknod: %s", to.p_path);
    310                 return (1);
    311         }
    312         return (pflag ? setfile(from_stat, -1) : 0);
    313 }
    314 
    315 int
    316 setfile(struct stat *fs, int fd)
     309                warn(pCtx, "mknod: %s", to.p_path);
     310                return (1);
     311        }
     312        return (pflag ? setfile(pCtx, from_stat, -1) : 0);
     313}
     314
     315int
     316setfile(PKMKBUILTINCTX pCtx, struct stat *fs, int fd)
    317317{
    318318        static struct timeval tv[2];
     
    335335#endif
    336336        if (islink ? lutimes(to.p_path, tv) : utimes(to.p_path, tv)) {
    337                 warn("%sutimes: %s", islink ? "l" : "", to.p_path);
     337                warn(pCtx, "%sutimes: %s", islink ? "l" : "", to.p_path);
    338338                rval = 1;
    339339        }
     
    357357                    chown(to.p_path, fs->st_uid, fs->st_gid))) {
    358358                        if (errno != EPERM) {
    359                                 warn("chown: %s", to.p_path);
     359                                warn(pCtx, "chown: %s", to.p_path);
    360360                                rval = 1;
    361361                        }
     
    367367                    (islink ? lchmod(to.p_path, fs->st_mode) :
    368368                    chmod(to.p_path, fs->st_mode))) {
    369                         warn("chmod: %s", to.p_path);
     369                        warn(pCtx, "chmod: %s", to.p_path);
    370370                        rval = 1;
    371371                }
     
    377377                    (islink ? (errno = ENOSYS) :
    378378                    chflags(to.p_path, fs->st_flags))) {
    379                         warn("chflags: %s", to.p_path);
     379                        warn(pCtx, "chflags: %s", to.p_path);
    380380                        rval = 1;
    381381                }
Note: See TracChangeset for help on using the changeset viewer.