/*\ * libLB - The LBPP support library * Copyright (C) 2001 Anthony Liguori * * libLB is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * libLB is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA \*/ #include #include "lb.h" int lb_register_dev_cid(LBContext *cxt, char *name) { int i; for (i = 0; i < cxt->dev_class_size; i++) { if (!strcmp(name, cxt->dev_class[i].name)) { break; } } if (i == cxt->dev_class_size) { if (++(cxt->dev_class_size) > cxt->dev_class_capacity) { cxt->dev_class_capacity += 10; cxt->dev_class = (LBDeviceClass *) realloc(cxt->dev_class, cxt->dev_class_capacity*sizeof(LBDeviceClass)); } strcpy(cxt->dev_class[i].name, name); } return i; } int lb_get_dev_cid(LBContext *cxt, char *name) { int i; for (i = 0; i < cxt->dev_class_size; i++) { if (!strcmp(name, cxt->dev_class[i].name)) { return (i); } } return (-1); } LBDevice *lb_get_dev(LBContext *cxt, char *name) { int i; for (i = 0; i < cxt->devs_size; i++) { if (!strcasecmp(cxt->devs[i].name, name)) { return &(cxt->devs[i]); } } return 0; } LBDevice *lb_register_dev(LBContext *cxt, char *name, char *class) { int i; for (i = 0; i < cxt->devs_size; i++) { if (!strcasecmp(cxt->devs[i].name, name)) { break; } } if (i == cxt->devs_size) { if (++(cxt->devs_size) > cxt->devs_capacity) { cxt->devs_capacity += 10; cxt->devs = (LBDevice *)realloc(cxt->devs, cxt->devs_capacity*sizeof(LBDevice)); } strcpy(cxt->devs[i].name, name); cxt->devs[i].dev_type = LB_DEV_NONE; cxt->devs[i].cid = lb_register_dev_cid(cxt, class); cxt->devs[i].open = 0; cxt->devs[i].close = 0; cxt->devs[i].eof = 0; cxt->devs[i].lof = 0; cxt->devs[i].read_str = 0; cxt->devs[i].write_str = 0; cxt->devs[i].read_db = 0; cxt->devs[i].write_str = 0; cxt->devs[i].read_str_from = 0; cxt->devs[i].write_str_to = 0; cxt->devs[i].read_db_from = 0; cxt->devs[i].write_str_to = 0; } return &(cxt->devs[i]); }