Ignore:
Timestamp:
Dec 18, 2005, 4:48:02 AM (20 years ago)
Author:
bird
Message:

o Ported all kmk builtins to win32.
o Fixed serveral bugs in kmk builtins.
o Probably broke both linux, bsd and OS/2. :-)

File:
1 edited

Legend:

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

    r347 r370  
    3131#if 0
    3232static char sccsid[] = "@(#)utils.c     8.3 (Berkeley) 4/1/94";
     33#include <sys/cdefs.h>
     34__FBSDID("$FreeBSD: src/bin/cp/utils.c,v 1.43 2004/04/06 20:06:44 markm Exp $");
    3335#endif
    3436#endif /* not lint */
    35 #include <sys/cdefs.h>
    36 //__FBSDID("$FreeBSD: src/bin/cp/utils.c,v 1.43 2004/04/06 20:06:44 markm Exp $");
    37 
     37
     38#ifndef _MSC_VER
    3839#include <sys/param.h>
     40#endif
    3941#include <sys/stat.h>
    4042#ifdef VM_AND_BUFFER_CACHE_SYNCHRONIZED
     
    4244#endif
    4345
    44 #include <err.h>
     46#include "err.h"
    4547#include <errno.h>
    4648#include <fcntl.h>
     49#ifndef _MSC_VER
    4750#include <fts.h>
     51#endif
    4852#include <limits.h>
    4953#include <stdio.h>
    5054#include <stdlib.h>
     55#include <signal.h>
     56#ifndef _MSC_VER
    5157#include <sysexits.h>
    5258#include <unistd.h>
    53 #include <signal.h>
     59#else
     60#include "mscfakes.h"
     61#include "ftsfake.h"
     62#endif
    5463
    5564#include "cp_extern.h"
     
    5766
    5867#ifndef MAXBSIZE
    59 #define MAXBSIZE (128*1024)
     68# define MAXBSIZE 16384
    6069#endif
    6170#ifndef O_BINARY
    6271# define O_BINARY 0
    6372#endif
     73
     74#ifndef S_ISVTX
     75# define S_ISVTX 0
     76#endif
    6477
    6578int
     
    7891
    7992        if ((from_fd = open(entp->fts_path, O_RDONLY | O_BINARY, 0)) == -1) {
    80                 fprintf(stderr, "%s: %s: %s\n", argv0, entp->fts_path, strerror(errno));
     93                warn("%s", entp->fts_path);
    8194                return (1);
    8295        }
     
    125138
    126139        if (to_fd == -1) {
    127                 fprintf(stderr, "%s: %s: %s\n", argv0, to.p_path, strerror(errno));
     140                warn("%s", to.p_path);
    128141                (void)close(from_fd);
    129142                return (1);
     
    142155                if ((p = mmap(NULL, (size_t)fs->st_size, PROT_READ,
    143156                    MAP_SHARED, from_fd, (off_t)0)) == MAP_FAILED) {
    144                         fprintf(stderr, "%s: %s: %s\n", argv0, entp->fts_path, strerror(errno));
     157                        warn("%s", entp->fts_path);
    145158                        rval = 1;
    146159                } else {
     
    162175                        }
    163176                        if (wcount != (ssize_t)wresid) {
    164                                 fprintf(stderr, "%s: %s: %s\n", argv0, to.p_path, strerror(errno));
     177                                warn("%s", to.p_path);
    165178                                rval = 1;
    166179                        }
    167180                        /* Some systems don't unmap on close(2). */
    168181                        if (munmap(p, fs->st_size) < 0) {
    169                                 fprintf(stderr, "%s: %s: %s\n", entp->fts_path, strerror(errno));
     182                                warn("%s", entp->fts_path);
    170183                                rval = 1;
    171184                        }
     
    192205                        }
    193206                        if (wcount != (ssize_t)wresid) {
    194                                 fprintf(stderr, "%s: %s: %s\n", argv0, to.p_path, strerror(errno));
     207                                warn("%s", to.p_path);
    195208                                rval = 1;
    196209                                break;
     
    198211                }
    199212                if (rcount < 0) {
    200                         fprintf(stderr, "%s: %s: %s\n", argv0, entp->fts_path, strerror(errno));
     213                        warn("%s", entp->fts_path);
    201214                        rval = 1;
    202215                }
     
    214227        (void)close(from_fd);
    215228        if (close(to_fd)) {
    216                 fprintf(stderr, "%s: %s: %s\n", argv0, to.p_path, strerror(errno));
     229                warn("%s", to.p_path);
    217230                rval = 1;
    218231        }
     
    227240
    228241        if ((len = readlink(p->fts_path, llink, sizeof(llink) - 1)) == -1) {
    229                 fprintf(stderr, "%s: readlink: %s: %s\n", argv0, p->fts_path, strerror(errno));
     242                warn("readlink: %s", p->fts_path);
    230243                return (1);
    231244        }
    232245        llink[len] = '\0';
    233246        if (exists && unlink(to.p_path)) {
    234                 fprintf(stderr, "%s: unlink: %s: %s\n", argv0, to.p_path, strerror(errno));
     247                warn("unlink: %s", to.p_path);
    235248                return (1);
    236249        }
    237250        if (symlink(llink, to.p_path)) {
    238                 fprintf(stderr, "%s: symlink: %s: %s\n", argv0, llink, strerror(errno));
     251                warn("symlink: %s", llink);
    239252                return (1);
    240253        }
     
    246259{
    247260        if (exists && unlink(to.p_path)) {
    248                 fprintf(stderr, "%s: unlink: %s: %s\n", argv0, to.p_path, strerror(errno));
     261                warn("unlink: %s", to.p_path);
    249262                return (1);
    250263        }
    251264        if (mkfifo(to.p_path, from_stat->st_mode)) {
    252                 fprintf(stderr, "%s: mkfifo: %s\n", argv0, to.p_path, strerror(errno));
     265                warn("mkfifo: %s", to.p_path);
    253266                return (1);
    254267        }
     
    260273{
    261274        if (exists && unlink(to.p_path)) {
    262                 fprintf(stderr, "%s: unlink: %s: %s\n", argv0, to.p_path, strerror(errno));
     275                warn("unlink: %s", to.p_path);
    263276                return (1);
    264277        }
    265278        if (mknod(to.p_path, from_stat->st_mode, from_stat->st_rdev)) {
    266                 fprintf(stderr, "%s: mknod: %s: %s\n", argv0, to.p_path, strerror(errno));
     279                warn("mknod: %s", to.p_path);
    267280                return (1);
    268281        }
     
    292305#endif
    293306        if (islink ? lutimes(to.p_path, tv) : utimes(to.p_path, tv)) {
    294                 fprintf(stderr, "%s: %sutimes: %s: %s\n", argv0, islink ? "l" : "", to.p_path, strerror(errno));
     307                warn("%sutimes: %s", islink ? "l" : "", to.p_path);
    295308                rval = 1;
    296309        }
     
    314327                    chown(to.p_path, fs->st_uid, fs->st_gid))) {
    315328                        if (errno != EPERM) {
    316                                 fprintf(stderr, "%s: chown: %s: %s\n", argv0, to.p_path, strerror(errno));
     329                                warn("chown: %s", to.p_path);
    317330                                rval = 1;
    318331                        }
     
    324337                    (islink ? lchmod(to.p_path, fs->st_mode) :
    325338                    chmod(to.p_path, fs->st_mode))) {
    326                         fprintf(stderr, "%s: chmod: %s: %s\n", to.p_path, strerror(errno));
     339                        warn("chmod: %s", to.p_path);
    327340                        rval = 1;
    328341                }
     
    334347                    (islink ? (errno = ENOSYS) :
    335348                    chflags(to.p_path, fs->st_flags))) {
    336                         fprintf(stderr, "%s: chflags: %s: %s", argv0, to.p_path, strerror(errno));
     349                        warn("chflags: %s", to.p_path);
    337350                        rval = 1;
    338351                }
     
    342355}
    343356
    344 void
     357int
    345358usage(void)
    346359{
     
    349362"usage: cp [-R [-H | -L | -P]] [-f | -i | -n] [-pv] src target",
    350363"       cp [-R [-H | -L | -P]] [-f | -i | -n] [-pv] src1 ... srcN directory");
    351         exit(EX_USAGE);
    352 }
     364        return EX_USAGE;
     365}
Note: See TracChangeset for help on using the changeset viewer.