Warn if open_count is already 0 when OSS_CloseDevice is called.
[wine/hacks.git] / dlls / ntdll / string.c
blob6a0b5e274873695c358cfe5f503d42738be48597
1 /*
2 * NTDLL string functions
4 * Copyright 2000 Alexandre Julliard
5 * Copyright 2000 Jon Griffiths
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.
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.
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
22 #include "config.h"
24 #include <ctype.h>
25 #include <string.h>
27 #include "windef.h"
29 /*********************************************************************
30 * _memicmp (NTDLL.@)
32 INT __cdecl NTDLL__memicmp( LPCSTR s1, LPCSTR s2, DWORD len )
34 int ret = 0;
35 while (len--)
37 if ((ret = tolower(*s1) - tolower(*s2))) break;
38 s1++;
39 s2++;
41 return ret;
44 /*********************************************************************
45 * _strupr (NTDLL.@)
47 LPSTR __cdecl _strupr( LPSTR str )
49 LPSTR ret = str;
50 for ( ; *str; str++) *str = toupper(*str);
51 return ret;
54 /*********************************************************************
55 * _strlwr (NTDLL.@)
57 * convert a string in place to lowercase
59 LPSTR __cdecl _strlwr( LPSTR str )
61 LPSTR ret = str;
62 for ( ; *str; str++) *str = tolower(*str);
63 return ret;
67 /*********************************************************************
68 * _ultoa (NTDLL.@)
70 LPSTR __cdecl _ultoa( unsigned long x, LPSTR buf, INT radix )
72 char *p, buffer[8*sizeof(unsigned long) + 1]; /* assume 8-bit chars */
74 p = buffer + sizeof(buffer);
75 *--p = 0;
78 int rem = x % radix;
79 *--p = (rem <= 9) ? rem + '0' : rem + 'a' - 10;
80 x /= radix;
81 } while (x);
82 strcpy( buf, p );
83 return buf;
87 /*********************************************************************
88 * _ltoa (NTDLL.@)
90 LPSTR __cdecl _ltoa( long x, LPSTR buf, INT radix )
92 LPSTR p = buf;
93 if (x < 0)
95 *p++ = '-';
96 x = -x;
98 _ultoa( x, p, radix );
99 return buf;
103 /*********************************************************************
104 * _itoa (NTDLL.@)
106 LPSTR __cdecl _itoa( int x, LPSTR buf, INT radix )
108 return _ltoa( x, buf, radix );
112 /*********************************************************************
113 * _splitpath (NTDLL.@)
115 void __cdecl _splitpath(const char* inpath, char * drv, char * dir,
116 char* fname, char * ext )
118 /* Modified PD code from 'snippets' collection. */
119 char ch, *ptr, *p;
120 char pathbuff[MAX_PATH], *path=pathbuff;
122 strcpy(pathbuff, inpath);
124 /* convert slashes to backslashes for searching */
125 for (ptr = (char*)path; *ptr; ++ptr)
126 if ('/' == *ptr)
127 *ptr = '\\';
129 /* look for drive spec */
130 if ('\0' != (ptr = strchr(path, ':')))
132 ++ptr;
133 if (drv)
135 strncpy(drv, path, ptr - path);
136 drv[ptr - path] = '\0';
138 path = ptr;
140 else if (drv)
141 *drv = '\0';
143 /* find rightmost backslash or leftmost colon */
144 if (NULL == (ptr = strrchr(path, '\\')))
145 ptr = (strchr(path, ':'));
147 if (!ptr)
149 ptr = (char *)path; /* no path */
150 if (dir)
151 *dir = '\0';
153 else
155 ++ptr; /* skip the delimiter */
156 if (dir)
158 ch = *ptr;
159 *ptr = '\0';
160 strcpy(dir, path);
161 *ptr = ch;
165 if (NULL == (p = strrchr(ptr, '.')))
167 if (fname)
168 strcpy(fname, ptr);
169 if (ext)
170 *ext = '\0';
172 else
174 *p = '\0';
175 if (fname)
176 strcpy(fname, ptr);
177 *p = '.';
178 if (ext)
179 strcpy(ext, p);
182 /* Fix pathological case - Win returns ':' as part of the
183 * directory when no drive letter is given.
185 if (drv && drv[0] == ':')
187 *drv = '\0';
188 if (dir)
190 pathbuff[0] = ':';
191 pathbuff[1] = '\0';
192 strcat(pathbuff,dir);
193 strcpy(dir,pathbuff);