mirror of
https://github.com/MariaDB/server.git
synced 2025-01-22 23:04:20 +01:00
e215a35f09
Ouputs without transactions, does not dump a header. git-svn-id: file:///svn/tokudb@441 c7de825b-a66e-492c-adef-691d508d4ae1
79 lines
4.1 KiB
C
Executable file
79 lines
4.1 KiB
C
Executable file
#if !defined(TOKUDB_COMMON_FUNCS_H)
|
|
|
|
#define TOKUDB_COMMON_FUNCS_H
|
|
#include "tokudb_common.h"
|
|
int strtoint32 (DB_ENV* dbenv, char* progname, char* str, int32_t* num, int32_t min, int32_t max, int base);
|
|
int strtouint32 (DB_ENV* dbenv, char* progname, char* str, uint32_t* num, uint32_t min, uint32_t max, int base);
|
|
int strtoint64 (DB_ENV* dbenv, char* progname, char* str, int64_t* num, int64_t min, int64_t max, int base);
|
|
int strtouint64 (DB_ENV* dbenv, char* progname, char* str, uint64_t* num, uint64_t min, uint64_t max, int base);
|
|
|
|
/*
|
|
* Convert a string to an integer of type "type".
|
|
*
|
|
*
|
|
* Sets errno and returns:
|
|
* EINVAL: str == NULL, num == NULL, or string not of the form [ \t]*[+-]?[0-9]+
|
|
* ERANGE: value out of range specified. (Range of [min, max])
|
|
*
|
|
* *num is unchanged on error.
|
|
* Returns:
|
|
*
|
|
*/
|
|
#define DEF_STR_TO(name, type, bigtype, strtofunc, frmt) \
|
|
int name(DB_ENV* dbenv, char* progname, char* str, type* num, type min, type max, int base) \
|
|
{ \
|
|
char* test; \
|
|
bigtype value; \
|
|
\
|
|
assert(str); \
|
|
assert(num); \
|
|
assert(min <= max); \
|
|
assert(dbenv || progname); \
|
|
assert(base == 0 || (base >= 2 && base <= 36)); \
|
|
\
|
|
errno = 0; \
|
|
while (isspace(*str)) str++; \
|
|
value = strtofunc(str, &test, base); \
|
|
if ((*test != '\0' && *test != '\n') || test == str) { \
|
|
if (dbenv == NULL) fprintf(stderr, "%s: %s: Invalid numeric argument\n", progname, str); \
|
|
else dbenv->err(dbenv, 0, "%s: Invalid numeric argument", str); \
|
|
errno = EINVAL; \
|
|
goto error; \
|
|
} \
|
|
if (errno != 0) { \
|
|
if (dbenv == NULL) fprintf(stderr, "%s: %s: %s\n", progname, str, strerror(errno)); \
|
|
else dbenv->err(dbenv, errno, "%s", str); \
|
|
goto error; \
|
|
} \
|
|
if (value < min) { \
|
|
if (dbenv == NULL) fprintf(stderr, "%s: %s: Less than minimum value (%" frmt ")\n", progname, str, min); \
|
|
else dbenv->err(dbenv, 0, "%s: Less than minimum value (%" frmt ")", str, min); \
|
|
goto error; \
|
|
} \
|
|
if (value > max) { \
|
|
if (dbenv == NULL) fprintf(stderr, "%s: %s: Greater than maximum value (%" frmt ")\n", progname, str, max); \
|
|
else dbenv->err(dbenv, 0, "%s: Greater than maximum value (%" frmt ")", str, max); \
|
|
goto error; \
|
|
} \
|
|
*num = value; \
|
|
return EXIT_SUCCESS; \
|
|
error: \
|
|
return errno; \
|
|
}
|
|
|
|
DEF_STR_TO(strtoint32, int32_t, int64_t, strtoll, "d");
|
|
DEF_STR_TO(strtouint32, uint32_t, uint64_t, strtoull, "u");
|
|
DEF_STR_TO(strtoint64, int64_t, int64_t, strtoll, "lld");
|
|
DEF_STR_TO(strtouint64, uint64_t, uint64_t, strtoull, "llu");
|
|
|
|
void outputbyte(uint8_t ch)
|
|
{
|
|
if (g.plaintext) {
|
|
if (ch == '\\') printf("\\\\");
|
|
else if (isprint(ch)) printf("%c", ch);
|
|
else printf("\\%02x", ch);
|
|
}
|
|
else printf("%02x", ch);
|
|
}
|
|
|
|
#endif /* #if !defined(TOKUDB_COMMON_H) */
|