Print this page
10138 smatch fixes for usr/src/cmd/sgs


  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
  24  */
  25 
  26 /*
  27  *      Copyright (c) 1988 AT&T
  28  *        All Rights Reserved
  29  */
  30 
  31 /*




  32  * Utility functions
  33  */
  34 #include <unistd.h>
  35 #include <stdio.h>
  36 #include <stdarg.h>
  37 #include <string.h>
  38 #include <fcntl.h>
  39 #include <sys/types.h>
  40 #include <sys/mman.h>
  41 #include <errno.h>
  42 #include <sgs.h>
  43 #include <libintl.h>
  44 #include <debug.h>
  45 #include "msg.h"
  46 #include "_libld.h"
  47 
  48 /*
  49  * libld_malloc() and dz_map() are used for both performance and for ease of
  50  * programming:
  51  *


 302 
 303 /*
 304  * Determine whether this string, possibly with an associated option, should
 305  * be translated to an option character.  If so, update the optind and optarg
 306  * and optopt as described for short options in getopt(3c).
 307  *
 308  * entry:
 309  *      lml - Link map list for debug messages
 310  *      ndx - Starting optind for current item
 311  *      argc, argv - Command line arguments
 312  *      arg - Option to be examined
 313  *      c, opt - Option character (c) and corresponding long name (opt)
 314  *      optsz - 0 if option does not accept a value. If option does
 315  *              accept a value, strlen(opt), giving the offset to the
 316  *              value if the option and value are combined in one string.
 317  *      cbfunc - NULL, or pointer to function to call if a translation is
 318  *              successful.
 319  */
 320 static int
 321 str2chr(Lm_list *lml, int ndx, int argc, char **argv, char *arg, int c,
 322     const char *opt, size_t optsz, int cbfunc(int))
 323 {
 324         if (optsz == 0) {
 325                 /*
 326                  * Compare a single option (ie. there's no associated option
 327                  * argument).
 328                  */
 329                 if (strcmp(arg, opt) == 0) {
 330                         DBG_CALL(Dbg_args_str2chr(lml, ndx, opt, c));
 331                         optind += 1;
 332                         optopt = c;
 333                         return (c);
 334                 }
 335         } else if ((strcmp(arg, opt) == 0) ||
 336             ((arg[optsz] == '=') && strncmp(arg, opt, optsz) == 0)) {
 337                 /*
 338                  * Otherwise, compare the option name, which may be
 339                  * concatenated with the option argument.
 340                  */
 341                 DBG_CALL(Dbg_args_str2chr(lml, ndx, opt, c));
 342 




  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
  24  */
  25 
  26 /*
  27  *      Copyright (c) 1988 AT&T
  28  *        All Rights Reserved
  29  */
  30 
  31 /*
  32  * Copyright (c) 2018, Joyent, Inc.
  33  */
  34 
  35 /*
  36  * Utility functions
  37  */
  38 #include <unistd.h>
  39 #include <stdio.h>
  40 #include <stdarg.h>
  41 #include <string.h>
  42 #include <fcntl.h>
  43 #include <sys/types.h>
  44 #include <sys/mman.h>
  45 #include <errno.h>
  46 #include <sgs.h>
  47 #include <libintl.h>
  48 #include <debug.h>
  49 #include "msg.h"
  50 #include "_libld.h"
  51 
  52 /*
  53  * libld_malloc() and dz_map() are used for both performance and for ease of
  54  * programming:
  55  *


 306 
 307 /*
 308  * Determine whether this string, possibly with an associated option, should
 309  * be translated to an option character.  If so, update the optind and optarg
 310  * and optopt as described for short options in getopt(3c).
 311  *
 312  * entry:
 313  *      lml - Link map list for debug messages
 314  *      ndx - Starting optind for current item
 315  *      argc, argv - Command line arguments
 316  *      arg - Option to be examined
 317  *      c, opt - Option character (c) and corresponding long name (opt)
 318  *      optsz - 0 if option does not accept a value. If option does
 319  *              accept a value, strlen(opt), giving the offset to the
 320  *              value if the option and value are combined in one string.
 321  *      cbfunc - NULL, or pointer to function to call if a translation is
 322  *              successful.
 323  */
 324 static int
 325 str2chr(Lm_list *lml, int ndx, int argc, char **argv, char *arg, int c,
 326     const char *opt, size_t optsz, int (*cbfunc)(int))
 327 {
 328         if (optsz == 0) {
 329                 /*
 330                  * Compare a single option (ie. there's no associated option
 331                  * argument).
 332                  */
 333                 if (strcmp(arg, opt) == 0) {
 334                         DBG_CALL(Dbg_args_str2chr(lml, ndx, opt, c));
 335                         optind += 1;
 336                         optopt = c;
 337                         return (c);
 338                 }
 339         } else if ((strcmp(arg, opt) == 0) ||
 340             ((arg[optsz] == '=') && strncmp(arg, opt, optsz) == 0)) {
 341                 /*
 342                  * Otherwise, compare the option name, which may be
 343                  * concatenated with the option argument.
 344                  */
 345                 DBG_CALL(Dbg_args_str2chr(lml, ndx, opt, c));
 346