Dieter Baron | 5149dfb | 2003-10-05 16:05:25 +0000 | [diff] [blame] | 1 | /* |
Dieter Baron | 1f3803c | 2005-06-09 19:57:10 +0000 | [diff] [blame] | 2 | $NiH: zip_error.c,v 1.6 2005/01/11 18:30:30 dillo Exp $ |
Dieter Baron | 5149dfb | 2003-10-05 16:05:25 +0000 | [diff] [blame] | 3 | |
| 4 | zip_error.c -- struct zip_error helper functions |
Dieter Baron | 1f3803c | 2005-06-09 19:57:10 +0000 | [diff] [blame] | 5 | Copyright (C) 1999, 2003, 2004, 2005 Dieter Baron and Thomas Klausner |
Dieter Baron | 5149dfb | 2003-10-05 16:05:25 +0000 | [diff] [blame] | 6 | |
| 7 | This file is part of libzip, a library to manipulate ZIP archives. |
| 8 | The authors can be contacted at <nih@giga.or.at> |
| 9 | |
| 10 | Redistribution and use in source and binary forms, with or without |
| 11 | modification, are permitted provided that the following conditions |
| 12 | are met: |
| 13 | 1. Redistributions of source code must retain the above copyright |
| 14 | notice, this list of conditions and the following disclaimer. |
| 15 | 2. Redistributions in binary form must reproduce the above copyright |
| 16 | notice, this list of conditions and the following disclaimer in |
| 17 | the documentation and/or other materials provided with the |
| 18 | distribution. |
| 19 | 3. The names of the authors may not be used to endorse or promote |
| 20 | products derived from this software without specific prior |
| 21 | written permission. |
| 22 | |
| 23 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS |
| 24 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 26 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY |
| 27 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 28 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
| 29 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 30 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER |
| 31 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 32 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 33 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 34 | */ |
| 35 | |
| 36 | |
| 37 | |
| 38 | #include <stdlib.h> |
| 39 | |
| 40 | #include "zip.h" |
| 41 | #include "zipint.h" |
| 42 | |
| 43 | |
| 44 | |
| 45 | void |
Dieter Baron | adaf98c | 2003-10-06 16:37:42 +0000 | [diff] [blame] | 46 | _zip_error_copy(struct zip_error *dst, struct zip_error *src) |
| 47 | { |
| 48 | dst->zip_err = src->zip_err; |
| 49 | dst->sys_err = src->sys_err; |
| 50 | } |
| 51 | |
| 52 | |
| 53 | |
| 54 | void |
Dieter Baron | 5149dfb | 2003-10-05 16:05:25 +0000 | [diff] [blame] | 55 | _zip_error_fini(struct zip_error *err) |
| 56 | { |
| 57 | free(err->str); |
| 58 | err->str = NULL; |
| 59 | } |
| 60 | |
| 61 | |
| 62 | |
Dieter Baron | e3f91ef | 2003-10-06 02:50:14 +0000 | [diff] [blame] | 63 | void |
| 64 | _zip_error_get(struct zip_error *err, int *zep, int *sep) |
| 65 | { |
| 66 | if (zep) |
| 67 | *zep = err->zip_err; |
Dieter Baron | a87f0e8 | 2005-01-11 18:30:30 +0000 | [diff] [blame] | 68 | if (sep) { |
| 69 | if (zip_error_get_sys_type(err->zip_err) != ZIP_ET_NONE) |
| 70 | *sep = err->sys_err; |
| 71 | else |
| 72 | *sep = 0; |
| 73 | } |
Dieter Baron | e3f91ef | 2003-10-06 02:50:14 +0000 | [diff] [blame] | 74 | } |
Dieter Baron | 5149dfb | 2003-10-05 16:05:25 +0000 | [diff] [blame] | 75 | |
Dieter Baron | e3f91ef | 2003-10-06 02:50:14 +0000 | [diff] [blame] | 76 | |
| 77 | |
| 78 | void |
| 79 | _zip_error_init(struct zip_error *err) |
Dieter Baron | 5149dfb | 2003-10-05 16:05:25 +0000 | [diff] [blame] | 80 | { |
| 81 | err->zip_err = 0; |
| 82 | err->sys_err = 0; |
| 83 | err->str = NULL; |
| 84 | } |
Dieter Baron | e3f91ef | 2003-10-06 02:50:14 +0000 | [diff] [blame] | 85 | |
| 86 | |
| 87 | |
| 88 | void |
| 89 | _zip_error_set(struct zip_error *err, int ze, int se) |
| 90 | { |
Dieter Baron | b2ed74d | 2004-04-14 14:01:31 +0000 | [diff] [blame] | 91 | if (err) { |
| 92 | err->zip_err = ze; |
| 93 | err->sys_err = se; |
| 94 | } |
Dieter Baron | e3f91ef | 2003-10-06 02:50:14 +0000 | [diff] [blame] | 95 | } |