The InspIRCd Project
Home | Developers | Wiki | Forums | Bug Tracker | SVN | Download | Blog | Stats
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

inspstring.cpp File Reference

#include "inspstring.h"

Include dependency graph for inspstring.cpp:

Go to the source code of this file.

Functions

CoreExport size_t strlcat (char *dst, const char *src, size_t siz)
CoreExport size_t strlcpy (char *dst, const char *src, size_t siz)
CoreExport int charlcat (char *x, char y, int z)
 charlcat() will append one character to a string using the same safety scemantics as strlcat().
CoreExport bool charremove (char *mp, char remove)
 charremove() will remove all instances of a character from a string


Function Documentation

CoreExport int charlcat char *  x,
char  y,
int  z
 

charlcat() will append one character to a string using the same safety scemantics as strlcat().

Parameters:
x The string to operate on
y the character to append to the end of x
z The maximum allowed length for z including null terminator

Definition at line 102 of file inspstring.cpp.

Referenced by chanrec::ChanModes().

00103 {
00104         char* x__n = x;
00105         int v = 0;
00106 
00107         while(*x__n++)
00108                 v++;
00109 
00110         if (v < z - 1)
00111         {
00112                 *--x__n = y;
00113                 *++x__n = 0;
00114         }
00115 
00116         return v;
00117 }

CoreExport bool charremove char *  mp,
char  remove
 

charremove() will remove all instances of a character from a string

Parameters:
mp The string to operate on
remove The character to remove

Definition at line 119 of file inspstring.cpp.

00120 {
00121         char* mptr = mp;
00122         bool shift_down = false;
00123 
00124         while (*mptr)
00125         {
00126                 if (*mptr == remove)
00127                 shift_down = true;
00128 
00129                 if (shift_down)
00130                         *mptr = *(mptr+1);
00131 
00132                 mptr++;
00133         }
00134 
00135         return shift_down;
00136 }

CoreExport size_t strlcat char *  dst,
const char *  src,
size_t  siz
 

Definition at line 44 of file inspstring.cpp.

Referenced by chanrec::ChanModes(), cmd_modules::Handle(), and TreeSocket::Modules().

00045 {
00046         char *d = dst;
00047         const char *s = src;
00048         size_t n = siz, dlen;
00049 
00050         while (n-- != 0 && *d != '\0')
00051                 d++;
00052 
00053         dlen = d - dst;
00054         n = siz - dlen;
00055 
00056         if (n == 0)
00057                 return(dlen + strlen(s));
00058 
00059         while (*s != '\0')
00060         {
00061                 if (n != 1)
00062                 {
00063                         *d++ = *s;
00064                         n--;
00065                 }
00066 
00067                 s++;
00068         }
00069 
00070         *d = '\0';
00071         return(dlen + (s - src)); /* count does not include NUL */
00072 }

CoreExport size_t strlcpy char *  dst,
const char *  src,
size_t  siz
 

Definition at line 74 of file inspstring.cpp.

Referenced by userrec::AddClient(), userrec::ChangeDisplayedHost(), userrec::ChangeIdent(), userrec::ChangeName(), ModuleCgiIRC::CheckIdent(), ModuleCgiIRC::CheckPass(), ServerConfig::ConfValue(), ServerConfig::DirValid(), TreeSocket::ForceTopic(), userrec::GetIPString(), cmd_whowas::Handle(), cmd_user::Handle(), cmd_topic::Handle(), cmd_pass::Handle(), cmd_nick::Handle(), cmd_modules::Handle(), cmd_kick::Handle(), cmd_away::Handle(), InspIRCd::HostMatchesEveryone(), InspIRCd::InspIRCd(), InspSocket::InspSocket(), TreeSocket::IntroduceClient(), InspIRCd::IPMatchesEveryone(), chanrec::JoinUser(), InspIRCd::Log(), ModulePgSQL::ModulePgSQL(), TreeSocket::Modules(), InspIRCd::NickMatchesEveryone(), ModuleIdent::OnCheckReady(), UserResolver::OnLookupComplete(), CGIResolver::OnLookupComplete(), NickFlood::OnModeChange(), MsgFlood::OnModeChange(), JoinFlood::OnModeChange(), ModuleAntiBottler::OnPreCommand(), ModuleCgiIRC::OnUserConnect(), userrec::Oper(), TreeSocket::OperType(), ModuleSpanningTree::ShowMap(), and irc::Spacify().

00075 {
00076         char *d = dst;
00077         const char *s = src;
00078         size_t n = siz;
00079 
00080         /* Copy as many bytes as will fit */
00081         if (n != 0 && --n != 0)
00082         {
00083                 do
00084                 {
00085                         if ((*d++ = *s++) == 0)
00086                                 break;
00087                 } while (--n != 0);
00088         }
00089 
00090         /* Not enough room in dst, add NUL and traverse rest of src */
00091         if (n == 0)
00092         {
00093                 if (siz != 0)
00094                         *d = '\0'; /* NUL-terminate dst */
00095                 while (*s++);
00096         }
00097 
00098         return(s - src - 1); /* count does not include NUL */
00099 }