]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/basic/parse-util.h
cpu-set-util: Accept commas as separators in parse_cpu_set_and_warn
[thirdparty/systemd.git] / src / basic / parse-util.h
CommitLineData
6bedfcbb
LP
1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3#pragma once
4
5/***
6 This file is part of systemd.
7
8 Copyright 2010 Lennart Poettering
9
10 systemd is free software; you can redistribute it and/or modify it
11 under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14
15 systemd is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
19
20 You should have received a copy of the GNU Lesser General Public License
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22***/
23
24#include <inttypes.h>
25#include <sys/types.h>
26
27#include "macro.h"
28
c7f1808a
LP
29#define MODE_INVALID ((mode_t) -1)
30
6bedfcbb
LP
31int parse_boolean(const char *v) _pure_;
32int parse_pid(const char *s, pid_t* ret_pid);
33int parse_mode(const char *s, mode_t *ret);
34
35int parse_size(const char *t, uint64_t base, uint64_t *size);
36
37#define FORMAT_BYTES_MAX 8
38char *format_bytes(char *buf, size_t l, uint64_t t);
39
40int safe_atou(const char *s, unsigned *ret_u);
41int safe_atoi(const char *s, int *ret_i);
42int safe_atollu(const char *s, unsigned long long *ret_u);
43int safe_atolli(const char *s, long long int *ret_i);
44
45int safe_atou8(const char *s, uint8_t *ret);
46
47int safe_atou16(const char *s, uint16_t *ret);
48int safe_atoi16(const char *s, int16_t *ret);
49
50static inline int safe_atou32(const char *s, uint32_t *ret_u) {
51 assert_cc(sizeof(uint32_t) == sizeof(unsigned));
52 return safe_atou(s, (unsigned*) ret_u);
53}
54
55static inline int safe_atoi32(const char *s, int32_t *ret_i) {
56 assert_cc(sizeof(int32_t) == sizeof(int));
57 return safe_atoi(s, (int*) ret_i);
58}
59
60static inline int safe_atou64(const char *s, uint64_t *ret_u) {
61 assert_cc(sizeof(uint64_t) == sizeof(unsigned long long));
62 return safe_atollu(s, (unsigned long long*) ret_u);
63}
64
65static inline int safe_atoi64(const char *s, int64_t *ret_i) {
66 assert_cc(sizeof(int64_t) == sizeof(long long int));
67 return safe_atolli(s, (long long int*) ret_i);
68}
69
70#if LONG_MAX == INT_MAX
71static inline int safe_atolu(const char *s, unsigned long *ret_u) {
72 assert_cc(sizeof(unsigned long) == sizeof(unsigned));
73 return safe_atou(s, (unsigned*) ret_u);
74}
75static inline int safe_atoli(const char *s, long int *ret_u) {
76 assert_cc(sizeof(long int) == sizeof(int));
77 return safe_atoi(s, (int*) ret_u);
78}
79#else
80static inline int safe_atolu(const char *s, unsigned long *ret_u) {
81 assert_cc(sizeof(unsigned long) == sizeof(unsigned long long));
82 return safe_atollu(s, (unsigned long long*) ret_u);
83}
84static inline int safe_atoli(const char *s, long int *ret_u) {
85 assert_cc(sizeof(long int) == sizeof(long long int));
86 return safe_atolli(s, (long long int*) ret_u);
87}
88#endif
89
90int safe_atod(const char *s, double *ret_d);