diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2020-06-24 01:36:27 -0400 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2020-06-24 01:36:27 -0400 |
commit | a20b46933554a91aeece1bf73810a25dd0b579a9 (patch) | |
tree | 9646047ca1f4b6f4a54e749d8670b11d940bf616 | |
parent | efb60e95320be455e28273b9c580b28cfceb6a1d (diff) | |
download | spmc-a20b46933554a91aeece1bf73810a25dd0b579a9.tar.gz |
Replace atoi usage
-rw-r--r-- | lib/config.c | 21 | ||||
-rw-r--r-- | lib/manifest.c | 5 | ||||
-rw-r--r-- | lib/str.c | 4 |
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) { @@ -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; |