summaryrefslogtreecommitdiff
path: root/src/misc.c
diff options
context:
space:
mode:
authorPaul Smith <psmith@gnu.org>2022-06-04 17:44:21 -0400
committerPaul Smith <psmith@gnu.org>2022-06-04 18:34:15 -0400
commite4b7ac21dc1663de1d901cda0b395d819b5c08ab (patch)
tree912aba0001bb5740b5665b51c0f09380f3e53222 /src/misc.c
parentd444b87173069dac357fd3a3b88f9ca057481f22 (diff)
downloadmake-git-e4b7ac21dc1663de1d901cda0b395d819b5c08ab.tar.gz
* src/misc.c (make_toui): Parse a string into an unsigned int
* src/makeint.h: Declare it. * src/arscan.c (ar_scan): Replace atoi() calls with make_toui(). Modify some integral types to be more correct. * src/job.c (load_too_high): Replace atoi() calls with make_toui(). * src/main.c (main): Ditto. (decode_switches): Ditto.
Diffstat (limited to 'src/misc.c')
-rw-r--r--src/misc.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/misc.c b/src/misc.c
index b03f2a3a..624cd058 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -34,6 +34,25 @@ this program. If not, see <http://www.gnu.org/licenses/>. */
# include <sys/file.h>
#endif
+unsigned int
+make_toui (const char *str, const char **error)
+{
+ char *end;
+ unsigned long val = strtoul (str, &end, 10);
+
+ if (error)
+ {
+ if (str[0] == '\0')
+ *error = "Missing value";
+ else if (*end != '\0')
+ *error = "Invalid value";
+ else
+ *error = NULL;
+ }
+
+ return val;
+}
+
/* Compare strings *S1 and *S2.
Return negative if the first is less, positive if it is greater,
zero if they are equal. */