| 1 | /*
|
|---|
| 2 | * NTDLL string functions
|
|---|
| 3 | *
|
|---|
| 4 | * Copyright 2000 Alexandre Julliard
|
|---|
| 5 | * Copyright 2000 Jon Griffiths
|
|---|
| 6 | *
|
|---|
| 7 | * This library is free software; you can redistribute it and/or
|
|---|
| 8 | * modify it under the terms of the GNU Lesser General Public
|
|---|
| 9 | * License as published by the Free Software Foundation; either
|
|---|
| 10 | * version 2.1 of the License, or (at your option) any later version.
|
|---|
| 11 | *
|
|---|
| 12 | * This library is distributed in the hope that it will be useful,
|
|---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|---|
| 15 | * Lesser General Public License for more details.
|
|---|
| 16 | *
|
|---|
| 17 | * You should have received a copy of the GNU Lesser General Public
|
|---|
| 18 | * License along with this library; if not, write to the Free Software
|
|---|
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|---|
| 20 | */
|
|---|
| 21 |
|
|---|
| 22 | #include "config.h"
|
|---|
| 23 |
|
|---|
| 24 | #include <ctype.h>
|
|---|
| 25 | #include <string.h>
|
|---|
| 26 |
|
|---|
| 27 | #include "windef.h"
|
|---|
| 28 |
|
|---|
| 29 | /*********************************************************************
|
|---|
| 30 | * _memicmp (NTDLL.@)
|
|---|
| 31 | */
|
|---|
| 32 | #ifdef __WIN32OS2__
|
|---|
| 33 | INT __cdecl NTDLL_memicmp( LPCSTR s1, LPCSTR s2, DWORD len )
|
|---|
| 34 | #else
|
|---|
| 35 | INT __cdecl _memicmp( LPCSTR s1, LPCSTR s2, DWORD len )
|
|---|
| 36 | #endif
|
|---|
| 37 | {
|
|---|
| 38 | int ret = 0;
|
|---|
| 39 | while (len--)
|
|---|
| 40 | {
|
|---|
| 41 | if ((ret = tolower(*s1) - tolower(*s2))) break;
|
|---|
| 42 | s1++;
|
|---|
| 43 | s2++;
|
|---|
| 44 | }
|
|---|
| 45 | return ret;
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | /*********************************************************************
|
|---|
| 49 | * _strupr (NTDLL.@)
|
|---|
| 50 | */
|
|---|
| 51 | LPSTR __cdecl _strupr( LPSTR str )
|
|---|
| 52 | {
|
|---|
| 53 | LPSTR ret = str;
|
|---|
| 54 | for ( ; *str; str++) *str = toupper(*str);
|
|---|
| 55 | return ret;
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | /*********************************************************************
|
|---|
| 59 | * _strlwr (NTDLL.@)
|
|---|
| 60 | *
|
|---|
| 61 | * convert a string in place to lowercase
|
|---|
| 62 | */
|
|---|
| 63 | LPSTR __cdecl _strlwr( LPSTR str )
|
|---|
| 64 | {
|
|---|
| 65 | LPSTR ret = str;
|
|---|
| 66 | for ( ; *str; str++) *str = tolower(*str);
|
|---|
| 67 | return ret;
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 | /*********************************************************************
|
|---|
| 72 | * _ultoa (NTDLL.@)
|
|---|
| 73 | */
|
|---|
| 74 | #ifdef __WIN32OS2__
|
|---|
| 75 | LPSTR __cdecl NTDLL_ultoa( unsigned long x, LPSTR buf, INT radix )
|
|---|
| 76 | #else
|
|---|
| 77 | LPSTR __cdecl _ultoa( unsigned long x, LPSTR buf, INT radix )
|
|---|
| 78 | #endif
|
|---|
| 79 | {
|
|---|
| 80 | char buffer[32], *p;
|
|---|
| 81 |
|
|---|
| 82 | p = buffer + sizeof(buffer);
|
|---|
| 83 | *--p = 0;
|
|---|
| 84 | do
|
|---|
| 85 | {
|
|---|
| 86 | int rem = x % radix;
|
|---|
| 87 | *--p = (rem <= 9) ? rem + '0' : rem + 'a' - 10;
|
|---|
| 88 | x /= radix;
|
|---|
| 89 | } while (x);
|
|---|
| 90 | strcpy( buf, p );
|
|---|
| 91 | return buf;
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 | /*********************************************************************
|
|---|
| 96 | * _ltoa (NTDLL.@)
|
|---|
| 97 | */
|
|---|
| 98 | #ifdef __WIN32OS2__
|
|---|
| 99 | LPSTR __cdecl NTDLL_ltoa( long x, LPSTR buf, INT radix )
|
|---|
| 100 | #else
|
|---|
| 101 | LPSTR __cdecl _ltoa( long x, LPSTR buf, INT radix )
|
|---|
| 102 | #endif
|
|---|
| 103 | {
|
|---|
| 104 | LPSTR p = buf;
|
|---|
| 105 | if (x < 0)
|
|---|
| 106 | {
|
|---|
| 107 | *p++ = '-';
|
|---|
| 108 | x = -x;
|
|---|
| 109 | }
|
|---|
| 110 | _ultoa( x, p, radix );
|
|---|
| 111 | return buf;
|
|---|
| 112 | }
|
|---|
| 113 |
|
|---|
| 114 |
|
|---|
| 115 | /*********************************************************************
|
|---|
| 116 | * _itoa (NTDLL.@)
|
|---|
| 117 | */
|
|---|
| 118 | #ifdef __WIN32OS2__
|
|---|
| 119 | LPSTR __cdecl NTDLL_itoa( int x, LPSTR buf, INT radix )
|
|---|
| 120 | #else
|
|---|
| 121 | LPSTR __cdecl _itoa( int x, LPSTR buf, INT radix )
|
|---|
| 122 | #endif
|
|---|
| 123 | {
|
|---|
| 124 | return _ltoa( x, buf, radix );
|
|---|
| 125 | }
|
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 | /*********************************************************************
|
|---|
| 129 | * _splitpath (NTDLL.@)
|
|---|
| 130 | */
|
|---|
| 131 | #ifdef __WIN32OS2__
|
|---|
| 132 | void __cdecl NTDLL_splitpath(const char* inpath, char * drv, char * dir,
|
|---|
| 133 | char* fname, char * ext )
|
|---|
| 134 | #else
|
|---|
| 135 | void __cdecl _splitpath(const char* inpath, char * drv, char * dir,
|
|---|
| 136 | char* fname, char * ext )
|
|---|
| 137 | #endif
|
|---|
| 138 | {
|
|---|
| 139 | /* Modified PD code from 'snippets' collection. */
|
|---|
| 140 | char ch, *ptr, *p;
|
|---|
| 141 | char pathbuff[MAX_PATH], *path=pathbuff;
|
|---|
| 142 |
|
|---|
| 143 | strcpy(pathbuff, inpath);
|
|---|
| 144 |
|
|---|
| 145 | /* convert slashes to backslashes for searching */
|
|---|
| 146 | for (ptr = (char*)path; *ptr; ++ptr)
|
|---|
| 147 | if ('/' == *ptr)
|
|---|
| 148 | *ptr = '\\';
|
|---|
| 149 |
|
|---|
| 150 | /* look for drive spec */
|
|---|
| 151 | if ('\0' != (ptr = strchr(path, ':')))
|
|---|
| 152 | {
|
|---|
| 153 | ++ptr;
|
|---|
| 154 | if (drv)
|
|---|
| 155 | {
|
|---|
| 156 | strncpy(drv, path, ptr - path);
|
|---|
| 157 | drv[ptr - path] = '\0';
|
|---|
| 158 | }
|
|---|
| 159 | path = ptr;
|
|---|
| 160 | }
|
|---|
| 161 | else if (drv)
|
|---|
| 162 | *drv = '\0';
|
|---|
| 163 |
|
|---|
| 164 | /* find rightmost backslash or leftmost colon */
|
|---|
| 165 | if (NULL == (ptr = strrchr(path, '\\')))
|
|---|
| 166 | ptr = (strchr(path, ':'));
|
|---|
| 167 |
|
|---|
| 168 | if (!ptr)
|
|---|
| 169 | {
|
|---|
| 170 | ptr = (char *)path; /* no path */
|
|---|
| 171 | if (dir)
|
|---|
| 172 | *dir = '\0';
|
|---|
| 173 | }
|
|---|
| 174 | else
|
|---|
| 175 | {
|
|---|
| 176 | ++ptr; /* skip the delimiter */
|
|---|
| 177 | if (dir)
|
|---|
| 178 | {
|
|---|
| 179 | ch = *ptr;
|
|---|
| 180 | *ptr = '\0';
|
|---|
| 181 | strcpy(dir, path);
|
|---|
| 182 | *ptr = ch;
|
|---|
| 183 | }
|
|---|
| 184 | }
|
|---|
| 185 |
|
|---|
| 186 | if (NULL == (p = strrchr(ptr, '.')))
|
|---|
| 187 | {
|
|---|
| 188 | if (fname)
|
|---|
| 189 | strcpy(fname, ptr);
|
|---|
| 190 | if (ext)
|
|---|
| 191 | *ext = '\0';
|
|---|
| 192 | }
|
|---|
| 193 | else
|
|---|
| 194 | {
|
|---|
| 195 | *p = '\0';
|
|---|
| 196 | if (fname)
|
|---|
| 197 | strcpy(fname, ptr);
|
|---|
| 198 | *p = '.';
|
|---|
| 199 | if (ext)
|
|---|
| 200 | strcpy(ext, p);
|
|---|
| 201 | }
|
|---|
| 202 |
|
|---|
| 203 | /* Fix pathological case - Win returns ':' as part of the
|
|---|
| 204 | * directory when no drive letter is given.
|
|---|
| 205 | */
|
|---|
| 206 | if (drv && drv[0] == ':')
|
|---|
| 207 | {
|
|---|
| 208 | *drv = '\0';
|
|---|
| 209 | if (dir)
|
|---|
| 210 | {
|
|---|
| 211 | pathbuff[0] = ':';
|
|---|
| 212 | pathbuff[1] = '\0';
|
|---|
| 213 | strcat(pathbuff,dir);
|
|---|
| 214 | strcpy(dir,pathbuff);
|
|---|
| 215 | }
|
|---|
| 216 | }
|
|---|
| 217 | }
|
|---|