Changeset 3216 for trunk/src/kmk


Ignore:
Timestamp:
Mar 31, 2018, 12:09:15 AM (7 years ago)
Author:
bird
Message:

kmk_rm, kmk_rmdir: changed to use getopt_r.

Location:
trunk/src/kmk/kmkbuiltin
Files:
2 edited

Legend:

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

    r3192 r3216  
    4646*   Header Files                                                                                                                 *
    4747*********************************************************************************************************************************/
     48#define FAKES_NO_GETOPT_H /* bird */
    4849#include "config.h"
    4950#include <sys/stat.h>
     
    6970#include <unistd.h>
    7071#include <ctype.h>
    71 #include "getopt.h"
     72#include "getopt_r.h"
    7273#ifdef __HAIKU__
    7374# include "haikufakes.h"
     
    187188{
    188189        RMINSTANCE This;
     190        struct getopt_state_r gos;
    189191        int ch, rflag;
    190192
     
    205207        kBuildProtectionInit(&This.g_ProtData, pCtx);
    206208
    207         /* kmk: reset getopt and set program name. */
    208         opterr = 1;
    209         optarg = NULL;
    210         optopt = 0;
    211         optind = 0; /* init */
    212 
    213209        rflag = 0;
    214         while ((ch = getopt_long(argc, argv, "dfiPRvW", long_options, NULL)) != -1)
     210        getopt_initialize_r(&gos, argc, argv, "dfiPRvW", long_options, envp, pCtx);
     211        while ((ch = getopt_long_r(&gos, NULL)) != -1)
    215212                switch (ch) {
    216213                case 'd':
     
    262259                        break;
    263260                case 267:
    264                         if (kBuildProtectionSetDepth(&This.g_ProtData, optarg)) {
     261                        if (kBuildProtectionSetDepth(&This.g_ProtData, gos.optarg)) {
    265262                            kBuildProtectionTerm(&This.g_ProtData);
    266263                            return 1;
     
    277274                        return usage(pCtx, 1);
    278275                }
    279         argc -= optind;
    280         argv += optind;
     276        argc -= gos.optind;
     277        argv += gos.optind;
    281278
    282279        if (argc < 1) {
     
    347344
    348345        flags = FTS_PHYSICAL;
     346#ifndef KMK_BUILTIN_STANDALONE
     347        flags |= FTS_NOCHDIR; /* Must not change the directory from inside kmk! */
     348#endif
    349349        if (!needstat)
    350350                flags |= FTS_NOSTAT;
  • trunk/src/kmk/kmkbuiltin/rmdir.c

    r3192 r3216  
    4848*   Header Files                                                                                                                 *
    4949*********************************************************************************************************************************/
     50#define FAKES_NO_GETOPT_H /* bird */
    5051#include "config.h"
    5152#include "err.h"
     
    5859# include <alloca.h>
    5960#endif
    60 #include "getopt.h"
     61#include "getopt_r.h"
    6162#include "kmkbuiltin.h"
    6263
     
    110111{
    111112        RMDIRINSTANCE This;
     113        struct getopt_state_r gos;
    112114        int ch, errors;
    113115
     
    119121        This.pflag = 0;
    120122
    121         /* kmk: reset getopt and set progname */
    122         opterr = 1;
    123         optarg = NULL;
    124         optopt = 0;
    125         optind = 0; /* init */
    126         while ((ch = getopt_long(argc, argv, "pv", long_options, NULL)) != -1)
     123        getopt_initialize_r(&gos, argc, argv, "pv", long_options, envp, pCtx);
     124        while ((ch = getopt_long_r(&gos, NULL)) != -1)
    127125                switch(ch) {
    128126                case 'p':
     
    147145                        return usage(pCtx, 1);
    148146                }
    149         argc -= optind;
    150         argv += optind;
     147        argc -= gos.optind;
     148        argv += gos.optind;
    151149
    152150        if (argc == 0)
Note: See TracChangeset for help on using the changeset viewer.