/[winpt]/trunk/Src/wptUtil.cpp
ViewVC logotype

Diff of /trunk/Src/wptUtil.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 260 by twoaday, Wed Aug 16 10:01:30 2006 UTC revision 278 by twoaday, Mon Jan 15 22:02:04 2007 UTC
# Line 1  Line 1 
1  /* wptUtil.cpp - Helper functions  /* wptUtil.cpp - Helper functions
2   *      Copyright (C) 2005 Timo Schulz   *      Copyright (C) 2005, 2006 Timo Schulz
3   *   *
4   * This file is part of WinPT.   * This file is part of WinPT.
5   *   *
# Line 12  Line 12 
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14   * General Public License for more details.   * General Public License for more details.
  *  
  * You should have received a copy of the GNU General Public License  
  * along with WinPT; if not, write to the Free Software Foundation,  
  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA  
15   */   */
   
16  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
17  #include <config.h>  #include <config.h>
18  #endif  #endif
19    
20    #include <windows.h>
21  #include <string.h>  #include <string.h>
22  #include <stdlib.h>  #include <stdlib.h>
23  #include <stdio.h>  #include <stdio.h>
24  #include <ctype.h>  #include <ctype.h>
25    
26    #include "wptTypes.h"
27    
28    
29  /* code taken from glibc-2.2.1/sysdeps/generic/strsep.c */  /* code taken from glibc-2.2.1/sysdeps/generic/strsep.c */
30  char*  char*
31  strsep (char **stringp, const char *delim)  strsep (char **stringp, const char *delim)
# Line 76  stristr (const char *buf, const char *su Line 75  stristr (const char *buf, const char *su
75      size_t n;      size_t n;
76      size_t buflen = strlen (buf);      size_t buflen = strlen (buf);
77    
78      for( t=buf, n=buflen, s=sub ; n ; t++, n-- ) {      for (t=buf, n=buflen, s=sub ; n ; t++, n--) {
79          if( toupper(*t) == toupper(*s) ) {          if (toupper (*t) == toupper (*s)) {
80              for( buf=t++, buflen = n--, s++;              for( buf=t++, buflen = n--, s++;
81                   n && toupper(*t) == toupper(*s); t++, s++, n-- )                   n && toupper(*t) == toupper(*s); t++, s++, n-- )
82                  ;                  ;
83              if( !*s )              if (!*s)
84                  return buf;                  return buf;
85              t = buf; n = buflen; s = sub ;              t = buf; n = buflen; s = sub ;
86          }          }
# Line 100  check_file_name (const char *fname, int Line 99  check_file_name (const char *fname, int
99    
100      /* If we are not in path mode (@is_path = 1) we also consider      /* If we are not in path mode (@is_path = 1) we also consider
101         path separators as illegal chars. */         path separators as illegal chars. */
102      if (!is_path) {      if (!is_path && (strchr (fname, ':') || strchr (fname, '\\')))
103          if (strchr (fname, ':') || strchr (fname, '\\'))          return -1;
             return -1;  
     }  
104    
105      for (i=0; i < strlen (fname); i++) {      for (i=0; i < strlen (fname); i++) {
106          if (strchr (not_allowed, fname[i]))          if (strchr (not_allowed, fname[i]))
# Line 147  substr (const char *str, unsigned int be Line 144  substr (const char *str, unsigned int be
144    
145      p = new char[end-begin+1];      p = new char[end-begin+1];
146      if (!p)      if (!p)
147          abort ();          BUG (0);
   
148      for (i = begin, pos=0; i < end; i++)      for (i = begin, pos=0; i < end; i++)
149          p[pos++] = str[i];          p[pos++] = str[i];
150      p[pos] = '\0';      p[pos] = '\0';
# Line 184  unhexify_buffer (const char *in, char ** Line 180  unhexify_buffer (const char *in, char **
180      out[i] = 0;      out[i] = 0;
181      *r_out = out;      *r_out = out;
182  }  }
183    
184    
185    /* Safe strdup version (C++ version). */
186    char*
187    m_strdup (const char *str)
188    {
189        char *p = new char[strlen (str) + 1];
190        if (!p)
191            BUG (NULL);
192        strcpy (p, str);
193        return p;
194    }

Legend:
Removed from v.260  
changed lines
  Added in v.278

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26