-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replacing atoi with proper number parsing
- Loading branch information
Showing
39 changed files
with
116 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,4 @@ venv/ | |
lib/hardware_info_root.py | ||
tools/cluster/cleanup.sh | ||
node_modules/ | ||
lib/c/parse_int.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
CFLAGS = -o3 -Wall | ||
|
||
parse_int.o: parse_int.c | ||
gcc -c $< $(CFLAGS) -o $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include "parse_int.h" | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <errno.h> | ||
#include <unistd.h> | ||
#include <limits.h> | ||
|
||
unsigned int parse_int(char *argument) { | ||
unsigned long int number = 0; | ||
char *endptr; | ||
|
||
errno = 0; // Reset errno before the call | ||
number = strtoul(argument, &endptr, 10); | ||
|
||
if (errno == ERANGE && (number == LONG_MAX || number == LONG_MIN)) { | ||
fprintf(stderr, "Error: Could not parse -i argument - Number out of range\n"); | ||
exit(1); | ||
} else if (errno != 0 && number == 0) { | ||
fprintf(stderr, "Error: Could not parse -i argument - Invalid number\n"); | ||
exit(1); | ||
} else if (endptr == argument) { | ||
fprintf(stderr, "Error: Could not parse -i argument - No digits were found\n"); | ||
exit(1); | ||
} else if (*endptr != '\0') { | ||
fprintf(stderr, "Error: Could not parse -i argument - Invalid characters after number\n"); | ||
exit(1); | ||
} | ||
|
||
return number; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#ifndef PARSE_INT_H | ||
#define PARSE_INT_H | ||
|
||
unsigned int parse_int(char *argument); | ||
|
||
#endif // PARSE_INT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
CFLAGS = -o3 -Wall -lm | ||
CFLAGS = -o3 -Wall -lm -I../../../../../../lib/c | ||
|
||
metric-provider-binary: source.c | ||
gcc $< $(CFLAGS) -o $@ | ||
gcc ../../../../../../lib/c/parse_int.o $< $(CFLAGS) -o $@ | ||
sudo chown root $@ | ||
sudo chmod u+s $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
CFLAGS = -o3 -Wall | ||
CFLAGS = -o3 -Wall -I../../../../../lib/c | ||
|
||
metric-provider-binary: source.c | ||
gcc $< $(CFLAGS) -o $@ | ||
gcc ../../../../../lib/c/parse_int.o $< $(CFLAGS) -o $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
CFLAGS = -o3 -Wall | ||
CFLAGS = -o3 -Wall -I../../../../../lib/c | ||
|
||
metric-provider-binary: source.c | ||
gcc $< $(CFLAGS) -o $@ | ||
gcc ../../../../../lib/c/parse_int.o $< $(CFLAGS) -o $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
CFLAGS = -o3 -Wall | ||
CFLAGS = -o3 -Wall -I../../../../../lib/c | ||
|
||
metric-provider-binary: source.c | ||
gcc $< $(CFLAGS) -o $@ | ||
gcc ../../../../../lib/c/parse_int.o $< $(CFLAGS) -o $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
CFLAGS = -o3 -Wall | ||
CFLAGS = -o3 -Wall -I../../../../../lib/c | ||
|
||
metric-provider-binary: source.c | ||
gcc $< $(CFLAGS) -o $@ | ||
gcc ../../../../../lib/c/parse_int.o $< $(CFLAGS) -o $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
CFLAGS = -o3 -Wall | ||
CFLAGS = -o3 -Wall -I../../../../../lib/c | ||
|
||
metric-provider-binary: source.c | ||
gcc $< $(CFLAGS) -o $@ | ||
gcc ../../../../../lib/c/parse_int.o $< $(CFLAGS) -o $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
CFLAGS = -o3 -Wall | ||
CFLAGS = -o3 -Wall -I../../../../../lib/c | ||
|
||
metric-provider-binary: source.c | ||
gcc $< $(CFLAGS) -o $@ | ||
gcc ../../../../../lib/c/parse_int.o $< $(CFLAGS) -o $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
CFLAGS = -o3 -Wall | ||
CFLAGS = -o3 -Wall -I../../../../../lib/c | ||
|
||
metric-provider-binary: source.c | ||
gcc $< $(CFLAGS) -o $@ | ||
gcc ../../../../../lib/c/parse_int.o $< $(CFLAGS) -o $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
CFLAGS = -o3 -Wall | ||
CFLAGS = -o3 -Wall -I../../../../../lib/c | ||
|
||
metric-provider-binary: source.c | ||
gcc $< $(CFLAGS) -o $@ | ||
gcc ../../../../../lib/c/parse_int.o $< $(CFLAGS) -o $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
CFLAGS = -o3 -Wall | ||
CFLAGS = -o3 -Wall -I../../../../../lib/c | ||
|
||
metric-provider-binary: source.c | ||
gcc $< $(CFLAGS) -o $@ | ||
gcc ../../../../../lib/c/parse_int.o $< $(CFLAGS) -o $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
CFLAGS = -o3 -Wall -lm | ||
CFLAGS = -o3 -Wall -lm -I../../../../../../lib/c | ||
|
||
metric-provider-binary: source.c | ||
gcc $< $(CFLAGS) -o $@ | ||
gcc ../../../../../../lib/c/parse_int.o $< $(CFLAGS) -o $@ | ||
sudo chown root $@ | ||
sudo chmod u+s $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
CFLAGS = -o3 -Wall | ||
CFLAGS = -o3 -Wall -I../../../../../lib/c | ||
|
||
metric-provider-binary: source.c | ||
gcc $< $(CFLAGS) -o $@ | ||
gcc ../../../../../lib/c/parse_int.o $< $(CFLAGS) -o $@ |
Oops, something went wrong.