VirtualBox

Changeset 3192 in kBuild for trunk/src/kmk/kmkbuiltin/chmod.c


Ignore:
Timestamp:
Mar 26, 2018 8: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/chmod.c

    r3148 r3192  
    7575#endif
    7676
    77 static int usage(FILE *);
     77static int usage(PKMKBUILTINCTX pCtx, int is_err);
    7878
    7979static struct option long_options[] =
     
    8686
    8787int
    88 kmk_builtin_chmod(int argc, char *argv[], char **envp)
     88kmk_builtin_chmod(int argc, char *argv[], char **envp, PKMKBUILTINCTX pCtx)
    8989{
    9090        FTS *ftsp;
     
    9898
    9999        /* kmk: reset getopt and set progname */
    100         g_progname = argv[0];
    101100        opterr = 1;
    102101        optarg = NULL;
     
    153152                        break;
    154153                case 261:
    155                         usage(stdout);
     154                        usage(pCtx, 0);
    156155                        return 0;
    157156                case 262:
     
    159158                case '?':
    160159                default:
    161                         return usage(stderr);
     160                        return usage(pCtx, 1);
    162161                }
    163162done:   argv += optind;
     
    165164
    166165        if (argc < 2)
    167                 return usage(stderr);
     166                return usage(pCtx, 1);
    168167
    169168        if (Rflag) {
    170169                fts_options = FTS_PHYSICAL;
    171170                if (hflag)
    172                         return errx(1,
     171                        return errx(pCtx, 1,
    173172                "the -R and -h options may not be specified together.");
    174173                if (Hflag)
     
    188187        mode = *argv;
    189188        if ((set = bsd_setmode(mode)) == NULL)
    190                 return errx(1, "invalid file mode: %s", mode);
     189                return errx(pCtx, 1, "invalid file mode: %s", mode);
    191190
    192191        if ((ftsp = fts_open(++argv, fts_options, 0)) == NULL)
    193                 return err(1, "fts_open");
     192                return err(pCtx, 1, "fts_open");
    194193        for (rval = 0; (p = fts_read(ftsp)) != NULL;) {
    195194                switch (p->fts_info) {
     
    199198                        continue;
    200199                case FTS_DNR:                   /* Warn, chmod, continue. */
    201                         warnx("fts: %s: %s", p->fts_path, strerror(p->fts_errno));
     200                        warnx(pCtx, "fts: %s: %s", p->fts_path, strerror(p->fts_errno));
    202201                        rval = 1;
    203202                        break;
    204203                case FTS_ERR:                   /* Warn, continue. */
    205204                case FTS_NS:
    206                         warnx("fts: %s: %s", p->fts_path, strerror(p->fts_errno));
     205                        warnx(pCtx, "fts: %s: %s", p->fts_path, strerror(p->fts_errno));
    207206                        rval = 1;
    208207                        continue;
     
    225224                        continue;
    226225                if ((*change_mode)(p->fts_accpath, newmode) && !fflag) {
    227                         warn("%schmod: %s", hflag ? "l" : "", p->fts_path);
     226                        warn(pCtx, "%schmod: %s", hflag ? "l" : "", p->fts_path);
    228227                        rval = 1;
    229228                } else {
    230229                        if (vflag) {
    231                                 (void)printf("%s", p->fts_path);
     230                                kmk_builtin_ctx_printf(pCtx, 0, "%s", p->fts_path);
    232231
    233232                                if (vflag > 1) {
     
    238237                                            S_IFMT) | newmode, m2);
    239238
    240                                         (void)printf(": 0%o [%s] -> 0%o [%s]",
     239                                        kmk_builtin_ctx_printf(pCtx, 0, ": 0%o [%s] -> 0%o [%s]",
    241240                                            (unsigned int)p->fts_statp->st_mode, m1,
    242241                                            (unsigned int)((p->fts_statp->st_mode & S_IFMT) | newmode), m2);
    243242                                }
    244                                 (void)printf("\n");
     243                                kmk_builtin_ctx_printf(pCtx, 0, "\n");
    245244                        }
    246245
     
    248247        }
    249248        if (errno)
    250                 rval = err(1, "fts_read");
     249                rval = err(pCtx, 1, "fts_read");
    251250        free(set);
    252251        fts_close(ftsp);
     
    255254
    256255int
    257 usage(FILE *out)
    258 {
    259         (void)fprintf(out,
     256usage(PKMKBUILTINCTX pCtx, int is_err)
     257{
     258        kmk_builtin_ctx_printf(pCtx, is_err,
    260259            "usage: %s [-fhv] [-R [-H | -L | -P]] mode file ...\n"
    261260            "   or: %s --version\n"
    262261            "   or: %s --help\n",
    263             g_progname, g_progname, g_progname);
     262            pCtx->pszProgName, pCtx->pszProgName, pCtx->pszProgName);
    264263
    265264        return 1;
    266265}
     266
     267#ifdef KMK_BUILTIN_STANDALONE
     268int main(int argc, char **argv, char **envp)
     269{
     270    KMKBUILTINCTX Ctx = { "kmk_chmod", NULL };
     271    return kmk_builtin_chmod(argc, argv, envp, &Ctx);
     272}
     273#endif
     274
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette