summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorColin Cross2012-04-26 16:24:35 -0500
committerColin Cross2012-07-10 00:09:37 -0500
commita21930b6b0dbb04a52948566d58fb48c6db58bab (patch)
treee74cfb32ad232c3b99364cd0931502519ca72111 /libsparse
parent9e1f17e926fa20255c5f4b4d2f68aa98a964253a (diff)
downloadplatform-system-core-a21930b6b0dbb04a52948566d58fb48c6db58bab.tar.gz
platform-system-core-a21930b6b0dbb04a52948566d58fb48c6db58bab.tar.xz
platform-system-core-a21930b6b0dbb04a52948566d58fb48c6db58bab.zip
libsparse: add error reporting functions
Change-Id: I2f21355b6c5339d1d724b4c121ea30d575b2d366
Diffstat (limited to 'libsparse')
-rw-r--r--libsparse/Android.mk3
-rw-r--r--libsparse/include/sparse/sparse.h18
-rw-r--r--libsparse/sparse.c5
-rw-r--r--libsparse/sparse_err.c33
-rw-r--r--libsparse/sparse_file.h1
5 files changed, 59 insertions, 1 deletions
diff --git a/libsparse/Android.mk b/libsparse/Android.mk
index dbe4d1842..d3eeae651 100644
--- a/libsparse/Android.mk
+++ b/libsparse/Android.mk
@@ -6,7 +6,8 @@ libsparse_src_files := \
6 backed_block.c \ 6 backed_block.c \
7 output_file.c \ 7 output_file.c \
8 sparse.c \ 8 sparse.c \
9 sparse_crc32.c 9 sparse_crc32.c \
10 sparse_err.c
10 11
11include $(CLEAR_VARS) 12include $(CLEAR_VARS)
12 13
diff --git a/libsparse/include/sparse/sparse.h b/libsparse/include/sparse/sparse.h
index 6484333ef..09a513725 100644
--- a/libsparse/include/sparse/sparse.h
+++ b/libsparse/include/sparse/sparse.h
@@ -157,4 +157,22 @@ int sparse_file_add_fd(struct sparse_file *s,
157int sparse_file_write(struct sparse_file *s, int fd, bool gz, bool sparse, 157int sparse_file_write(struct sparse_file *s, int fd, bool gz, bool sparse,
158 bool crc); 158 bool crc);
159 159
160/**
161 * sparse_file_verbose - set a sparse file cookie to print verbose errors
162 *
163 * @s - sparse file cookie
164 *
165 * Print verbose sparse file errors whenever using the sparse file cookie.
166 */
167void sparse_file_verbose(struct sparse_file *s);
168
169/**
170 * sparse_print_verbose - function called to print verbose errors
171 *
172 * By default, verbose errors will print to standard error.
173 * sparse_print_verbose may be overridden to log verbose errors somewhere else.
174 *
175 */
176extern void (*sparse_print_verbose)(const char *fmt, ...);
177
160#endif 178#endif
diff --git a/libsparse/sparse.c b/libsparse/sparse.c
index 4ebcf0f8d..3403604d4 100644
--- a/libsparse/sparse.c
+++ b/libsparse/sparse.c
@@ -151,3 +151,8 @@ int sparse_file_write(struct sparse_file *s, int fd, bool gz, bool sparse,
151 151
152 return 0; 152 return 0;
153} 153}
154
155void sparse_file_verbose(struct sparse_file *s)
156{
157 s->verbose = true;
158}
diff --git a/libsparse/sparse_err.c b/libsparse/sparse_err.c
new file mode 100644
index 000000000..0f392ad60
--- /dev/null
+++ b/libsparse/sparse_err.c
@@ -0,0 +1,33 @@
1/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <sparse/sparse.h>
18
19#include <stdarg.h>
20#include <stdio.h>
21#include <unistd.h>
22
23void sparse_default_print(const char *fmt, ...)
24{
25 va_list argp;
26
27 va_start(argp, fmt);
28 vfprintf(stderr, fmt, argp);
29 va_end(argp);
30}
31
32void (*sparse_print_error)(const char *fmt, ...) = sparse_default_print;
33void (*sparse_print_verbose)(const char *fmt, ...) = sparse_default_print;
diff --git a/libsparse/sparse_file.h b/libsparse/sparse_file.h
index fae1c168c..91a12e678 100644
--- a/libsparse/sparse_file.h
+++ b/libsparse/sparse_file.h
@@ -22,6 +22,7 @@
22struct sparse_file { 22struct sparse_file {
23 unsigned int block_size; 23 unsigned int block_size;
24 int64_t len; 24 int64_t len;
25 bool verbose;
25 26
26 struct backed_block_list *backed_block_list; 27 struct backed_block_list *backed_block_list;
27 struct output_file *out; 28 struct output_file *out;