本文整理汇总了C++中safe_atou函数的典型用法代码示例。如果您正苦于以下问题:C++ safe_atou函数的具体用法?C++ safe_atou怎么用?C++ safe_atou使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了safe_atou函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: routes_max
static unsigned routes_max(void) {
static thread_local unsigned cached = 0;
_cleanup_free_ char *s4 = NULL, *s6 = NULL;
unsigned val4 = ROUTES_DEFAULT_MAX_PER_FAMILY, val6 = ROUTES_DEFAULT_MAX_PER_FAMILY;
if (cached > 0)
return cached;
if (sysctl_read("net/ipv4/route/max_size", &s4) >= 0) {
truncate_nl(s4);
if (safe_atou(s4, &val4) >= 0 &&
val4 == 2147483647U)
/* This is the default "no limit" value in the kernel */
val4 = ROUTES_DEFAULT_MAX_PER_FAMILY;
}
if (sysctl_read("net/ipv6/route/max_size", &s6) >= 0) {
truncate_nl(s6);
(void) safe_atou(s6, &val6);
}
cached = MAX(ROUTES_DEFAULT_MAX_PER_FAMILY, val4) +
MAX(ROUTES_DEFAULT_MAX_PER_FAMILY, val6);
return cached;
}
开发者ID:Werkov,项目名称:systemd,代码行数:26,代码来源:networkd-route.c
示例2: config_parse_unsigned
int config_parse_unsigned(
const char *filename,
unsigned line,
const char *section,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
unsigned *u = data;
int r;
assert(filename);
assert(lvalue);
assert(rvalue);
assert(data);
r = safe_atou(rvalue, u);
if (r < 0) {
log_error("[%s:%u] Failed to parse numeric value: %s", filename, line, rvalue);
return r;
}
return 0;
}
开发者ID:olegchir,项目名称:systemd,代码行数:26,代码来源:conf-parser.c
示例3: client_run
static int client_run(int ifindex, const char *seed_str, const struct ether_addr *ha, sd_event *e) {
sd_ipv4ll *ll;
assert_se(sd_ipv4ll_new(&ll) >= 0);
assert_se(sd_ipv4ll_attach_event(ll, e, 0) >= 0);
assert_se(sd_ipv4ll_set_index(ll, ifindex) >= 0);
assert_se(sd_ipv4ll_set_mac(ll, ha) >= 0);
assert_se(sd_ipv4ll_set_callback(ll, ll_handler, NULL) >= 0);
if (seed_str) {
unsigned seed;
assert_se(safe_atou(seed_str, &seed) >= 0);
assert_se(sd_ipv4ll_set_address_seed(ll, seed) >= 0);
}
log_info("starting IPv4LL client");
assert_se(sd_ipv4ll_start(ll) >= 0);
assert_se(sd_event_loop(e) >= 0);
assert_se(!sd_ipv4ll_unref(ll));
return EXIT_SUCCESS;
}
开发者ID:lnykryn,项目名称:systemd,代码行数:28,代码来源:test-ipv4ll-manual.c
示例4: socket_address_parse
int socket_address_parse(SocketAddress *a, const char *s) {
char *e, *n;
unsigned u;
int r;
assert(a);
assert(s);
zero(*a);
a->type = SOCK_STREAM;
if (*s == '[') {
/* IPv6 in [x:.....:z]:p notation */
if (!socket_ipv6_is_supported()) {
log_warning("Binding to IPv6 address not available since kernel does not support IPv6.");
return -EAFNOSUPPORT;
}
e = strchr(s+1, ']');
if (!e)
return -EINVAL;
n = strndupa(s+1, e-s-1);
errno = 0;
if (inet_pton(AF_INET6, n, &a->sockaddr.in6.sin6_addr) <= 0)
return errno > 0 ? -errno : -EINVAL;
e++;
if (*e != ':')
return -EINVAL;
e++;
r = safe_atou(e, &u);
if (r < 0)
return r;
if (u <= 0 || u > 0xFFFF)
return -EINVAL;
a->sockaddr.in6.sin6_family = AF_INET6;
a->sockaddr.in6.sin6_port = htons((uint16_t) u);
a->size = sizeof(struct sockaddr_in6);
} else if (*s == '/') {
/* AF_UNIX socket */
size_t l;
l = strlen(s);
if (l >= sizeof(a->sockaddr.un.sun_path))
return -EINVAL;
a->sockaddr.un.sun_family = AF_UNIX;
memcpy(a->sockaddr.un.sun_path, s, l);
a->size = offsetof(struct sockaddr_un, sun_path) + l + 1;
} else if (*s == '@') {
开发者ID:275288698,项目名称:systemd-ubuntu-with-dbus,代码行数:59,代码来源:socket-util.c
示例5: prompt_loop
static int prompt_loop(const char *text, char **l, bool (*is_valid)(const char *name), char **ret) {
int r;
assert(text);
assert(is_valid);
assert(ret);
for (;;) {
_cleanup_free_ char *p = NULL;
unsigned u;
r = ask_string(&p, "%s %s (empty to skip): ", draw_special_char(DRAW_TRIANGULAR_BULLET), text);
if (r < 0) {
log_error("Failed to query user: %s", strerror(-r));
return r;
}
if (isempty(p)) {
log_warning("No data entered, skipping.");
return 0;
}
r = safe_atou(p, &u);
if (r >= 0) {
char *c;
if (u <= 0 || u > strv_length(l)) {
log_error("Specified entry number out of range.");
continue;
}
log_info("Selected '%s'.", l[u-1]);
c = strdup(l[u-1]);
if (!c)
return log_oom();
free(*ret);
*ret = c;
return 0;
}
if (!is_valid(p)) {
log_error("Entered data invalid.");
continue;
}
free(*ret);
*ret = p;
p = 0;
return 0;
}
}
开发者ID:alan030189,项目名称:systemd,代码行数:53,代码来源:firstboot.c
示例6: test_ioprio_class_from_to_string_one
static void test_ioprio_class_from_to_string_one(const char *val, int expected) {
assert_se(ioprio_class_from_string(val) == expected);
if (expected >= 0) {
_cleanup_free_ char *s = NULL;
unsigned ret;
assert_se(ioprio_class_to_string_alloc(expected, &s) == 0);
/* We sometimes get a class number and sometimes a number back */
assert_se(streq(s, val) ||
safe_atou(val, &ret) == 0);
}
}
开发者ID:karelzak,项目名称:systemd,代码行数:12,代码来源:test-process-util.c
示例7: parse_cpu_set_and_warn
int parse_cpu_set_and_warn(
const char *rvalue,
cpu_set_t **cpu_set,
const char *unit,
const char *filename,
unsigned line,
const char *lvalue) {
const char *whole_rvalue = rvalue;
_cleanup_cpu_free_ cpu_set_t *c = NULL;
unsigned ncpus = 0;
assert(lvalue);
assert(rvalue);
for (;;) {
_cleanup_free_ char *word = NULL;
unsigned cpu;
int r;
r = extract_first_word(&rvalue, &word, WHITESPACE, EXTRACT_QUOTES);
if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, r, "Invalid value for %s: %s", lvalue, whole_rvalue);
return r;
}
if (r == 0)
break;
if (!c) {
c = cpu_set_malloc(&ncpus);
if (!c)
return log_oom();
}
r = safe_atou(word, &cpu);
if (r < 0 || cpu >= ncpus) {
log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse CPU affinity '%s'", rvalue);
return -EINVAL;
}
CPU_SET_S(cpu, CPU_ALLOC_SIZE(ncpus), c);
}
/* On success, sets *cpu_set and returns ncpus for the system. */
if (c) {
*cpu_set = c;
c = NULL;
}
return (int) ncpus;
}
开发者ID:josephgbr,项目名称:systemd,代码行数:51,代码来源:cpu-set-util.c
示例8: strspn
/* Ignore failure. E.g. 10.M is valid */
frac = l2;
for (; e < e2; e++)
frac /= 10;
}
}
e += strspn(e, WHITESPACE);
for (i = start_pos; i < n_entries; i++)
if (startswith(e, table[i].suffix))
break;
if (i >= n_entries)
return -EINVAL;
if (l + (frac > 0) > ULLONG_MAX / table[i].factor)
return -ERANGE;
tmp = l * table[i].factor + (unsigned long long) (frac * table[i].factor);
if (tmp > ULLONG_MAX - r)
return -ERANGE;
r += tmp;
if ((unsigned long long) (uint64_t) r != r)
return -ERANGE;
p = e + strlen(table[i].suffix);
start_pos = i + 1;
} while (*p);
*size = r;
return 0;
}
#if 0 /* NM_IGNORED */
int parse_range(const char *t, unsigned *lower, unsigned *upper) {
_cleanup_free_ char *word = NULL;
unsigned l, u;
int r;
assert(lower);
assert(upper);
/* Extract the lower bound. */
r = extract_first_word(&t, &word, "-", EXTRACT_DONT_COALESCE_SEPARATORS);
if (r < 0)
return r;
if (r == 0)
return -EINVAL;
r = safe_atou(word, &l);
if (r < 0)
return r;
/* Check for the upper bound and extract it if needed */
if (!t)
/* Single number with no dashes. */
u = l;
else if (!*t)
/* Trailing dash is an error. */
return -EINVAL;
else {
r = safe_atou(t, &u);
if (r < 0)
return r;
}
*lower = l;
*upper = u;
return 0;
}
开发者ID:atulhjp,项目名称:NetworkManager,代码行数:75,代码来源:parse-util.c
示例9: sd_session_get_vt
_public_ int sd_session_get_vt(const char *session, unsigned *vtnr) {
_cleanup_free_ char *vtnr_string = NULL;
unsigned u;
int r;
r = session_get_string(session, "VTNR", &vtnr_string);
if (r < 0)
return r;
r = safe_atou(vtnr_string, &u);
if (r < 0)
return r;
*vtnr = u;
return 0;
}
开发者ID:chuanchang,项目名称:systemd,代码行数:16,代码来源:sd-login.c
示例10: parse_percent_unbounded
int parse_percent_unbounded(const char *p) {
const char *pc, *n;
unsigned v;
int r;
pc = endswith(p, "%");
if (!pc)
return -EINVAL;
n = strndupa(p, pc - p);
r = safe_atou(n, &v);
if (r < 0)
return r;
return (int) v;
}
开发者ID:NetworkManager,项目名称:NetworkManager,代码行数:16,代码来源:parse-util.c
示例11: device_set_devuid
static int device_set_devuid(sd_device *device, const char *uid) {
unsigned u;
int r;
assert(device);
assert(uid);
r = safe_atou(uid, &u);
if (r < 0)
return r;
r = device_add_property_internal(device, "DEVUID", uid);
if (r < 0)
return r;
device->devuid = u;
return 0;
}
开发者ID:torstehu,项目名称:systemd,代码行数:19,代码来源:device-private.c
示例12: device_set_devgid
static int device_set_devgid(sd_device *device, const char *gid) {
unsigned g;
int r;
assert(device);
assert(gid);
r = safe_atou(gid, &g);
if (r < 0)
return r;
r = device_add_property_internal(device, "DEVGID", gid);
if (r < 0)
return r;
device->devgid = g;
return 0;
}
开发者ID:torstehu,项目名称:systemd,代码行数:19,代码来源:device-private.c
示例13: signal_from_string
int signal_from_string(const char *s) {
int signo;
int offset = 0;
unsigned u;
signo = __signal_from_string(s);
if (signo > 0)
return signo;
if (startswith(s, "RTMIN+")) {
s += 6;
offset = SIGRTMIN;
}
if (safe_atou(s, &u) >= 0) {
signo = (int) u + offset;
if (signo > 0 && signo < _NSIG)
return signo;
}
return -EINVAL;
}
开发者ID:AOSC-Dev,项目名称:systemd,代码行数:20,代码来源:signal-util.c
示例14: dns_type_from_string
int dns_type_from_string(const char *s) {
const struct dns_type_name *sc;
assert(s);
sc = lookup_dns_type(s, strlen(s));
if (sc)
return sc->id;
s = startswith_no_case(s, "TYPE");
if (s) {
unsigned x;
if (safe_atou(s, &x) >= 0 &&
x <= UINT16_MAX)
return (int) x;
}
return _DNS_TYPE_INVALID;
}
开发者ID:Hariprasathganesh,项目名称:testsysd,代码行数:20,代码来源:dns-type.c
示例15: test_cap_list
/* verify the capability parser */
static void test_cap_list(void) {
int i;
assert_se(!capability_to_name(-1));
assert_se(!capability_to_name(capability_list_length()));
for (i = 0; i < capability_list_length(); i++) {
const char *n;
assert_se(n = capability_to_name(i));
assert_se(capability_from_name(n) == i);
printf("%s = %i\n", n, i);
}
assert_se(capability_from_name("asdfbsd") == -EINVAL);
assert_se(capability_from_name("CAP_AUDIT_READ") == CAP_AUDIT_READ);
assert_se(capability_from_name("cap_audit_read") == CAP_AUDIT_READ);
assert_se(capability_from_name("cAp_aUdIt_rEAd") == CAP_AUDIT_READ);
assert_se(capability_from_name("0") == 0);
assert_se(capability_from_name("15") == 15);
assert_se(capability_from_name("-1") == -EINVAL);
for (i = 0; i < capability_list_length(); i++) {
_cleanup_cap_free_charp_ char *a = NULL;
const char *b;
unsigned u;
assert_se(a = cap_to_name(i));
/* quit the loop as soon as libcap starts returning
* numeric ids, formatted as strings */
if (safe_atou(a, &u) >= 0)
break;
assert_se(b = capability_to_name(i));
printf("%s vs. %s\n", a, b);
assert_se(strcasecmp(a, b) == 0);
}
}
开发者ID:arthur-c,项目名称:systemd,代码行数:42,代码来源:test-cap-list.c
示例16: add_match
static int add_match(Set *set, const char *match) {
int r = -ENOMEM;
unsigned pid;
const char* prefix;
char *pattern = NULL;
_cleanup_free_ char *p = NULL;
if (strchr(match, '='))
prefix = "";
else if (strchr(match, '/')) {
p = path_make_absolute_cwd(match);
if (!p)
goto fail;
match = p;
prefix = "COREDUMP_EXE=";
}
else if (safe_atou(match, &pid) == 0)
prefix = "COREDUMP_PID=";
else
prefix = "COREDUMP_COMM=";
pattern = strjoin(prefix, match, NULL);
if (!pattern)
goto fail;
log_debug("Adding pattern: %s", pattern);
r = set_put(set, pattern);
if (r < 0) {
log_error("Failed to add pattern '%s': %s",
pattern, strerror(-r));
free(pattern);
goto fail;
}
return 0;
fail:
log_error("Failed to add match: %s", strerror(-r));
return r;
}
开发者ID:jaanek,项目名称:systemd,代码行数:40,代码来源:coredumpctl.c
示例17: verify_contents
static void verify_contents(sd_journal *j, unsigned skip) {
unsigned i;
assert(j);
i = 0;
SD_JOURNAL_FOREACH(j) {
const void *d;
char *k, *c;
size_t l;
unsigned u;
assert_se(sd_journal_get_cursor(j, &k) >= 0);
printf("cursor: %s\n", k);
free(k);
assert_se(sd_journal_get_data(j, "MAGIC", &d, &l) >= 0);
printf("\t%.*s\n", (int) l, (const char*) d);
assert_se(sd_journal_get_data(j, "NUMBER", &d, &l) >= 0);
assert_se(k = strndup(d, l));
printf("\t%s\n", k);
if (skip > 0) {
assert_se(safe_atou(k + 7, &u) >= 0);
assert_se(i == u);
i += skip;
}
free(k);
assert_se(sd_journal_get_cursor(j, &c) >= 0);
assert_se(sd_journal_test_cursor(j, c) > 0);
free(c);
}
if (skip > 0)
assert_se(i == N_ENTRIES);
}
开发者ID:vitalikp,项目名称:journal,代码行数:39,代码来源:test-journal-stream.c
示例18: parse_argv
static int parse_argv(int argc, char *argv[]) {
enum {
ARG_VERSION = 0x100,
ARG_DEPTH,
ARG_CPU_TYPE,
ARG_ORDER,
ARG_RECURSIVE,
};
static const struct option options[] = {
{ "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, ARG_VERSION },
{ "delay", required_argument, NULL, 'd' },
{ "iterations", required_argument, NULL, 'n' },
{ "batch", no_argument, NULL, 'b' },
{ "raw", no_argument, NULL, 'r' },
{ "depth", required_argument, NULL, ARG_DEPTH },
{ "cpu", optional_argument, NULL, ARG_CPU_TYPE },
{ "order", required_argument, NULL, ARG_ORDER },
{ "recursive", required_argument, NULL, ARG_RECURSIVE },
{ "machine", required_argument, NULL, 'M' },
{}
};
bool recursive_unset = false;
int c, r;
assert(argc >= 1);
assert(argv);
while ((c = getopt_long(argc, argv, "hptcmin:brd:kPM:", options, NULL)) >= 0)
switch (c) {
case 'h':
help();
return 0;
case ARG_VERSION:
return version();
case ARG_CPU_TYPE:
if (optarg) {
if (streq(optarg, "time"))
arg_cpu_type = CPU_TIME;
else if (streq(optarg, "percentage"))
arg_cpu_type = CPU_PERCENT;
else {
log_error("Unknown argument to --cpu=: %s", optarg);
return -EINVAL;
}
} else
arg_cpu_type = CPU_TIME;
break;
case ARG_DEPTH:
r = safe_atou(optarg, &arg_depth);
if (r < 0) {
log_error("Failed to parse depth parameter.");
return -EINVAL;
}
break;
case 'd':
r = parse_sec(optarg, &arg_delay);
if (r < 0 || arg_delay <= 0) {
log_error("Failed to parse delay parameter.");
return -EINVAL;
}
break;
case 'n':
r = safe_atou(optarg, &arg_iterations);
if (r < 0) {
log_error("Failed to parse iterations parameter.");
return -EINVAL;
}
break;
case 'b':
arg_batch = true;
break;
case 'r':
arg_raw = true;
break;
case 'p':
arg_order = ORDER_PATH;
break;
case 't':
arg_order = ORDER_TASKS;
break;
//.........这里部分代码省略.........
开发者ID:Like-all,项目名称:tinysystemd-substrate,代码行数:101,代码来源:cgtop.c
示例19: automount_deserialize_item
static int automount_deserialize_item(Unit *u, const char *key, const char *value, FDSet *fds) {
Automount *a = AUTOMOUNT(u);
int r;
assert(a);
assert(fds);
if (streq(key, "state")) {
AutomountState state;
state = automount_state_from_string(value);
if (state < 0)
log_debug_unit(u->id, "Failed to parse state value %s", value);
else
a->deserialized_state = state;
} else if (streq(key, "result")) {
AutomountResult f;
f = automount_result_from_string(value);
if (f < 0)
log_debug_unit(u->id, "Failed to parse result value %s", value);
else if (f != AUTOMOUNT_SUCCESS)
a->result = f;
} else if (streq(key, "dev-id")) {
unsigned d;
if (safe_atou(value, &d) < 0)
log_debug_unit(u->id, "Failed to parse dev-id value %s", value);
else
a->dev_id = (unsigned) d;
} else if (streq(key, "token")) {
unsigned token;
if (safe_atou(value, &token) < 0)
log_debug_unit(u->id, "Failed to parse token value %s", value);
else {
if (!a->tokens)
if (!(a->tokens = set_new(trivial_hash_func, trivial_compare_func)))
return -ENOMEM;
r = set_put(a->tokens, UINT_TO_PTR(token));
if (r < 0)
return r;
}
} else if (streq(key, "pipe-fd")) {
int fd;
if (safe_atoi(value, &fd) < 0 || fd < 0 || !fdset_contains(fds, fd))
log_debug_unit(u->id, "Failed to parse pipe-fd value %s", value);
else {
if (a->pipe_fd >= 0)
close_nointr_nofail(a->pipe_fd);
a->pipe_fd = fdset_remove(fds, fd);
}
} else
log_debug_unit(u->id, "Unknown serialization key '%s'", key);
return 0;
}
开发者ID:ariscop,项目名称:systemd,代码行数:61,代码来源:automount.c
示例20: parse_argv
static int parse_argv(int argc, char *argv[]) {
enum {
ARG_VERSION = 0x100,
ARG_FILES_MAX,
ARG_FILE_SIZE_MAX,
ARG_TIMEOUT
};
static const struct option options[] = {
{ "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, ARG_VERSION },
{ "files-max", required_argument, NULL, ARG_FILES_MAX },
{ "file-size-max", required_argument, NULL, ARG_FILE_SIZE_MAX },
{ "timeout", required_argument, NULL, ARG_TIMEOUT },
{}
};
int c;
assert(argc >= 0);
assert(argv);
while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0) {
switch (c) {
case 'h':
return help();
case ARG_VERSION:
puts(PACKAGE_STRING);
puts(SYSTEMD_FEATURES);
return 0;
case ARG_FILES_MAX:
if (safe_atou(optarg, &arg_files_max) < 0 || arg_files_max <= 0) {
log_error("Failed to parse maximum number of files %s.", optarg);
return -EINVAL;
}
break;
case ARG_FILE_SIZE_MAX: {
unsigned long long ull;
if (safe_atollu(optarg, &ull) < 0 || ull <= 0) {
log_error("Failed to parse maximum file size %s.", optarg);
return -EINVAL;
}
arg_file_size_max = (off_t) ull;
break;
}
case ARG_TIMEOUT:
if (parse_sec(optarg, &arg_timeout) < 0 || arg_timeout <= 0) {
log_error("Failed to parse timeout %s.", optarg);
return -EINVAL;
}
break;
case '?':
return -EINVAL;
default:
assert_not_reached("Unhandled option");
}
}
if (optind != argc-1 &&
optind != argc-2) {
help();
return -EINVAL;
}
return 1;
}
开发者ID:MOBO-OSS,项目名称:systemd-relative,代码行数:78,代码来源:readahead.c
注:本文中的safe_atou函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论