Main Page | Data Structures | File List | Data Fields | Globals

libipg_init.c

Go to the documentation of this file.
00001 /*
00002  *  $Id: libipg_init.c,v 1.1.1.1 2003/12/28 18:45:43 mike Exp $
00003  *
00004  *  libipg
00005  *  libipg_init.c - initilization routines
00006  *
00007  *  Copyright (c) 2003 - 2004 Mike D. Schiffman <mike@infonexus.com>
00008  *  All rights reserved.
00009  *
00010  * Redistribution and use in source and binary forms, with or without
00011  * modification, are permitted provided that the following conditions
00012  * are met:
00013  * 1. Redistributions of source code must retain the above copyright
00014  *    notice, this list of conditions and the following disclaimer.
00015  * 2. Redistributions in binary form must reproduce the above copyright
00016  *    notice, this list of conditions and the following disclaimer in the
00017  *    documentation and/or other materials provided with the distribution.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
00020  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00021  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00022  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
00023  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00024  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00025  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00026  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00027  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00028  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00029  * SUCH DAMAGE.
00030  *
00031  */
00032 
00042 #if (HAVE_CONFIG_H)
00043 #include "../include/config.h"
00044 #endif
00045 
00046 #include "./libipg.h"
00047 
00048 ipgeo_t *
00049 ipgeo_init(char *file, u_int8_t flags, char *err_buf)
00050 {
00051     ipgeo_t *ipg = NULL;
00052 
00053     ipg = (ipgeo_t *)malloc(sizeof (ipgeo_t));
00054     if (ipg == NULL)
00055     {
00056         snprintf(err_buf, IPGEO_ERRBUF_SIZE, "malloc(): %s\n", strerror(errno));
00057         goto bad;
00058     }
00059 
00060     memset(ipg, 0, sizeof (ipg));
00061 
00062     ipg->db = fopen(file, "r");
00063     if (ipg->db == NULL)
00064     {
00065         snprintf(err_buf, IPGEO_ERRBUF_SIZE, "fopen() (%s): %s\n", file, 
00066                 strerror(errno));
00067         goto bad;
00068     }
00069 
00071     ipg->dbt = 6;
00072 
00074     ipg->flags = flags;
00075 
00076     return (ipg);
00077 
00078 bad:
00079     if (ipg)
00080     {
00081         if (ipg->db)
00082         {
00083             fclose(ipg->db);
00084         }
00085         free (ipg);
00086     }
00087     return (NULL);
00088 }
00089 
00090 void
00091 ipgeo_destroy(ipgeo_t *ipg)
00092 {
00093     if (ipg)
00094     {
00095         if (ipg->db)
00096         {
00097             fclose(ipg->db);
00098         }
00099         free (ipg);
00100     }
00101 }
00102 
00103 char *
00104 ipgeo_geterror(ipgeo_t *ipg)
00105 {
00106     return (ipg->err_buf);
00107 }
00108 
00109 int
00110 ipgeo_getdbt(ipgeo_t *ipg)
00111 {
00112     if (ipg == NULL || ipg->db == NULL)
00113     {
00114         return (-1);
00115     }
00116     return (ipg->dbt);
00117 }
00118 
00119 int
00120 ipgeo_getfd(ipgeo_t *ipg)
00121 {
00122     if (ipg == NULL || ipg->db == NULL)
00123     {
00124         return (-1);
00125     }
00126 
00131     return (fileno(ipg->db));
00132 }
00133 
00134 /* EOF */

Generated on Wed Dec 31 12:06:49 2003 for libipg by doxygen 1.3.4