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/ln.c

    r368 r370  
    3838static char sccsid[] = "@(#)ln.c        8.2 (Berkeley) 3/31/94";
    3939#endif /* not lint */
    40 #endif
    4140#include <sys/cdefs.h>
    4241__FBSDID("$FreeBSD: src/bin/ln/ln.c,v 1.33 2005/02/09 17:37:37 ru Exp $");
    43 
     42#endif /* no $id */
     43
     44#ifndef _MSC_VER
    4445#include <sys/param.h>
     46#endif
    4547#include <sys/stat.h>
    4648
    47 #include <err.h>
     49#include "err.h"
    4850#include <errno.h>
    4951#include <limits.h>
     
    5153#include <stdlib.h>
    5254#include <string.h>
     55#ifndef _MSC_VER
    5356#include <unistd.h>
     57#else
     58#include "mscfakes.h"
     59#endif
    5460
    5561static int      fflag;                          /* Unlink existing files. */
     
    6369
    6470static int      linkit(const char *, const char *, int);
    65 static void     usage(void);
     71static int      usage(void);
     72
    6673
    6774int
     
    7279        int ch, exitval;
    7380
     81        /* kmk: reset getopt() and set program name. */
     82        g_progname = argv[0];
     83        opterr = 1;
     84        optarg = NULL;
     85        optopt = 0;
     86#if defined(__FreeBSD__) || defined(__EMX__)
     87        optreset = 1;
     88        optind = 1;
     89#else
     90        optind = 0; /* init */
     91#endif
     92
     93#if 0 /* kmk: we don't need this. */
    7494        /*
    7595         * Test for the special case where the utility is called as
     
    83103        if (strcmp(p, "link") == 0) {
    84104                while (getopt(argc, argv, "") != -1)
    85                         usage();
     105                        return usage();
    86106                argc -= optind;
    87107                argv += optind;
    88108                if (argc != 2)
    89                         usage();
     109                        return usage();
    90110                linkf = link;
    91                 exit(linkit(argv[0], argv[1], 0));
    92         }
     111                return linkit(argv[0], argv[1], 0);
     112        }
     113#else
     114        (void)p;
     115#endif
     116       
    93117
    94118        while ((ch = getopt(argc, argv, "fhinsv")) != -1)
     
    114138                case '?':
    115139                default:
    116                         usage();
     140                        return usage();
    117141                }
    118142
     
    125149        switch(argc) {
    126150        case 0:
    127                 usage();
     151                return usage();
    128152                /* NOTREACHED */
    129153        case 1:                         /* ln target */
    130                 exit(linkit(argv[0], ".", 1));
     154                return linkit(argv[0], ".", 1);
    131155        case 2:                         /* ln target source */
    132                 exit(linkit(argv[0], argv[1], 0));
     156                return linkit(argv[0], argv[1], 0);
    133157        default:
    134158                ;
     
    142166                 */
    143167                errno = ENOTDIR;
    144                 err(1, "%s", sourcedir);
     168                return err(1, "%s", sourcedir);
    145169        }
    146170        if (stat(sourcedir, &sb))
    147                 err(1, "%s", sourcedir);
     171                return err(1, "%s", sourcedir);
    148172        if (!S_ISDIR(sb.st_mode))
    149                 usage();
     173                return usage();
    150174        for (exitval = 0; *argv != sourcedir; ++argv)
    151175                exitval |= linkit(*argv, sourcedir, 1);
    152         exit(exitval);
     176        return exitval;
    153177}
    154178
    155 int
     179static int
    156180linkit(const char *target, const char *source, int isdir)
    157181{
     
    233257}
    234258
    235 void
     259static int
    236260usage(void)
    237261{
     
    240264            "       ln [-fhinsv] source_file ... target_dir",
    241265            "       link source_file target_file");
    242         exit(1);
     266        return 1;
    243267}
Note: See TracChangeset for help on using the changeset viewer.