fltk 1.3.0rc3
About: FLTK (Fast Light Tool Kit) is a cross-platform C++ GUI toolkit for UNIX/Linux (X11), Microsoft Windows, and MacOS X. Release candidate.
  SfR Fresh Dox: fltk-1.3.0rc3-source.tar.gz ("inofficial" and yet experimental doxygen-generated source code documentation)  

flstring.c

Go to the documentation of this file.
00001 /*
00002  * "$Id: flstring.c 7903 2010-11-28 21:06:39Z matt $"
00003  *
00004  * BSD string functions for the Fast Light Tool Kit (FLTK).
00005  *
00006  * Copyright 1998-2010 by Bill Spitzak and others.
00007  *
00008  * This library is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Library General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2 of the License, or (at your option) any later version.
00012  *
00013  * This library is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * Library General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Library General Public
00019  * License along with this library; if not, write to the Free Software
00020  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00021  * USA.
00022  *
00023  * Please report all bugs and problems on the following page:
00024  *
00025  *     http://www.fltk.org/str.php
00026  */
00027 
00028 #include "flstring.h"
00029 
00030 
00031 /*
00032  * 'fl_strlcat()' - Safely concatenate two strings.
00033  */
00034 
00035 size_t                          /* O - Length of string */
00036 fl_strlcat(char       *dst,     /* O - Destination string */
00037            const char *src,     /* I - Source string */
00038            size_t     size) {   /* I - Size of destination string buffer */
00039   size_t        srclen;         /* Length of source string */
00040   size_t        dstlen;         /* Length of destination string */
00041 
00042 
00043  /*
00044   * Figure out how much room is left...
00045   */
00046 
00047   dstlen = strlen(dst);
00048   size   -= dstlen + 1;
00049 
00050   if (!size) return (dstlen);   /* No room, return immediately... */
00051 
00052  /*
00053   * Figure out how much room is needed...
00054   */
00055 
00056   srclen = strlen(src);
00057 
00058  /*
00059   * Copy the appropriate amount...
00060   */
00061 
00062   if (srclen > size) srclen = size;
00063 
00064   memcpy(dst + dstlen, src, srclen);
00065   dst[dstlen + srclen] = '\0';
00066 
00067   return (dstlen + srclen);
00068 }
00069 
00070 
00071 /*
00072  * 'fl_strlcpy()' - Safely copy two strings.
00073  */
00074 
00075 size_t                          /* O - Length of string */
00076 fl_strlcpy(char       *dst,     /* O - Destination string */
00077            const char *src,     /* I - Source string */
00078            size_t      size) {  /* I - Size of destination string buffer */
00079   size_t        srclen;         /* Length of source string */
00080 
00081 
00082  /*
00083   * Figure out how much room is needed...
00084   */
00085 
00086   size --;
00087 
00088   srclen = strlen(src);
00089 
00090  /*
00091   * Copy the appropriate amount...
00092   */
00093 
00094   if (srclen > size) srclen = size;
00095 
00096   memcpy(dst, src, srclen);
00097   dst[srclen] = '\0';
00098 
00099   return (srclen);
00100 }
00101 
00102 
00103 /*
00104  * End of "$Id: flstring.c 7903 2010-11-28 21:06:39Z matt $".
00105  */