56 lines
1.7 KiB
Diff
56 lines
1.7 KiB
Diff
From 11b85805955557ae87494fff57ead04be6ab90b6 Mon Sep 17 00:00:00 2001
|
|
From: David Lutterkort <lutter@redhat.com>
|
|
Date: Tue, 29 Jun 2010 15:43:07 -0700
|
|
Subject: [PATCH 6/9] Add xstrtoint64 to internal.[ch]
|
|
|
|
The implementation is directly from libvirt
|
|
|
|
* src/internal.h (xstrtoint64): add prototype
|
|
* src/internal.c (xstrtoint64): add impl
|
|
---
|
|
src/internal.c | 13 +++++++++++++
|
|
src/internal.h | 3 +++
|
|
2 files changed, 16 insertions(+), 0 deletions(-)
|
|
|
|
diff --git a/src/internal.c b/src/internal.c
|
|
index befd3af..8419ca2 100644
|
|
--- a/src/internal.c
|
|
+++ b/src/internal.c
|
|
@@ -392,6 +392,19 @@ int xasprintf(char **strp, const char *format, ...) {
|
|
return result;
|
|
}
|
|
|
|
+/* From libvirt's src/xen/block_stats.c */
|
|
+int xstrtoint64(char const *s, int base, int64_t *result) {
|
|
+ long long int lli;
|
|
+ char *p;
|
|
+
|
|
+ errno = 0;
|
|
+ lli = strtoll(s, &p, base);
|
|
+ if (errno || !(*p == 0 || *p == '\n') || p == s || (int64_t) lli != lli)
|
|
+ return -1;
|
|
+ *result = lli;
|
|
+ return 0;
|
|
+}
|
|
+
|
|
void calc_line_ofs(const char *text, size_t pos, size_t *line, size_t *ofs) {
|
|
*line = 1;
|
|
*ofs = 0;
|
|
diff --git a/src/internal.h b/src/internal.h
|
|
index b2a402f..51aa025 100644
|
|
--- a/src/internal.h
|
|
+++ b/src/internal.h
|
|
@@ -272,6 +272,9 @@ const char *xstrerror(int errnum, char *buf, size_t len);
|
|
/* Like asprintf, but set *STRP to NULL on error */
|
|
int xasprintf(char **strp, const char *format, ...);
|
|
|
|
+/* Convert S to RESULT with error checking */
|
|
+int xstrtoint64(char const *s, int base, int64_t *result);
|
|
+
|
|
/* Calculate line and column number of character POS in TEXT */
|
|
void calc_line_ofs(const char *text, size_t pos, size_t *line, size_t *ofs);
|
|
|
|
--
|
|
1.6.6.1
|
|
|