summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.mk2
-rw-r--r--pkstn.h138
-rw-r--r--test/pkstn.c22
-rw-r--r--test/pkstn.cpp22
4 files changed, 92 insertions, 92 deletions
diff --git a/config.mk b/config.mk
index ca23f51..3bc19f6 100644
--- a/config.mk
+++ b/config.mk
@@ -1,5 +1,5 @@
# pk.h version
-VERSION = 0.0.3
+VERSION = 0.0.4
# paths
PREFIX = /usr/local
diff --git a/pkstn.h b/pkstn.h
index fd9233d..1d5430f 100644
--- a/pkstn.h
+++ b/pkstn.h
@@ -7,31 +7,31 @@
#include <stdint.h>
#include <stdlib.h>
-enum PK_STN_ERR {
- PK_STN_ERR_SUCCESS,
- PK_STN_ERR_OVERFLOW,
- PK_STN_ERR_UNDERFLOW,
- PK_STN_ERR_INCONVERTIBLE
+enum PK_STN_RES {
+ PK_STN_RES_SUCCESS,
+ PK_STN_RES_OVERFLOW,
+ PK_STN_RES_UNDERFLOW,
+ PK_STN_RES_INCONVERTIBLE
};
-enum PK_STN_ERR pk_stn_int64_t(int64_t *i, char const *s, int base);
-enum PK_STN_ERR pk_stn_uint64_t(uint64_t *i, char const *s, int base);
-enum PK_STN_ERR pk_stn_int32_t(int32_t *i, char const *s, int base);
-enum PK_STN_ERR pk_stn_uint32_t(uint32_t *i, char const *s, int base);
-enum PK_STN_ERR pk_stn_int16_t(int16_t *i, char const *s, int base);
-enum PK_STN_ERR pk_stn_uint16_t(uint16_t *i, char const *s, int base);
-enum PK_STN_ERR pk_stn_int8_t(int8_t *i, char const *s, int base);
-enum PK_STN_ERR pk_stn_uint8_t(uint8_t *i, char const *s, int base);
-enum PK_STN_ERR pk_stn_float(float *f, char const *s);
-enum PK_STN_ERR pk_stn_double(double *d, char const *s);
-enum PK_STN_ERR pk_stn_float_e(float *f, char const *s, char **pEnd);
-enum PK_STN_ERR pk_stn_double_e(double *d, char const *s, char **pEnd);
+enum PK_STN_RES pk_stn_int64_t(int64_t *i, char const *s, int base);
+enum PK_STN_RES pk_stn_uint64_t(uint64_t *i, char const *s, int base);
+enum PK_STN_RES pk_stn_int32_t(int32_t *i, char const *s, int base);
+enum PK_STN_RES pk_stn_uint32_t(uint32_t *i, char const *s, int base);
+enum PK_STN_RES pk_stn_int16_t(int16_t *i, char const *s, int base);
+enum PK_STN_RES pk_stn_uint16_t(uint16_t *i, char const *s, int base);
+enum PK_STN_RES pk_stn_int8_t(int8_t *i, char const *s, int base);
+enum PK_STN_RES pk_stn_uint8_t(uint8_t *i, char const *s, int base);
+enum PK_STN_RES pk_stn_float(float *f, char const *s);
+enum PK_STN_RES pk_stn_double(double *d, char const *s);
+enum PK_STN_RES pk_stn_float_e(float *f, char const *s, char **pEnd);
+enum PK_STN_RES pk_stn_double_e(double *d, char const *s, char **pEnd);
#endif /* PK_PK_STN_H */
#ifdef PK_IMPL_STN
-enum PK_STN_ERR
+enum PK_STN_RES
pk_stn_int64_t(int64_t *i, char const *s, int base)
{
char *end;
@@ -39,19 +39,19 @@ pk_stn_int64_t(int64_t *i, char const *s, int base)
errno = 0;
l = strtoll(s, &end, base);
if (errno == ERANGE && l == LLONG_MAX) {
- return PK_STN_ERR_OVERFLOW;
+ return PK_STN_RES_OVERFLOW;
}
if (errno == ERANGE && l == LLONG_MIN) {
- return PK_STN_ERR_UNDERFLOW;
+ return PK_STN_RES_UNDERFLOW;
}
if (*s == '\0' || *end != '\0') {
- return PK_STN_ERR_INCONVERTIBLE;
+ return PK_STN_RES_INCONVERTIBLE;
}
*i = l;
- return PK_STN_ERR_SUCCESS;
+ return PK_STN_RES_SUCCESS;
}
-enum PK_STN_ERR
+enum PK_STN_RES
pk_stn_uint64_t(uint64_t *i, char const *s, int base)
{
char *end;
@@ -59,19 +59,19 @@ pk_stn_uint64_t(uint64_t *i, char const *s, int base)
errno = 0;
l = strtoull(s, &end, base);
if (errno == ERANGE && l == LLONG_MAX) {
- return PK_STN_ERR_OVERFLOW;
+ return PK_STN_RES_OVERFLOW;
}
if (errno == ERANGE && l == LLONG_MIN) {
- return PK_STN_ERR_UNDERFLOW;
+ return PK_STN_RES_UNDERFLOW;
}
if (*s == '\0' || *end != '\0') {
- return PK_STN_ERR_INCONVERTIBLE;
+ return PK_STN_RES_INCONVERTIBLE;
}
*i = l;
- return PK_STN_ERR_SUCCESS;
+ return PK_STN_RES_SUCCESS;
}
-enum PK_STN_ERR
+enum PK_STN_RES
pk_stn_int32_t(int32_t *i, char const *s, int base)
{
char *end;
@@ -79,19 +79,19 @@ pk_stn_int32_t(int32_t *i, char const *s, int base)
errno = 0;
l = strtol(s, &end, base);
if (errno == ERANGE && l == LONG_MAX) {
- return PK_STN_ERR_OVERFLOW;
+ return PK_STN_RES_OVERFLOW;
}
if (errno == ERANGE && l == LONG_MIN) {
- return PK_STN_ERR_UNDERFLOW;
+ return PK_STN_RES_UNDERFLOW;
}
if (*s == '\0' || *end != '\0') {
- return PK_STN_ERR_INCONVERTIBLE;
+ return PK_STN_RES_INCONVERTIBLE;
}
*i = l;
- return PK_STN_ERR_SUCCESS;
+ return PK_STN_RES_SUCCESS;
}
-enum PK_STN_ERR
+enum PK_STN_RES
pk_stn_uint32_t(uint32_t *i, char const *s, int base)
{
char *end;
@@ -99,19 +99,19 @@ pk_stn_uint32_t(uint32_t *i, char const *s, int base)
errno = 0;
l = strtoul(s, &end, base);
if (errno == ERANGE && l == LONG_MAX) {
- return PK_STN_ERR_OVERFLOW;
+ return PK_STN_RES_OVERFLOW;
}
if (errno == ERANGE && l == LONG_MIN) {
- return PK_STN_ERR_UNDERFLOW;
+ return PK_STN_RES_UNDERFLOW;
}
if (*s == '\0' || *end != '\0') {
- return PK_STN_ERR_INCONVERTIBLE;
+ return PK_STN_RES_INCONVERTIBLE;
}
*i = l;
- return PK_STN_ERR_SUCCESS;
+ return PK_STN_RES_SUCCESS;
}
-enum PK_STN_ERR
+enum PK_STN_RES
pk_stn_int16_t(int16_t *i, char const *s, int base)
{
char *end;
@@ -119,19 +119,19 @@ pk_stn_int16_t(int16_t *i, char const *s, int base)
errno = 0;
l = strtol(s, &end, base);
if (errno == ERANGE && l == LONG_MAX) {
- return PK_STN_ERR_OVERFLOW;
+ return PK_STN_RES_OVERFLOW;
}
if (errno == ERANGE && l == LONG_MIN) {
- return PK_STN_ERR_UNDERFLOW;
+ return PK_STN_RES_UNDERFLOW;
}
if (*s == '\0' || *end != '\0') {
- return PK_STN_ERR_INCONVERTIBLE;
+ return PK_STN_RES_INCONVERTIBLE;
}
*i = l;
- return PK_STN_ERR_SUCCESS;
+ return PK_STN_RES_SUCCESS;
}
-enum PK_STN_ERR
+enum PK_STN_RES
pk_stn_uint16_t(uint16_t *i, char const *s, int base)
{
char *end;
@@ -139,19 +139,19 @@ pk_stn_uint16_t(uint16_t *i, char const *s, int base)
errno = 0;
l = strtoul(s, &end, base);
if (errno == ERANGE && l == LONG_MAX) {
- return PK_STN_ERR_OVERFLOW;
+ return PK_STN_RES_OVERFLOW;
}
if (errno == ERANGE && l == LONG_MIN) {
- return PK_STN_ERR_UNDERFLOW;
+ return PK_STN_RES_UNDERFLOW;
}
if (*s == '\0' || *end != '\0') {
- return PK_STN_ERR_INCONVERTIBLE;
+ return PK_STN_RES_INCONVERTIBLE;
}
*i = l;
- return PK_STN_ERR_SUCCESS;
+ return PK_STN_RES_SUCCESS;
}
-enum PK_STN_ERR
+enum PK_STN_RES
pk_stn_int8_t(int8_t *i, char const *s, int base)
{
char *end;
@@ -159,19 +159,19 @@ pk_stn_int8_t(int8_t *i, char const *s, int base)
errno = 0;
l = strtol(s, &end, base);
if (errno == ERANGE && l == LONG_MAX) {
- return PK_STN_ERR_OVERFLOW;
+ return PK_STN_RES_OVERFLOW;
}
if (errno == ERANGE && l == LONG_MIN) {
- return PK_STN_ERR_UNDERFLOW;
+ return PK_STN_RES_UNDERFLOW;
}
if (*s == '\0' || *end != '\0') {
- return PK_STN_ERR_INCONVERTIBLE;
+ return PK_STN_RES_INCONVERTIBLE;
}
*i = l;
- return PK_STN_ERR_SUCCESS;
+ return PK_STN_RES_SUCCESS;
}
-enum PK_STN_ERR
+enum PK_STN_RES
pk_stn_uint8_t(uint8_t *i, char const *s, int base)
{
char *end;
@@ -179,68 +179,68 @@ pk_stn_uint8_t(uint8_t *i, char const *s, int base)
errno = 0;
l = strtoul(s, &end, base);
if (errno == ERANGE && l == LONG_MAX) {
- return PK_STN_ERR_OVERFLOW;
+ return PK_STN_RES_OVERFLOW;
}
if (errno == ERANGE && l == LONG_MIN) {
- return PK_STN_ERR_UNDERFLOW;
+ return PK_STN_RES_UNDERFLOW;
}
if (*s == '\0' || *end != '\0') {
- return PK_STN_ERR_INCONVERTIBLE;
+ return PK_STN_RES_INCONVERTIBLE;
}
*i = l;
- return PK_STN_ERR_SUCCESS;
+ return PK_STN_RES_SUCCESS;
}
-enum PK_STN_ERR
+enum PK_STN_RES
pk_stn_float(float *f, char const *s)
{
char *end;
return pk_stn_float_e(f, s, &end);
}
-enum PK_STN_ERR
+enum PK_STN_RES
pk_stn_double(double *d, char const *s)
{
char *end;
return pk_stn_double_e(d, s, &end);
}
-enum PK_STN_ERR
+enum PK_STN_RES
pk_stn_float_e(float *f, char const *s, char **pEnd)
{
float l;
errno = 0;
l = strtof(s, pEnd);
if (errno == ERANGE && l == HUGE_VALF) {
- return PK_STN_ERR_OVERFLOW;
+ return PK_STN_RES_OVERFLOW;
}
if (errno == ERANGE && l == -HUGE_VALF) {
- return PK_STN_ERR_UNDERFLOW;
+ return PK_STN_RES_UNDERFLOW;
}
if (*s == '\0' || &s == (const char **)pEnd) {
- return PK_STN_ERR_INCONVERTIBLE;
+ return PK_STN_RES_INCONVERTIBLE;
}
*f = l;
- return PK_STN_ERR_SUCCESS;
+ return PK_STN_RES_SUCCESS;
}
-enum PK_STN_ERR
+enum PK_STN_RES
pk_stn_double_e(double *d, char const *s, char **pEnd)
{
double l;
errno = 0;
l = strtod(s, pEnd);
if (errno == ERANGE && l == HUGE_VAL) {
- return PK_STN_ERR_OVERFLOW;
+ return PK_STN_RES_OVERFLOW;
}
if (errno == ERANGE && l == -HUGE_VAL) {
- return PK_STN_ERR_UNDERFLOW;
+ return PK_STN_RES_UNDERFLOW;
}
if (*s == '\0' || &s == (const char **)pEnd) {
- return PK_STN_ERR_INCONVERTIBLE;
+ return PK_STN_RES_INCONVERTIBLE;
}
*d = l;
- return PK_STN_ERR_SUCCESS;
+ return PK_STN_RES_SUCCESS;
}
#endif /* PK_IMPL_STN */
diff --git a/test/pkstn.c b/test/pkstn.c
index 97ec8a9..8884804 100644
--- a/test/pkstn.c
+++ b/test/pkstn.c
@@ -8,14 +8,14 @@ int main(int argc, char *argv[])
{
(void)argc;
(void)argv;
- enum PK_STN_ERR res = {0};
+ enum PK_STN_RES res = {0};
// stn_int64_t
{
int64_t i = {0};
res = pk_stn_int64_t(&i, "-1", 0);
fprintf(stdout, "pkstn: stn_int64_t res: %ld\n", i);
- if (res != PK_STN_ERR_SUCCESS) exit(1);
+ if (res != PK_STN_RES_SUCCESS) exit(1);
if (-1 != i) exit(1);
}
@@ -24,7 +24,7 @@ int main(int argc, char *argv[])
uint64_t i = {0};
res = pk_stn_uint64_t(&i, "1", 0);
fprintf(stdout, "pkstn: stn_uint64_t res: %lu\n", i);
- if (res != PK_STN_ERR_SUCCESS) exit(1);
+ if (res != PK_STN_RES_SUCCESS) exit(1);
if (1 != i) exit(1);
}
@@ -33,7 +33,7 @@ int main(int argc, char *argv[])
int32_t i = {0};
res = pk_stn_int32_t(&i, "-1", 0);
fprintf(stdout, "pkstn: stn_int32_t res: %d\n", i);
- if (res != PK_STN_ERR_SUCCESS) exit(1);
+ if (res != PK_STN_RES_SUCCESS) exit(1);
if (-1 != i) exit(1);
}
@@ -42,7 +42,7 @@ int main(int argc, char *argv[])
uint32_t i = {0};
res = pk_stn_uint32_t(&i, "1", 0);
fprintf(stdout, "pkstn: stn_uint32_t res: %u\n", i);
- if (res != PK_STN_ERR_SUCCESS) exit(1);
+ if (res != PK_STN_RES_SUCCESS) exit(1);
if (1 != i) exit(1);
}
@@ -51,7 +51,7 @@ int main(int argc, char *argv[])
int16_t i = {0};
res = pk_stn_int16_t(&i, "-1", 0);
fprintf(stdout, "pkstn: stn_int16_t res: %d\n", i);
- if (res != PK_STN_ERR_SUCCESS) exit(1);
+ if (res != PK_STN_RES_SUCCESS) exit(1);
if (-1 != i) exit(1);
}
@@ -60,7 +60,7 @@ int main(int argc, char *argv[])
uint16_t i = {0};
res = pk_stn_uint16_t(&i, "1", 0);
fprintf(stdout, "pkstn: stn_uint16_t res: %u\n", i);
- if (res != PK_STN_ERR_SUCCESS) exit(1);
+ if (res != PK_STN_RES_SUCCESS) exit(1);
if (1 != i) exit(1);
}
@@ -69,7 +69,7 @@ int main(int argc, char *argv[])
int8_t i = {0};
res = pk_stn_int8_t(&i, "-1", 0);
fprintf(stdout, "pkstn: stn_int8_t res: %d\n", i);
- if (res != PK_STN_ERR_SUCCESS) exit(1);
+ if (res != PK_STN_RES_SUCCESS) exit(1);
if (-1 != i) exit(1);
}
@@ -78,7 +78,7 @@ int main(int argc, char *argv[])
uint8_t i = {0};
res = pk_stn_uint8_t(&i, "1", 0);
fprintf(stdout, "pkstn: stn_uint8_t res: %u\n", i);
- if (res != PK_STN_ERR_SUCCESS) exit(1);
+ if (res != PK_STN_RES_SUCCESS) exit(1);
if (1 != i) exit(1);
}
@@ -87,7 +87,7 @@ int main(int argc, char *argv[])
float f = {0};
res = pk_stn_float(&f, "-1");
fprintf(stdout, "pkstn: stn_float res: %f\n", f);
- if (res != PK_STN_ERR_SUCCESS) exit(1);
+ if (res != PK_STN_RES_SUCCESS) exit(1);
if (-1 != f) exit(1);
}
@@ -96,7 +96,7 @@ int main(int argc, char *argv[])
double f = {0};
res = pk_stn_double(&f, "-1");
fprintf(stdout, "pkstn: stn_double res: %f\n", f);
- if (res != PK_STN_ERR_SUCCESS) exit(1);
+ if (res != PK_STN_RES_SUCCESS) exit(1);
if (-1 != f) exit(1);
}
diff --git a/test/pkstn.cpp b/test/pkstn.cpp
index 261fb56..920c6ac 100644
--- a/test/pkstn.cpp
+++ b/test/pkstn.cpp
@@ -8,14 +8,14 @@ int main(int argc, char *argv[])
{
(void)argc;
(void)argv;
- enum PK_STN_ERR res = {};
+ enum PK_STN_RES res = {};
// stn_int64_t
{
int64_t i = {0};
res = pk_stn_int64_t(&i, "-1", 0);
fprintf(stdout, "pkstn: stn_int64_t res: %ld\n", i);
- if (res != PK_STN_ERR_SUCCESS) exit(1);
+ if (res != PK_STN_RES_SUCCESS) exit(1);
if (-1 != i) exit(1);
}
@@ -24,7 +24,7 @@ int main(int argc, char *argv[])
uint64_t i = {0};
res = pk_stn_uint64_t(&i, "1", 0);
fprintf(stdout, "pkstn: stn_uint64_t res: %lu\n", i);
- if (res != PK_STN_ERR_SUCCESS) exit(1);
+ if (res != PK_STN_RES_SUCCESS) exit(1);
if (1 != i) exit(1);
}
@@ -33,7 +33,7 @@ int main(int argc, char *argv[])
int32_t i = {0};
res = pk_stn_int32_t(&i, "-1", 0);
fprintf(stdout, "pkstn: stn_int32_t res: %d\n", i);
- if (res != PK_STN_ERR_SUCCESS) exit(1);
+ if (res != PK_STN_RES_SUCCESS) exit(1);
if (-1 != i) exit(1);
}
@@ -42,7 +42,7 @@ int main(int argc, char *argv[])
uint32_t i = {0};
res = pk_stn_uint32_t(&i, "1", 0);
fprintf(stdout, "pkstn: stn_uint32_t res: %u\n", i);
- if (res != PK_STN_ERR_SUCCESS) exit(1);
+ if (res != PK_STN_RES_SUCCESS) exit(1);
if (1 != i) exit(1);
}
@@ -51,7 +51,7 @@ int main(int argc, char *argv[])
int16_t i = {0};
res = pk_stn_int16_t(&i, "-1", 0);
fprintf(stdout, "pkstn: stn_int16_t res: %d\n", i);
- if (res != PK_STN_ERR_SUCCESS) exit(1);
+ if (res != PK_STN_RES_SUCCESS) exit(1);
if (-1 != i) exit(1);
}
@@ -60,7 +60,7 @@ int main(int argc, char *argv[])
uint16_t i = {0};
res = pk_stn_uint16_t(&i, "1", 0);
fprintf(stdout, "pkstn: stn_uint16_t res: %u\n", i);
- if (res != PK_STN_ERR_SUCCESS) exit(1);
+ if (res != PK_STN_RES_SUCCESS) exit(1);
if (1 != i) exit(1);
}
@@ -69,7 +69,7 @@ int main(int argc, char *argv[])
int8_t i = {0};
res = pk_stn_int8_t(&i, "-1", 0);
fprintf(stdout, "pkstn: stn_int8_t res: %d\n", i);
- if (res != PK_STN_ERR_SUCCESS) exit(1);
+ if (res != PK_STN_RES_SUCCESS) exit(1);
if (-1 != i) exit(1);
}
@@ -78,7 +78,7 @@ int main(int argc, char *argv[])
uint8_t i = {0};
res = pk_stn_uint8_t(&i, "1", 0);
fprintf(stdout, "pkstn: stn_uint8_t res: %u\n", i);
- if (res != PK_STN_ERR_SUCCESS) exit(1);
+ if (res != PK_STN_RES_SUCCESS) exit(1);
if (1 != i) exit(1);
}
@@ -87,7 +87,7 @@ int main(int argc, char *argv[])
float f = {0};
res = pk_stn_float(&f, "-1");
fprintf(stdout, "pkstn: stn_float res: %f\n", f);
- if (res != PK_STN_ERR_SUCCESS) exit(1);
+ if (res != PK_STN_RES_SUCCESS) exit(1);
if (-1 != f) exit(1);
}
@@ -96,7 +96,7 @@ int main(int argc, char *argv[])
double f = {0};
res = pk_stn_double(&f, "-1");
fprintf(stdout, "pkstn: stn_double res: %f\n", f);
- if (res != PK_STN_ERR_SUCCESS) exit(1);
+ if (res != PK_STN_RES_SUCCESS) exit(1);
if (-1 != f) exit(1);
}