Index: usr.sbin/mixer/mixer.8 =================================================================== --- usr.sbin/mixer/mixer.8 +++ usr.sbin/mixer/mixer.8 @@ -21,7 +21,7 @@ .\" .\" $FreeBSD$ .\" -.Dd March 20, 2022 +.Dd April 29, 2022 .Dt MIXER 8 .Os .Sh NAME @@ -112,8 +112,8 @@ .It Sy Name Ta Sy Value .It Ar dev Cm .volume Ta Xo .Ar vol | -.Oo Cm \&+ | Cm \&- Oc Ar lvol -.Oo Cm \&: Oo Cm \&+ | Cm \&- Oc Ar rvol Oc +.Oo Cm \&+ | Cm \&- Oc Ar lvol Oo % Oc +.Oo Cm \&: Oo Cm \&+ | Cm \&- Oc Ar rvol Oo % Oc Oc .Xc .It Ar dev Cm .mute Ta Cm 0 | 1 | ^ .It Ar dev Cm .recsrc Ta Cm ^ | + | - | = @@ -128,10 +128,10 @@ and/or .Ar rvol values have to be specified. -The values have to be normalized 32-bit floats, from 0.0 to 1.0 inclusively. -If no -.Ql \&. -character is present, the value is treated like a percentage, for backwards compatibility. +The values should typically be normalized 32-bit floats, from 0.0 to 1.0 +inclusively. +A trailing percent sign indicates that the value should be treated as a percent, +rather than an absolute value. If the left or right volume values are prefixed with .Cm + or Index: usr.sbin/mixer/mixer.c =================================================================== --- usr.sbin/mixer/mixer.c +++ usr.sbin/mixer/mixer.c @@ -341,7 +341,7 @@ mix_ctl_t *cp; mix_volume_t v; const char *val; - char lstr[8], rstr[8]; + char *endp, lstr[8], rstr[8]; float lprev, rprev, lrel, rrel; int n; @@ -357,19 +357,25 @@ if (n > 0) { if (*lstr == '+' || *lstr == '-') lrel = rrel = 1; - v.left = strtof(lstr, NULL); + v.left = strtof(lstr, &endp); + if (*endp != '\0' && *endp != '%') { + warnx("invalid volume value: %s", lstr); + return (-1); + } - /* be backwards compatible */ - if (strstr(lstr, ".") == NULL) + if (*endp == '%') v.left /= 100.0f; } if (n > 1) { if (*rstr == '+' || *rstr == '-') rrel = 1; - v.right = strtof(rstr, NULL); + v.right = strtof(rstr, &endp); + if (*endp != '\0' && *endp != '%') { + warnx("invalid volume value: %s", rstr); + return (-1); + } - /* be backwards compatible */ - if (strstr(rstr, ".") == NULL) + if (*endp == '%') v.right /= 100.0f; } switch (n) {