// ========== Copyright Header Begin ==========================================
// OpenSPARC T2 Processor File: arg.cc
// Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
// DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
// The above named program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public
// License version 2 as published by the Free Software Foundation.
// The above named program is distributed in the hope that it will be
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
// You should have received a copy of the GNU General Public
// License along with this work; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
// ========== Copyright Header End ============================================
// Utility for parsing sysconf args
// Copyright 2004 Sun Microsystems Inc
//@(#)arg.cc 1.3 06/04/18
// return str from name=value
argval(const char *name
, const char *arg
, const char **value
)
char *peq
= strchr(tmp
, '=');
ans
= !strcmp(name
, tmp
);
*value
= strdup(peq
+ 1);
ans
= !strcmp(name
, tmp
);
// return bool from name=value
argval(const char *name
, const char *arg
, bool *value
)
if (argval(name
, arg
, &str
)) {
*value
= true; // missing '=value', treat as a switch
else if (strchr("tTyY1", str
[0])) // true or yes or 1
else if (!strchr("oO", str
[0])) // on vs off
else if (strchr("nN", str
[1]))
// return unsigned long long from name=value
argval(const char *name
, const char *arg
, unsigned long long *value
)
if (argval(name
, arg
, &str
)) {
// return int from name=value
argval(const char *name
, const char *arg
, int *value
)
if (argval(name
, arg
, &ull
)) {
// return ul from name=value
argval(const char *name
, const char *arg
, unsigned long *value
)
if (argval(name
, arg
, &ull
)) {
*value
= (unsigned long) ull
;
// convert decimal, octal or hex
return (int) strtol(s
, NULL
, 0);
return (unsigned long long) strtoll(s
, NULL
, 0);
// format a string and return a copy
const char *makestr(const char *format
, ...)
vsnprintf(buf
, sizeof buf
, format
, ap
);