aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@users.noreply.github.com>2020-11-30 14:09:49 -0500
committerGitHub <noreply@github.com>2020-11-30 14:09:49 -0500
commitecc7897bf007c0672d5bdc7711bcbf9fb104f995 (patch)
tree9646047ca1f4b6f4a54e749d8670b11d940bf616
parentefb60e95320be455e28273b9c580b28cfceb6a1d (diff)
parenta20b46933554a91aeece1bf73810a25dd0b579a9 (diff)
downloadspmc-master.tar.gz
Merge pull request #50 from jhunkeler/atoi-to-strtolHEADmaster
Replace atoi usage
-rw-r--r--lib/config.c21
-rw-r--r--lib/manifest.c5
-rw-r--r--lib/str.c4
3 files changed, 4 insertions, 26 deletions
diff --git a/lib/config.c b/lib/config.c
index 0fb17e8..8ead9a8 100644
--- a/lib/config.c
+++ b/lib/config.c
@@ -210,24 +210,3 @@ ConfigItem *config_get(ConfigItem **item, const char *key) {
}
return NULL;
}
-
-void config_test(void) {
- ConfigItem **config = config_read("program.conf");
- printf("Data Parsed:\n");
- for (int i = 0; config[i] != NULL; i++) {
- printf("key: '%s', value: '%s'\n", config[i]->key, config[i]->value);
- }
-
- printf("Testing config_get():\n");
- ConfigItem *cptr = NULL;
- if ((cptr = config_get(config, "integer_value"))) {
- printf("%s = %d\n", cptr->key, atoi(cptr->value));
- }
- if ((cptr = config_get(config, "float_value"))) {
- printf("%s = %.3f\n", cptr->key, atof(cptr->value));
- }
- if ((cptr = config_get(config, "string_value"))) {
- printf("%s = %s\n", cptr->key, cptr->value);
- }
- config_free(config);
-}
diff --git a/lib/manifest.c b/lib/manifest.c
index cd51b97..f746bbe 100644
--- a/lib/manifest.c
+++ b/lib/manifest.c
@@ -473,7 +473,6 @@ Manifest *manifest_read(char *file_or_url) {
info->records = total_records;
while (fgets(dptr, BUFSIZ, fp) != NULL) {
dptr = strip(dptr);
- char *garbage = NULL;
char **parts = split(dptr, separator);
char *_origin = NULL;
@@ -490,11 +489,11 @@ Manifest *manifest_read(char *file_or_url) {
free(_origin);
strncpy(info->packages[i]->archive, parts[0], SPM_PACKAGE_MEMBER_SIZE);
- info->packages[i]->size = strtoul(parts[1], &garbage, 10);
+ info->packages[i]->size = strtoul(parts[1], NULL, 10);
strncpy(info->packages[i]->name, parts[2], SPM_PACKAGE_MEMBER_SIZE);
strncpy(info->packages[i]->version, parts[3], SPM_PACKAGE_MEMBER_SIZE);
strncpy(info->packages[i]->revision, parts[4], SPM_PACKAGE_MEMBER_SIZE);
- info->packages[i]->requirements_records = (size_t) atoi(parts[5]);
+ info->packages[i]->requirements_records = strtoul(parts[5], NULL, 10);
info->packages[i]->requirements = NULL;
if (strncmp(parts[6], SPM_MANIFEST_NODATA, strlen(SPM_MANIFEST_NODATA)) != 0) {
diff --git a/lib/str.c b/lib/str.c
index 5fbb8ad..fbf6e9d 100644
--- a/lib/str.c
+++ b/lib/str.c
@@ -427,8 +427,8 @@ static int _strsort_numeric_compare(const void *a, const void *b) {
const char *bb = *(const char **)b;
if (isdigit(*aa) && isdigit(*bb)) {
- int ia = atoi(aa);
- int ib = atoi(bb);
+ long ia = strtol(aa, NULL, 10);
+ long ib = strtol(bb, NULL, 10);
if (ia == ib) {
return 0;