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

kmk_ln, kmk_mkdir, kmk_mv, kmk_printf: changed to use getopt_r and got rid of remaining static buffers.

File:
1 edited

Legend:

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

    r3192 r3215  
    5151*   Header Files                                                                                                                 *
    5252*********************************************************************************************************************************/
     53#define FAKES_NO_GETOPT_H /* bird */
    5354#include "config.h"
    5455#include <sys/types.h>
     
    8081#endif
    8182#include <unistd.h>
    82 #include "getopt.h"
     83#include "getopt_r.h"
    8384#ifdef __sun__
    8485# include "solfakes.h"
     
    121122
    122123static int      do_move(PMVINSTANCE, char *, char *);
    123 #ifdef CROSS_DEVICE_MOVE
     124#if 0 // def CROSS_DEVICE_MOVE
    124125static int      fastcopy(char *, char *, struct stat *);
    125126static int      copy(char *, char *);
     
    128129
    129130
    130 #if !defined(__FreeBSD__) && !defined(__APPLE__) && !defined(__DragonFly__) && !defined(__OpenBSD__)
    131 # ifdef __OS2__
    132 static
    133 # endif
    134 const char *user_from_uid(uid_t id, int x)
    135 {
    136         static char s_buf[64];
    137         sprintf(s_buf, "%ld", (long int)id);
    138         (void)x;
    139         return s_buf;
    140 }
    141 # ifdef __OS2__
    142 static
    143 # endif
    144 const char *group_from_gid(gid_t id, int x)
    145 {
    146         static char s_buf[64];
    147         sprintf(s_buf, "%ld", (long int)id);
    148         (void)x;
    149         return s_buf;
    150 }
    151 #endif /* 'not in libc' */
    152 
    153 
    154131int
    155132kmk_builtin_mv(int argc, char **argv, char **envp, PKMKBUILTINCTX pCtx)
    156133{
    157134        MVINSTANCE This;
     135        struct getopt_state_r gos;
    158136        size_t baselen, len;
    159137        int rval;
     
    170148        This.vflg = 0;
    171149
    172         /* kmk: reset getopt and set progname */
    173         opterr = 1;
    174         optarg = NULL;
    175         optopt = 0;
    176         optind = 0; /* init */
    177 
    178         while ((ch = getopt_long(argc, argv, "finv", long_options, NULL)) != -1)
     150        getopt_initialize_r(&gos, argc, argv, "finv", long_options, envp, pCtx);
     151        while ((ch = getopt_long_r(&gos, NULL)) != -1)
    179152                switch (ch) {
    180153                case 'i':
     
    201174                        return usage(pCtx, 1);
    202175                }
    203         argc -= optind;
    204         argv += optind;
     176        argc -= gos.optind;
     177        argv += gos.optind;
    205178
    206179        if (argc < 2)
     
    301274                } else if (access(to, W_OK) && !stat(to, &sb)) {
    302275                        bsd_strmode(sb.st_mode, modep);
     276#if 0 /* probably not thread safe, also BSDism. */
    303277                        (void)fprintf(stderr, "override %s%s%s/%s for %s? %s",
    304278                            modep + 1, modep[9] == ' ' ? "" : " ",
    305279                            user_from_uid((unsigned long)sb.st_uid, 0),
    306280                            group_from_gid((unsigned long)sb.st_gid, 0), to, YESNO);
     281#else
     282                        (void)fprintf(stderr, "override %s%s%ul/%ul for %s? %s",
     283                                      modep + 1, modep[9] == ' ' ? "" : " ",
     284                                      (unsigned long)sb.st_uid, (unsigned long)sb.st_gid,
     285                                      to, YESNO);
     286#endif
    307287                        ask = 1;
    308288                }
     
    335315
    336316        if (errno == EXDEV) {
    337 #ifndef CROSS_DEVICE_MOVE
     317#if 1 //ndef CROSS_DEVICE_MOVE
    338318                warnx(pThis->pCtx, "cannot move `%s' to a different device: `%s'", from, to);
    339319                return (1);
     
    368348        }
    369349
    370 #ifdef CROSS_DEVICE_MOVE
     350#if 0//def CROSS_DEVICE_MOVE
    371351        /*
    372352         * If rename fails because we're trying to cross devices, and
     
    383363}
    384364
    385 #ifdef CROSS_DEVICE_MOVE
     365#if 0 //def CROSS_DEVICE_MOVE - using static buffers and fork.
    386366int
    387367static fastcopy(char *from, char *to, struct stat *sbp)
Note: See TracChangeset for help on using the changeset viewer.