X-Git-Url: http://git.tuebingen.mpg.de/?p=dss.git;a=blobdiff_plain;f=string.c;h=60c53d58d84ec0c2fd017b20b02b4c6cd636b801;hp=38fb1ee3f83a00b08b5a93af5260df4e092bc05f;hb=04bcb8e95d4afd843bcbb98cb01eb6c19a990446;hpb=301b9cccfc5de2489b70a46850933ff688ed9732 diff --git a/string.c b/string.c index 38fb1ee..60c53d5 100644 --- a/string.c +++ b/string.c @@ -1,5 +1,11 @@ +/* + * Copyright (C) 2004-2009 Andre Noll + * + * Licensed under the GPL v2. For licencing details see COPYING. + */ #include #include +#include #include #include #include @@ -9,14 +15,11 @@ #include -#include "cmdline.h" #include "gcc-compat.h" #include "log.h" #include "error.h" #include "string.h" -__noreturn void clean_exit(int status); - /** * Write a message to a dynamically allocated string. * @@ -71,7 +74,7 @@ __must_check __malloc void *dss_realloc(void *p, size_t size) if (!(p = realloc(p, size))) { DSS_EMERG_LOG("realloc failed (size = %zu), aborting\n", size); - clean_exit(EXIT_FAILURE); + exit(EXIT_FAILURE); } return p; } @@ -96,7 +99,7 @@ __must_check __malloc void *dss_malloc(size_t size) if (!p) { DSS_EMERG_LOG("malloc failed (size = %zu), aborting\n", size); - clean_exit(EXIT_FAILURE); + exit(EXIT_FAILURE); } return p; } @@ -142,7 +145,7 @@ __must_check __malloc char *dss_strdup(const char *s) if ((ret = strdup(s? s: ""))) return ret; DSS_EMERG_LOG("strdup failed, aborting\n"); - clean_exit(EXIT_FAILURE); + exit(EXIT_FAILURE); } /** @@ -166,12 +169,6 @@ __must_check __printf_1_2 __malloc char *make_message(const char *fmt, ...) return msg; } -__printf_1_2 void make_err_msg(const char* fmt,...) -{ - free(dss_error_txt); - VSPRINTF(fmt, dss_error_txt); -} - /** * Get the home directory of the current user. * @@ -201,22 +198,14 @@ int dss_atoi64(const char *str, int64_t *value) errno = 0; /* To distinguish success/failure after call */ tmp = strtoll(str, &endptr, 10); - if (errno == ERANGE && (tmp == LLONG_MAX || tmp == LLONG_MIN)) { - make_err_msg("%s", str); + if (errno == ERANGE && (tmp == LLONG_MAX || tmp == LLONG_MIN)) return -E_ATOI_OVERFLOW; - } - if (errno != 0 && tmp == 0) { /* other error */ - make_err_msg("%s", str); + if (errno != 0 && tmp == 0) /* other error */ return -E_STRTOLL; - } - if (endptr == str) { - make_err_msg("%s", str); + if (endptr == str) return -E_ATOI_NO_DIGITS; - } - if (*endptr != '\0') { /* Further characters after number */ - make_err_msg("%s", str); + if (*endptr != '\0') /* Further characters after number */ return -E_ATOI_JUNK_AT_END; - } *value = tmp; return 1; }