|
Last change
on this file was 50549, checked in by martinl, 13 years ago |
|
vlib: free allocated string in error_handler_io()
|
-
Property svn:eol-style
set to
native
-
Property svn:mime-type
set to
text/x-csrc
|
|
File size:
1.6 KB
|
| Line | |
|---|
| 1 | /*!
|
|---|
| 2 | \file lib/vector/Vlib/handler.c
|
|---|
| 3 |
|
|---|
| 4 | \brief Vector library - standard error handlers
|
|---|
| 5 |
|
|---|
| 6 | Higher level functions for reading/writing/manipulating vectors.
|
|---|
| 7 |
|
|---|
| 8 | (C) 2011 by the GRASS Development Team
|
|---|
| 9 |
|
|---|
| 10 | This program is free software under the GNU General Public License
|
|---|
| 11 | (>=v2). Read the file COPYING that comes with GRASS for details.
|
|---|
| 12 |
|
|---|
| 13 | \author Martin Landa <landa.martin gmail.com>
|
|---|
| 14 | */
|
|---|
| 15 |
|
|---|
| 16 | #include <grass/gis.h>
|
|---|
| 17 | #include <grass/vector.h>
|
|---|
| 18 |
|
|---|
| 19 | struct handler_data_io {
|
|---|
| 20 | struct Map_info *In;
|
|---|
| 21 | struct Map_info *Out;
|
|---|
| 22 | };
|
|---|
| 23 |
|
|---|
| 24 | static struct handler_data_io *handler_io;
|
|---|
| 25 |
|
|---|
| 26 | static void error_handler_io(void *p)
|
|---|
| 27 | {
|
|---|
| 28 | char *name;
|
|---|
| 29 | struct Map_info *In, *Out;
|
|---|
| 30 |
|
|---|
| 31 | In = handler_io->In;
|
|---|
| 32 | Out = handler_io->Out;
|
|---|
| 33 |
|
|---|
| 34 | if (In && In->open == VECT_OPEN_CODE)
|
|---|
| 35 | Vect_close(In);
|
|---|
| 36 |
|
|---|
| 37 | if (Out && Out->open == VECT_OPEN_CODE) {
|
|---|
| 38 | name = G_store(Out->name);
|
|---|
| 39 | Vect_close(Out);
|
|---|
| 40 | Vect_delete(name);
|
|---|
| 41 | G_free(name);
|
|---|
| 42 | }
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 | /*!
|
|---|
| 46 | \brief Define standard error handler for input and output vector maps
|
|---|
| 47 |
|
|---|
| 48 | This handler:
|
|---|
| 49 | - close input vector map on error
|
|---|
| 50 | - close and delete output vector map on error
|
|---|
| 51 |
|
|---|
| 52 | Note: It's recommended to call this routine after Vect_open_old() or
|
|---|
| 53 | Vect_open_old2().
|
|---|
| 54 |
|
|---|
| 55 | \param In pointer in Map_info struct (input vector map) or NULL
|
|---|
| 56 | \param Out pointer to Map_info struct (output vector map) or NULL
|
|---|
| 57 | */
|
|---|
| 58 | void Vect_set_error_handler_io(struct Map_info *In, struct Map_info *Out)
|
|---|
| 59 | {
|
|---|
| 60 | if (!handler_io)
|
|---|
| 61 | handler_io = G_malloc(sizeof(struct handler_data_io));
|
|---|
| 62 |
|
|---|
| 63 | handler_io->In = In;
|
|---|
| 64 | handler_io->Out = Out;
|
|---|
| 65 |
|
|---|
| 66 | G_add_error_handler(error_handler_io, handler_io);
|
|---|
| 67 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.