[BACK]Return to xstd.c CVS log [TXT][DIR] Up to [cvsweb.bsd.lv] / mandoc

Diff for /mandoc/Attic/xstd.c between version 1.1 and 1.11

version 1.1, 2008/12/23 05:30:49 version 1.11, 2009/03/16 23:37:28
Line 1 
Line 1 
 /* $Id$ */  /* $Id$ */
 /*  /*
  * Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>   * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@openbsd.org>
  *   *
  * Permission to use, copy, modify, and distribute this software for any   * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the   * purpose with or without fee is hereby granted, provided that the
Line 16 
Line 16 
  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR   * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  * PERFORMANCE OF THIS SOFTWARE.   * PERFORMANCE OF THIS SOFTWARE.
  */   */
   #include <assert.h>
 #include <err.h>  #include <err.h>
 #include <stdlib.h>  #include <stdlib.h>
 #include <string.h>  #include <string.h>
   
 #include "private.h"  #include "private.h"
   
   /*
    * Contains wrappers for common functions to simplify their general
    * usage throughout this codebase.
    */
   
 int  int
 xstrcmp(const char *p1, const char *p2)  xstrcmp(const char *p1, const char *p2)
Line 30  xstrcmp(const char *p1, const char *p2)
Line 35  xstrcmp(const char *p1, const char *p2)
         return(0 == strcmp(p1, p2));          return(0 == strcmp(p1, p2));
 }  }
   
   
 int  int
 xstrlcat(char *dst, const char *src, size_t sz)  xstrlcat(char *dst, const char *src, size_t sz)
 {  {
Line 38  xstrlcat(char *dst, const char *src, size_t sz)
Line 42  xstrlcat(char *dst, const char *src, size_t sz)
         return(strlcat(dst, src, sz) < sz);          return(strlcat(dst, src, sz) < sz);
 }  }
   
   
 int  int
 xstrlcpy(char *dst, const char *src, size_t sz)  xstrlcpy(char *dst, const char *src, size_t sz)
 {  {
Line 46  xstrlcpy(char *dst, const char *src, size_t sz)
Line 49  xstrlcpy(char *dst, const char *src, size_t sz)
         return(strlcpy(dst, src, sz) < sz);          return(strlcpy(dst, src, sz) < sz);
 }  }
   
   void *
   xrealloc(void *ptr, size_t sz)
   {
           void            *p;
   
           if (NULL == (p = realloc(ptr, sz)))
                   err(EXIT_FAILURE, "realloc");
           return(p);
   }
   
 void *  void *
 xcalloc(size_t num, size_t sz)  xcalloc(size_t num, size_t sz)
Line 58  xcalloc(size_t num, size_t sz)
Line 69  xcalloc(size_t num, size_t sz)
         return(p);          return(p);
 }  }
   
   
 char *  char *
 xstrdup(const char *p)  xstrdup(const char *p)
 {  {
Line 69  xstrdup(const char *p)
Line 79  xstrdup(const char *p)
         return(pp);          return(pp);
 }  }
   
   int
   xstrlcpys(char *buf, const struct mdoc_node *n, size_t sz)
   {
           char             *p;
   
           assert(sz > 0);
           assert(buf);
           *buf = 0;
   
           for ( ; n; n = n->next) {
                   assert(MDOC_TEXT == n->type);
                   p = n->string;
                   if ( ! xstrlcat(buf, p, sz))
                           return(0);
                   if (n->next && ! xstrlcat(buf, " ", sz))
                           return(0);
           }
   
           return(1);
   }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.11

CVSweb