6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering#pragma once
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering/***
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering This file is part of systemd.
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering Copyright 2010 Lennart Poettering
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering systemd is free software; you can redistribute it and/or modify it
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering under the terms of the GNU Lesser General Public License as published by
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering (at your option) any later version.
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering systemd is distributed in the hope that it will be useful, but
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering Lesser General Public License for more details.
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering You should have received a copy of the GNU Lesser General Public License
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering***/
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering#include <inttypes.h>
11c3a36649e5e5e77db499c92f3cdcbd619efd3aThomas Hindoe Paaboel Andersen#include <limits.h>
11c3a36649e5e5e77db499c92f3cdcbd619efd3aThomas Hindoe Paaboel Andersen#include <stddef.h>
11c3a36649e5e5e77db499c92f3cdcbd619efd3aThomas Hindoe Paaboel Andersen#include <stdint.h>
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering#include <sys/types.h>
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering#include "macro.h"
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering
c7f1808add4d971229ba5311cf66e659122aa338Lennart Poettering#define MODE_INVALID ((mode_t) -1)
c7f1808add4d971229ba5311cf66e659122aa338Lennart Poettering
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poetteringint parse_boolean(const char *v) _pure_;
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poetteringint parse_pid(const char *s, pid_t* ret_pid);
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poetteringint parse_mode(const char *s, mode_t *ret);
6ad623a3f77e087e308f334525fd4046811f2a9aLennart Poetteringint parse_ifindex(const char *s, int *ret);
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poetteringint parse_size(const char *t, uint64_t base, uint64_t *size);
28cb17ef0281efc3a46e5d0e702b0b0ddeaafaa4Filipe Brandenburgerint parse_range(const char *t, unsigned *lower, unsigned *upper);
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering#define FORMAT_BYTES_MAX 8
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poetteringchar *format_bytes(char *buf, size_t l, uint64_t t);
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poetteringint safe_atou(const char *s, unsigned *ret_u);
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poetteringint safe_atoi(const char *s, int *ret_i);
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poetteringint safe_atollu(const char *s, unsigned long long *ret_u);
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poetteringint safe_atolli(const char *s, long long int *ret_i);
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poetteringint safe_atou8(const char *s, uint8_t *ret);
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poetteringint safe_atou16(const char *s, uint16_t *ret);
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poetteringint safe_atoi16(const char *s, int16_t *ret);
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poetteringstatic inline int safe_atou32(const char *s, uint32_t *ret_u) {
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering assert_cc(sizeof(uint32_t) == sizeof(unsigned));
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering return safe_atou(s, (unsigned*) ret_u);
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering}
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poetteringstatic inline int safe_atoi32(const char *s, int32_t *ret_i) {
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering assert_cc(sizeof(int32_t) == sizeof(int));
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering return safe_atoi(s, (int*) ret_i);
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering}
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poetteringstatic inline int safe_atou64(const char *s, uint64_t *ret_u) {
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering assert_cc(sizeof(uint64_t) == sizeof(unsigned long long));
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering return safe_atollu(s, (unsigned long long*) ret_u);
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering}
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poetteringstatic inline int safe_atoi64(const char *s, int64_t *ret_i) {
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering assert_cc(sizeof(int64_t) == sizeof(long long int));
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering return safe_atolli(s, (long long int*) ret_i);
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering}
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering#if LONG_MAX == INT_MAX
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poetteringstatic inline int safe_atolu(const char *s, unsigned long *ret_u) {
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering assert_cc(sizeof(unsigned long) == sizeof(unsigned));
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering return safe_atou(s, (unsigned*) ret_u);
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering}
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poetteringstatic inline int safe_atoli(const char *s, long int *ret_u) {
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering assert_cc(sizeof(long int) == sizeof(int));
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering return safe_atoi(s, (int*) ret_u);
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering}
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering#else
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poetteringstatic inline int safe_atolu(const char *s, unsigned long *ret_u) {
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering assert_cc(sizeof(unsigned long) == sizeof(unsigned long long));
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering return safe_atollu(s, (unsigned long long*) ret_u);
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering}
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poetteringstatic inline int safe_atoli(const char *s, long int *ret_u) {
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering assert_cc(sizeof(long int) == sizeof(long long int));
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering return safe_atolli(s, (long long int*) ret_u);
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering}
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering#endif
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poetteringint safe_atod(const char *s, double *ret_d);
436dd70f5331ec541ebdd84e106abaa63203f6f1Hristo Venev
436dd70f5331ec541ebdd84e106abaa63203f6f1Hristo Venevint parse_fractional_part_u(const char **s, size_t digits, unsigned *res);