Mercurial > hg > xmms-sid
view src/xs_support.c @ 218:57231fe14369
Minor fixes
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 15 Dec 2004 11:23:02 +0000 |
parents | 575686094eb1 |
children | df4cb5115322 |
line wrap: on
line source
/* XMMS-SID - SIDPlay input plugin for X MultiMedia System (XMMS) Miscellaneous support functions Written by Matti "ccr" Hamalainen <ccr@tnsp.org> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "xmms-sid.h" #include "xs_support.h" /* Copy a string */ gchar *xs_strncpy(gchar *pDest, gchar *pSource, size_t n) { gchar *s, *d; size_t i; /* Check the string pointers */ if (!pSource || !pDest) return pDest; /* Copy to the destination */ i = n; s = pSource; d = pDest; while (*s && (i > 0)) { *(d++) = *(s++); i--; } /* Fill rest of space with zeros */ while (i > 0) { *(d++) = 0; i--; } /* Ensure that last is always zero */ pDest[n - 1] = 0; return pDest; } /* Copy a given string over in *ppResult. */ gint xs_pstrcpy(gchar **ppResult, const gchar *pStr) { /* Check the string pointers */ if (!ppResult || !pStr) return -1; /* Allocate memory for destination */ if (*ppResult) g_free(*ppResult); *ppResult = (gchar *) g_malloc(strlen(pStr) + 1); if (!*ppResult) return -2; /* Copy to the destination */ strcpy(*ppResult, pStr); return 0; } /* Concatenates a given string into string pointed by *ppResult. */ gint th_pstrcat(gchar **ppResult, const gchar *pStr) { /* Check the string pointers */ if (!ppResult || !pStr) return -1; if (*ppResult != NULL) { *ppResult = g_realloc(*ppResult, strlen(*ppResult) + strlen(pStr) + 1); if (*ppResult == NULL) return -1; strcat(*ppResult, pStr); } else { *ppResult = g_malloc(strlen(pStr) + 1); if (*ppResult == NULL) return -1; strcpy(*ppResult, pStr); } return 0; } /* Locate character in string */ gchar *xs_strrchr(gchar *pcStr, gchar ch) { gchar *lastPos = NULL; while (*pcStr) { if (*pcStr == ch) lastPos = pcStr; pcStr++; } return lastPos; } inline void xs_findnext(gchar *pcStr, guint *piPos) { while (pcStr[*piPos] && isspace(pcStr[*piPos])) (*piPos)++; } inline void xs_findeol(gchar *pcStr, guint *piPos) { while (pcStr[*piPos] && (pcStr[*piPos] != '\n') && (pcStr[*piPos] != '\r')) (*piPos)++; } inline void xs_findnum(gchar *pcStr, guint *piPos) { while (pcStr[*piPos] && isdigit(pcStr[*piPos])) (*piPos)++; } #ifndef HAVE_MEMSET void *xs_memset(void *p, int c, size_t n) { gchar *dp; dp = (gchar *) p; while (n--) { *dp = (gchar) c; n--; } return p; } #endif