overhaul parse_args - don't use strlcpy and strlen when overkill
also fixes off-by-one saves 48 .text
This commit is contained in:
20
misc.c
20
misc.c
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#include "sh.h"
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.25 2006/11/10 01:44:39 tg Exp $\t"
|
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.26 2006/11/10 01:52:23 tg Exp $\t"
|
||||||
MKSH_SH_H_ID);
|
MKSH_SH_H_ID);
|
||||||
|
|
||||||
unsigned char chtypes[UCHAR_MAX + 1]; /* type bits for unsigned char */
|
unsigned char chtypes[UCHAR_MAX + 1]; /* type bits for unsigned char */
|
||||||
@ -257,7 +257,7 @@ parse_args(char **argv,
|
|||||||
int *setargsp)
|
int *setargsp)
|
||||||
{
|
{
|
||||||
static char cmd_opts[NELEM(options) + 5]; /* o:T:\0 */
|
static char cmd_opts[NELEM(options) + 5]; /* o:T:\0 */
|
||||||
static char set_opts[NELEM(options) + 5]; /* Ao;s\0 */
|
static char set_opts[NELEM(options) + 6]; /* A:o;s\0 */
|
||||||
char *opts;
|
char *opts;
|
||||||
char *array = NULL;
|
char *array = NULL;
|
||||||
Getopt go;
|
Getopt go;
|
||||||
@ -266,14 +266,20 @@ parse_args(char **argv,
|
|||||||
|
|
||||||
/* First call? Build option strings... */
|
/* First call? Build option strings... */
|
||||||
if (cmd_opts[0] == '\0') {
|
if (cmd_opts[0] == '\0') {
|
||||||
char *p, *q;
|
char *p = cmd_opts, *q = set_opts;
|
||||||
|
|
||||||
/* see cmd_opts[] declaration */
|
/* see cmd_opts[] declaration */
|
||||||
strlcpy(cmd_opts, "o:T:", sizeof cmd_opts);
|
*p++ = 'o';
|
||||||
p = cmd_opts + strlen(cmd_opts);
|
*p++ = ':';
|
||||||
|
*p++ = 'T';
|
||||||
|
*p++ = ':';
|
||||||
/* see set_opts[] declaration */
|
/* see set_opts[] declaration */
|
||||||
strlcpy(set_opts, "A:o;s", sizeof set_opts);
|
*q++ = 'A';
|
||||||
q = set_opts + strlen(set_opts);
|
*q++ = ':';
|
||||||
|
*q++ = 'o';
|
||||||
|
*q++ = ';';
|
||||||
|
*q++ = 's';
|
||||||
|
|
||||||
for (i = 0; i < NELEM(options); i++) {
|
for (i = 0; i < NELEM(options); i++) {
|
||||||
if (options[i].c) {
|
if (options[i].c) {
|
||||||
if (options[i].flags & OF_CMDLINE)
|
if (options[i].flags & OF_CMDLINE)
|
||||||
|
Reference in New Issue
Block a user