LCOV - code coverage report
Current view: top level - libpkg - pkg_attributes.c (source / functions) Hit Total Coverage
Test: cov.info Lines: 71 101 70.3 %
Date: 2015-08-15 Functions: 15 19 78.9 %

          Line data    Source code
       1             : /*-
       2             :  * Copyright (c) 2011-2013 Baptiste Daroussin <bapt@FreeBSD.org>
       3             :  * Copyright (c) 2011-2012 Julien Laffaye <jlaffaye@FreeBSD.org>
       4             :  * Copyright (c) 2013 Matthew Seaman <matthew@FreeBSD.org>
       5             :  * All rights reserved.
       6             :  * 
       7             :  * Redistribution and use in source and binary forms, with or without
       8             :  * modification, are permitted provided that the following conditions
       9             :  * are met:
      10             :  * 1. Redistributions of source code must retain the above copyright
      11             :  *    notice, this list of conditions and the following disclaimer
      12             :  *    in this position and unchanged.
      13             :  * 2. Redistributions in binary form must reproduce the above copyright
      14             :  *    notice, this list of conditions and the following disclaimer in the
      15             :  *    documentation and/or other materials provided with the distribution.
      16             :  * 
      17             :  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
      18             :  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
      19             :  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
      20             :  * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
      21             :  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
      22             :  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
      23             :  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
      24             :  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
      25             :  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
      26             :  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      27             :  */
      28             : 
      29             : #include <assert.h>
      30             : 
      31             : #include "pkg.h"
      32             : #include "private/event.h"
      33             : #include "private/pkg.h"
      34             : 
      35             : /*
      36             :  * Dep
      37             :  */
      38             : int
      39         197 : pkg_dep_new(struct pkg_dep **d)
      40             : {
      41         197 :         if ((*d = calloc(1, sizeof(struct pkg_dep))) == NULL)
      42           0 :                 return (EPKG_FATAL);
      43             : 
      44         197 :         return (EPKG_OK);
      45             : }
      46             : 
      47             : void
      48         129 : pkg_dep_free(struct pkg_dep *d)
      49             : {
      50         129 :         if (d == NULL)
      51         129 :                 return;
      52             : 
      53         129 :         free(d->origin);
      54         129 :         free(d->name);
      55         129 :         free(d->version);
      56         129 :         free(d->uid);
      57         129 :         free(d);
      58             : }
      59             : 
      60             : const char *
      61           4 : pkg_dep_get(struct pkg_dep const * const d, const pkg_dep_attr attr)
      62             : {
      63           4 :         assert(d != NULL);
      64             : 
      65           4 :         switch (attr) {
      66             :         case PKG_DEP_NAME:
      67           4 :                 return (d->name);
      68             :                 break;
      69             :         case PKG_DEP_ORIGIN:
      70           0 :                 return (d->origin);
      71             :                 break;
      72             :         case PKG_DEP_VERSION:
      73           0 :                 return (d->version);
      74             :                 break;
      75             :         default:
      76           0 :                 return (NULL);
      77             :                 break;
      78             :         }
      79             : }
      80             : 
      81             : bool
      82           0 : pkg_dep_is_locked(struct pkg_dep const * const d)
      83             : {
      84           0 :         assert(d != NULL);
      85             : 
      86           0 :         return d->locked;
      87             : }
      88             : 
      89             : /*
      90             :  * File
      91             :  */
      92             : 
      93             : int
      94         199 : pkg_file_new(struct pkg_file **file)
      95             : {
      96         199 :         if ((*file = calloc(1, sizeof(struct pkg_file))) == NULL)
      97           0 :                 return (EPKG_FATAL);
      98             : 
      99         199 :         (*file)->perm = 0;
     100         199 :         (*file)->fflags = 0;
     101             : 
     102         199 :         return (EPKG_OK);
     103             : }
     104             : 
     105             : void
     106         151 : pkg_file_free(struct pkg_file *file)
     107             : {
     108         151 :         free(file->sum);
     109         151 :         free(file);
     110         151 : }
     111             : 
     112             : /*
     113             :  * Dir
     114             :  */
     115             : 
     116             : int
     117          18 : pkg_dir_new(struct pkg_dir **d)
     118             : {
     119          18 :         if ((*d = calloc(1, sizeof(struct pkg_dir))) == NULL)
     120           0 :                 return (EPKG_FATAL);
     121             : 
     122          18 :         (*d)->perm = 0;
     123          18 :         (*d)->fflags = 0;
     124             : 
     125          18 :         return (EPKG_OK);
     126             : }
     127             : 
     128             : void
     129          10 : pkg_dir_free(struct pkg_dir *d)
     130             : {
     131          10 :         free(d);
     132          10 : }
     133             : 
     134             : /*
     135             :  * Script
     136             :  */
     137             : 
     138             : const char *
     139        1586 : pkg_script_get(struct pkg const * const p, pkg_script i)
     140             : {
     141        1586 :         if (p->scripts[i] == NULL)
     142        1486 :                 return (NULL);
     143             : 
     144         100 :         if (sbuf_done(p->scripts[i]) == 0)
     145           0 :                 sbuf_finish(p->scripts[i]);
     146             : 
     147         100 :         return (sbuf_data(p->scripts[i]));
     148             : }
     149             : 
     150             : /*
     151             :  * Option
     152             :  */
     153             : 
     154             : int
     155          66 : pkg_option_new(struct pkg_option **option)
     156             : {
     157          66 :         if ((*option = calloc(1, sizeof(struct pkg_option))) == NULL) {
     158           0 :                 pkg_emit_errno("calloc", "pkg_option");
     159           0 :                 return (EPKG_FATAL);
     160             :         }
     161          66 :         return (EPKG_OK);
     162             : }
     163             : 
     164             : void
     165          54 : pkg_option_free(struct pkg_option *option)
     166             : {
     167          54 :         if (option == NULL)
     168          54 :                 return;
     169             : 
     170          54 :         free(option->key);
     171          54 :         free(option->value);
     172          54 :         free(option->default_value);
     173          54 :         free(option->description);
     174          54 :         free(option);
     175             : }
     176             : 
     177             : /*
     178             :  * Conflicts
     179             :  */
     180             : 
     181             : int
     182           8 : pkg_conflict_new(struct pkg_conflict **c)
     183             : {
     184           8 :         if ((*c = calloc(1, sizeof(struct pkg_conflict))) == NULL)
     185           0 :                 return (EPKG_FATAL);
     186             : 
     187           8 :         return (EPKG_OK);
     188             : }
     189             : 
     190             : void
     191           0 : pkg_conflict_free(struct pkg_conflict *c)
     192             : {
     193           0 :         if (c == NULL)
     194           0 :                 return;
     195             : 
     196           0 :         free(c->uid);
     197           0 :         free(c->digest);
     198           0 :         free(c);
     199             : }
     200             : 
     201             : /*
     202             :  * Config files
     203             :  */
     204             : int
     205           0 : pkg_config_file_new(struct pkg_config_file **c)
     206             : {
     207           0 :         if ((*c = calloc(1, sizeof(struct pkg_config_file))) == NULL)
     208           0 :                 return (EPKG_FATAL);
     209             : 
     210           0 :         return (EPKG_OK);
     211             : }
     212             : 
     213             : void
     214           0 : pkg_config_file_free(struct pkg_config_file *c)
     215             : {
     216           0 :         if (c == NULL)
     217           0 :                 return;
     218             : 
     219           0 :         free(c->content);
     220           0 :         free(c);
     221             : }
     222             : 
     223             : /*
     224             :  * strel
     225             :  */
     226             : 
     227             : int
     228         182 : pkg_strel_new(struct pkg_strel **c, const char *val)
     229             : {
     230         182 :         if ((*c = calloc(1, sizeof(struct pkg_strel))) == NULL)
     231           0 :                 return (EPKG_FATAL);
     232             : 
     233         182 :         (*c)->value = strdup(val);
     234             : 
     235         182 :         return (EPKG_OK);
     236             : }
     237             : 
     238             : void
     239          91 : pkg_strel_free(struct pkg_strel *c)
     240             : {
     241          91 :         if (c == NULL)
     242          91 :                 return;
     243             : 
     244          91 :         free(c->value);
     245          91 :         free(c);
     246             : }
     247             : 
     248             : /*
     249             :  * kv
     250             :  */
     251             : 
     252             : int
     253          77 : pkg_kv_new(struct pkg_kv **c, const char *key, const char *val)
     254             : {
     255          77 :         if ((*c = calloc(1, sizeof(struct pkg_kv))) == NULL)
     256           0 :                 return (EPKG_FATAL);
     257             : 
     258          77 :         (*c)->key = strdup(key);
     259          77 :         (*c)->value = strdup(val);
     260             : 
     261          77 :         return (EPKG_OK);
     262             : }
     263             : 
     264             : void
     265          75 : pkg_kv_free(struct pkg_kv *c)
     266             : {
     267          75 :         if (c == NULL)
     268          75 :                 return;
     269             : 
     270          75 :         free(c->key);
     271          75 :         free(c->value);
     272          75 :         free(c);
     273             : }

Generated by: LCOV version 1.10