summaryrefslogtreecommitdiff
path: root/src/shared/conf-parser.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-02-23 03:13:54 +0100
committerLennart Poettering <lennart@poettering.net>2014-02-23 03:19:04 +0100
commit5556b5fe41173107a67dbe875fbd916a46e52a02 (patch)
treea9ca468b7c030c5c95a87bb35b4f986dedb1bba8 /src/shared/conf-parser.c
parente342365c27ecae32a7f20ada0b2c623ce22e5ea8 (diff)
core: clean up some confusing regarding SI decimal and IEC binary suffixes for sizes
According to Wikipedia it is customary to specify hardware metrics and transfer speeds to the basis 1000 (SI decimal), while software metrics and physical volatile memory (RAM) sizes to the basis 1024 (IEC binary). So far we specified everything in IEC, let's fix that and be more true to what's otherwise customary. Since we don't want to parse "Mi" instead of "M" we document each time what the context used is.
Diffstat (limited to 'src/shared/conf-parser.c')
-rw-r--r--src/shared/conf-parser.c44
1 files changed, 35 insertions, 9 deletions
diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c
index dde62b5755..cfa669b113 100644
--- a/src/shared/conf-parser.c
+++ b/src/shared/conf-parser.c
@@ -447,8 +447,7 @@ DEFINE_PARSER(double, double, safe_atod)
DEFINE_PARSER(nsec, nsec_t, parse_nsec)
DEFINE_PARSER(sec, usec_t, parse_sec)
-
-int config_parse_bytes_size(const char* unit,
+int config_parse_iec_size(const char* unit,
const char *filename,
unsigned line,
const char *section,
@@ -468,10 +467,9 @@ int config_parse_bytes_size(const char* unit,
assert(rvalue);
assert(data);
- r = parse_bytes(rvalue, &o);
+ r = parse_size(rvalue, 1024, &o);
if (r < 0 || (off_t) (size_t) o != o) {
- log_syntax(unit, LOG_ERR, filename, line, -r,
- "Failed to parse byte value, ignoring: %s", rvalue);
+ log_syntax(unit, LOG_ERR, filename, line, r < 0 ? -r : ERANGE, "Failed to parse size value, ignoring: %s", rvalue);
return 0;
}
@@ -479,8 +477,37 @@ int config_parse_bytes_size(const char* unit,
return 0;
}
+int config_parse_si_size(const char* unit,
+ const char *filename,
+ unsigned line,
+ const char *section,
+ unsigned section_line,
+ const char *lvalue,
+ int ltype,
+ const char *rvalue,
+ void *data,
+ void *userdata) {
+
+ size_t *sz = data;
+ off_t o;
+ int r;
+
+ assert(filename);
+ assert(lvalue);
+ assert(rvalue);
+ assert(data);
+
+ r = parse_size(rvalue, 1000, &o);
+ if (r < 0 || (off_t) (size_t) o != o) {
+ log_syntax(unit, LOG_ERR, filename, line, r < 0 ? -r : ERANGE, "Failed to parse size value, ignoring: %s", rvalue);
+ return 0;
+ }
+
+ *sz = (size_t) o;
+ return 0;
+}
-int config_parse_bytes_off(const char* unit,
+int config_parse_iec_off(const char* unit,
const char *filename,
unsigned line,
const char *section,
@@ -501,10 +528,9 @@ int config_parse_bytes_off(const char* unit,
assert_cc(sizeof(off_t) == sizeof(uint64_t));
- r = parse_bytes(rvalue, bytes);
+ r = parse_size(rvalue, 1024, bytes);
if (r < 0)
- log_syntax(unit, LOG_ERR, filename, line, -r,
- "Failed to parse bytes value, ignoring: %s", rvalue);
+ log_syntax(unit, LOG_ERR, filename, line, -r, "Failed to parse size value, ignoring: %s", rvalue);
return 0;
}