summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2022-11-03 17:55:47 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2022-11-03 17:55:47 -0700
commit066b59df4a07fb426f7a4173a0e57818ab26d875 (patch)
tree7ce55f25ead698209264db4cd61bed7835fb0c58
parent120c202bc39abfdfd7a60e407abd742e6cb218e2 (diff)
Use strtof() if available, instead of casting atof() to float
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r--configure.ac2
-rw-r--r--xgamma.c12
2 files changed, 10 insertions, 4 deletions
diff --git a/configure.ac b/configure.ac
index d526307..6a3fda0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -37,6 +37,8 @@ m4_ifndef([XORG_MACROS_VERSION],
XORG_MACROS_VERSION(1.8)
XORG_DEFAULT_OPTIONS
+AC_CHECK_FUNCS([strtof])
+
# Checks for pkg-config packages
PKG_CHECK_MODULES(XGAMMA, [x11 xxf86vm xproto >= 7.0.17])
diff --git a/xgamma.c b/xgamma.c
index 511decd..f370dfe 100644
--- a/xgamma.c
+++ b/xgamma.c
@@ -35,6 +35,10 @@
#include <ctype.h>
#include <stdlib.h>
+#ifndef HAVE_STRTOF
+#define strtof(a, n) (float)atof(a)
+#endif
+
static char *ProgramName;
static int MajorVersion, MinorVersion;
static int EventBase, ErrorBase;
@@ -129,7 +133,7 @@ main(int argc, char *argv[])
if (++i >= argc) Syntax ("-gamma requires an argument");
if ((rgam >= 0.0f) || (ggam >= 0.0f) || (bgam >= 0.0f))
Syntax ("-gamma cannot be used with -rgamma, -ggamma, or -bgamma");
- gam = (float)atof(argv[i]);
+ gam = strtof(argv[i], NULL);
if ((gam < GAMMA_MIN) || (gam > GAMMA_MAX)) {
fprintf(stderr,
"Gamma values must be between %6.3f and %6.3f\n",
@@ -140,7 +144,7 @@ main(int argc, char *argv[])
} else if (isabbreviation ("-rgamma", arg, 2)) {
if (++i >= argc) Syntax ("-rgamma requires an argument");
if (gam >= 0.0f) Syntax ("cannot set both -gamma and -rgamma");
- rgam = (float)atof(argv[i]);
+ rgam = strtof(argv[i], NULL);
if ((rgam < GAMMA_MIN) || (rgam > GAMMA_MAX)) {
fprintf(stderr,
"Gamma values must be between %6.3f and %6.3f\n",
@@ -151,7 +155,7 @@ main(int argc, char *argv[])
} else if (isabbreviation ("-ggamma", arg, 2)) {
if (++i >= argc) Syntax ("-ggamma requires an argument");
if (gam >= 0.0f) Syntax ("cannot set both -gamma and -ggamma");
- ggam = (float)atof(argv[i]);
+ ggam = strtof(argv[i], NULL);
if ((ggam < GAMMA_MIN) || (ggam > GAMMA_MAX)) {
fprintf(stderr,
"Gamma values must be between %6.3f and %6.3f\n",
@@ -162,7 +166,7 @@ main(int argc, char *argv[])
} else if (isabbreviation ("-bgamma", arg, 2)) {
if (++i >= argc) Syntax ("-bgamma requires an argument");
if (gam >= 0.0f) Syntax ("cannot set both -gamma and -bgamma");
- bgam = (float)atof(argv[i]);
+ bgam = strtof(argv[i], NULL);
if ((bgam < GAMMA_MIN) || (bgam > GAMMA_MAX)) {
fprintf(stderr,
"Gamma values must be between %6.3f and %6.3f\n",