Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Atom table functions |
| 3 | * |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 4 | * Copyright 1993, 1994, 1995 Alexandre Julliard |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 5 | * |
| 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Lesser General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2.1 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Lesser General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Lesser General Public |
| 17 | * License along with this library; if not, write to the Free Software |
Jonathan Ernst | 360a3f9 | 2006-05-18 14:49:52 +0200 | [diff] [blame] | 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
Patrik Stridvall | bc38d6b | 2001-07-20 18:00:00 +0000 | [diff] [blame] | 21 | #include "config.h" |
Patrik Stridvall | 51e6c0c | 2002-08-31 19:04:14 +0000 | [diff] [blame] | 22 | #include "wine/port.h" |
Patrik Stridvall | bc38d6b | 2001-07-20 18:00:00 +0000 | [diff] [blame] | 23 | |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 24 | #include <stdlib.h> |
Alexandre Julliard | e37c6e1 | 2003-09-05 23:08:26 +0000 | [diff] [blame] | 25 | #include <stdarg.h> |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 26 | #include <stdio.h> |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 27 | #include <string.h> |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 28 | #include <ctype.h> |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 29 | |
Jeremy White | d3e22d9 | 2000-02-10 19:03:02 +0000 | [diff] [blame] | 30 | #include "windef.h" |
Francois Gouget | 541ff5f | 2001-10-15 17:49:23 +0000 | [diff] [blame] | 31 | #include "winbase.h" |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 32 | #include "winerror.h" |
Eric Pouech | 289889c | 2005-10-29 12:37:42 +0000 | [diff] [blame] | 33 | #include "winternl.h" |
Patrik Stridvall | bc38d6b | 2001-07-20 18:00:00 +0000 | [diff] [blame] | 34 | |
Marcus Meissner | 6c2eae2 | 2005-08-19 15:20:06 +0000 | [diff] [blame] | 35 | #include "wine/exception.h" |
Patrik Stridvall | bc38d6b | 2001-07-20 18:00:00 +0000 | [diff] [blame] | 36 | #include "wine/unicode.h" |
Alexandre Julliard | 55b51ea | 2003-11-13 21:04:01 +0000 | [diff] [blame] | 37 | #include "kernel_private.h" |
Patrik Stridvall | bc38d6b | 2001-07-20 18:00:00 +0000 | [diff] [blame] | 38 | |
Eric Pouech | 78d096c | 2005-02-03 16:58:21 +0000 | [diff] [blame] | 39 | #define MAX_ATOM_LEN 255 |
Michael Stefaniuc | 3f37e33 | 2010-02-10 11:43:37 +0100 | [diff] [blame] | 40 | #define IS_INTATOM(x) (((ULONG_PTR)(x) >> 16) == 0) |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 41 | |
Eric Pouech | 289889c | 2005-10-29 12:37:42 +0000 | [diff] [blame] | 42 | /****************************************************************** |
| 43 | * get_local_table |
| 44 | * |
| 45 | * Returns the local atom table for this process (and create it if doesn't |
| 46 | * exist yet) |
| 47 | */ |
| 48 | static RTL_ATOM_TABLE get_local_table(DWORD entries) |
Eric Pouech | e626736 | 2005-05-10 15:15:50 +0000 | [diff] [blame] | 49 | { |
Eric Pouech | 289889c | 2005-10-29 12:37:42 +0000 | [diff] [blame] | 50 | static RTL_ATOM_TABLE local_table; |
Eric Pouech | e626736 | 2005-05-10 15:15:50 +0000 | [diff] [blame] | 51 | |
| 52 | if (!local_table) |
| 53 | { |
Eric Pouech | 289889c | 2005-10-29 12:37:42 +0000 | [diff] [blame] | 54 | NTSTATUS status; |
| 55 | RTL_ATOM_TABLE table = NULL; |
Eric Pouech | e626736 | 2005-05-10 15:15:50 +0000 | [diff] [blame] | 56 | |
Eric Pouech | 289889c | 2005-10-29 12:37:42 +0000 | [diff] [blame] | 57 | if ((status = RtlCreateAtomTable( entries, &table ))) |
Eric Pouech | e626736 | 2005-05-10 15:15:50 +0000 | [diff] [blame] | 58 | SetLastError( RtlNtStatusToDosError( status ) ); |
| 59 | else if (InterlockedCompareExchangePointer((void*)&local_table, table, NULL) != NULL) |
Eric Pouech | 289889c | 2005-10-29 12:37:42 +0000 | [diff] [blame] | 60 | RtlDestroyAtomTable( table ); |
Eric Pouech | e626736 | 2005-05-10 15:15:50 +0000 | [diff] [blame] | 61 | } |
Eric Pouech | 289889c | 2005-10-29 12:37:42 +0000 | [diff] [blame] | 62 | |
Eric Pouech | e626736 | 2005-05-10 15:15:50 +0000 | [diff] [blame] | 63 | return local_table; |
| 64 | } |
| 65 | |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 66 | |
| 67 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 68 | * InitAtomTable (KERNEL32.@) |
Jon Griffiths | 4c1fa16 | 2003-10-01 03:20:21 +0000 | [diff] [blame] | 69 | * |
Nikolay Sivov | dde69d6 | 2015-05-08 18:05:02 +0300 | [diff] [blame] | 70 | * Initialise local atom table. |
Jon Griffiths | 4c1fa16 | 2003-10-01 03:20:21 +0000 | [diff] [blame] | 71 | * |
| 72 | * PARAMS |
| 73 | * entries [I] The number of entries to reserve in the table. |
| 74 | * |
| 75 | * RETURNS |
| 76 | * Success: TRUE. |
| 77 | * Failure: FALSE. |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 78 | */ |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 79 | BOOL WINAPI InitAtomTable( DWORD entries ) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 80 | { |
Michael Stefaniuc | 97512d7 | 2012-07-31 11:34:54 +0200 | [diff] [blame] | 81 | return get_local_table( entries ) != 0; |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 82 | } |
| 83 | |
Eric Pouech | 289889c | 2005-10-29 12:37:42 +0000 | [diff] [blame] | 84 | /****************************************************************** |
| 85 | * check_integral_atom |
| 86 | * |
| 87 | * Check if a string (ANSI or UNICODE) is in fact an integral atom |
| 88 | * (but doesn't check the "#1234" form) |
| 89 | */ |
| 90 | static inline BOOL check_integral_atom( const void* ptr, ATOM* patom) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 91 | { |
Michael Stefaniuc | 3f37e33 | 2010-02-10 11:43:37 +0100 | [diff] [blame] | 92 | if (!IS_INTATOM( ptr )) return FALSE; |
Eric Pouech | 289889c | 2005-10-29 12:37:42 +0000 | [diff] [blame] | 93 | if ((*patom = LOWORD( ptr )) >= MAXINTATOM) |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 94 | { |
Eric Pouech | 289889c | 2005-10-29 12:37:42 +0000 | [diff] [blame] | 95 | SetLastError( ERROR_INVALID_PARAMETER ); |
| 96 | *patom = 0; |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 97 | } |
Eric Pouech | 289889c | 2005-10-29 12:37:42 +0000 | [diff] [blame] | 98 | return TRUE; |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 99 | } |
| 100 | |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 101 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 102 | * GlobalAddAtomA (KERNEL32.@) |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 103 | * |
Jon Griffiths | 4c1fa16 | 2003-10-01 03:20:21 +0000 | [diff] [blame] | 104 | * Add a character string to the global atom table and return a unique |
| 105 | * value identifying it. |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 106 | * |
| 107 | * RETURNS |
Jon Griffiths | 4c1fa16 | 2003-10-01 03:20:21 +0000 | [diff] [blame] | 108 | * Success: The atom allocated to str. |
| 109 | * Failure: 0. |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 110 | */ |
Jon Griffiths | 4c1fa16 | 2003-10-01 03:20:21 +0000 | [diff] [blame] | 111 | ATOM WINAPI GlobalAddAtomA( LPCSTR str /* [in] String to add */ ) |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 112 | { |
Eric Pouech | 289889c | 2005-10-29 12:37:42 +0000 | [diff] [blame] | 113 | ATOM atom = 0; |
Marcus Meissner | 6c2eae2 | 2005-08-19 15:20:06 +0000 | [diff] [blame] | 114 | __TRY |
| 115 | { |
Eric Pouech | 289889c | 2005-10-29 12:37:42 +0000 | [diff] [blame] | 116 | if (!check_integral_atom( str, &atom )) |
| 117 | { |
| 118 | WCHAR buffer[MAX_ATOM_LEN]; |
| 119 | DWORD len = MultiByteToWideChar( CP_ACP, 0, str, strlen(str), buffer, MAX_ATOM_LEN ); |
| 120 | if (!len) SetLastError( ERROR_INVALID_PARAMETER ); |
| 121 | else |
| 122 | { |
| 123 | NTSTATUS status = NtAddAtom( buffer, len * sizeof(WCHAR), &atom ); |
| 124 | if (status) |
| 125 | { |
| 126 | SetLastError( RtlNtStatusToDosError( status ) ); |
| 127 | atom = 0; |
| 128 | } |
| 129 | } |
| 130 | } |
Marcus Meissner | 6c2eae2 | 2005-08-19 15:20:06 +0000 | [diff] [blame] | 131 | } |
Alexandre Julliard | ae964ac | 2005-12-16 17:17:57 +0100 | [diff] [blame] | 132 | __EXCEPT_PAGE_FAULT |
Marcus Meissner | 6c2eae2 | 2005-08-19 15:20:06 +0000 | [diff] [blame] | 133 | { |
| 134 | SetLastError( ERROR_INVALID_PARAMETER ); |
Eric Pouech | 289889c | 2005-10-29 12:37:42 +0000 | [diff] [blame] | 135 | atom = 0; |
Marcus Meissner | 6c2eae2 | 2005-08-19 15:20:06 +0000 | [diff] [blame] | 136 | } |
| 137 | __ENDTRY |
Eric Pouech | 289889c | 2005-10-29 12:37:42 +0000 | [diff] [blame] | 138 | return atom; |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | |
| 142 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 143 | * AddAtomA (KERNEL32.@) |
Jon Griffiths | 4c1fa16 | 2003-10-01 03:20:21 +0000 | [diff] [blame] | 144 | * |
Nikolay Sivov | dde69d6 | 2015-05-08 18:05:02 +0300 | [diff] [blame] | 145 | * Add a character string to local atom table and return a unique |
Jon Griffiths | 4c1fa16 | 2003-10-01 03:20:21 +0000 | [diff] [blame] | 146 | * value identifying it. |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 147 | * |
| 148 | * RETURNS |
Jon Griffiths | 4c1fa16 | 2003-10-01 03:20:21 +0000 | [diff] [blame] | 149 | * Success: The atom allocated to str. |
| 150 | * Failure: 0. |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 151 | */ |
Jon Griffiths | 4c1fa16 | 2003-10-01 03:20:21 +0000 | [diff] [blame] | 152 | ATOM WINAPI AddAtomA( LPCSTR str /* [in] String to add */ ) |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 153 | { |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 154 | ATOM atom = 0; |
Eric Pouech | 289889c | 2005-10-29 12:37:42 +0000 | [diff] [blame] | 155 | |
| 156 | if (!check_integral_atom( str, &atom )) |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 157 | { |
Eric Pouech | 289889c | 2005-10-29 12:37:42 +0000 | [diff] [blame] | 158 | WCHAR buffer[MAX_ATOM_LEN + 1]; |
| 159 | DWORD len; |
| 160 | RTL_ATOM_TABLE table; |
| 161 | |
| 162 | len = MultiByteToWideChar( CP_ACP, 0, str, -1, buffer, MAX_ATOM_LEN + 1 ); |
| 163 | if (!len) SetLastError( ERROR_INVALID_PARAMETER ); |
| 164 | else if ((table = get_local_table( 0 ))) |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 165 | { |
Eric Pouech | 289889c | 2005-10-29 12:37:42 +0000 | [diff] [blame] | 166 | NTSTATUS status = RtlAddAtomToAtomTable( table, buffer, &atom ); |
| 167 | if (status) |
| 168 | { |
| 169 | SetLastError( RtlNtStatusToDosError( status ) ); |
| 170 | atom = 0; |
| 171 | } |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 172 | } |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 173 | } |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 174 | return atom; |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 175 | } |
| 176 | |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 177 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 178 | * GlobalAddAtomW (KERNEL32.@) |
Jon Griffiths | 4c1fa16 | 2003-10-01 03:20:21 +0000 | [diff] [blame] | 179 | * |
| 180 | * Unicode version of GlobalAddAtomA. |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 181 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 182 | ATOM WINAPI GlobalAddAtomW( LPCWSTR str ) |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 183 | { |
Eric Pouech | 289889c | 2005-10-29 12:37:42 +0000 | [diff] [blame] | 184 | ATOM atom = 0; |
| 185 | NTSTATUS status; |
| 186 | |
| 187 | if (!check_integral_atom( str, &atom ) && |
| 188 | (status = NtAddAtom( str, strlenW( str ) * sizeof(WCHAR), &atom ))) |
| 189 | { |
| 190 | SetLastError( RtlNtStatusToDosError( status ) ); |
| 191 | atom = 0; |
| 192 | } |
| 193 | return atom; |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | |
| 197 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 198 | * AddAtomW (KERNEL32.@) |
Jon Griffiths | 4c1fa16 | 2003-10-01 03:20:21 +0000 | [diff] [blame] | 199 | * |
| 200 | * Unicode version of AddAtomA. |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 201 | */ |
| 202 | ATOM WINAPI AddAtomW( LPCWSTR str ) |
| 203 | { |
Eric Pouech | 289889c | 2005-10-29 12:37:42 +0000 | [diff] [blame] | 204 | ATOM atom = 0; |
| 205 | RTL_ATOM_TABLE table; |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 206 | |
Eric Pouech | 289889c | 2005-10-29 12:37:42 +0000 | [diff] [blame] | 207 | if (!check_integral_atom( str, &atom ) && (table = get_local_table( 0 ))) |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 208 | { |
Eric Pouech | 289889c | 2005-10-29 12:37:42 +0000 | [diff] [blame] | 209 | NTSTATUS status = RtlAddAtomToAtomTable( table, str, &atom ); |
| 210 | if (status) |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 211 | { |
Eric Pouech | 289889c | 2005-10-29 12:37:42 +0000 | [diff] [blame] | 212 | SetLastError( RtlNtStatusToDosError( status ) ); |
| 213 | atom = 0; |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 214 | } |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 215 | } |
Eric Pouech | 289889c | 2005-10-29 12:37:42 +0000 | [diff] [blame] | 216 | return atom; |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | |
| 220 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 221 | * GlobalDeleteAtom (KERNEL32.@) |
Jon Griffiths | 4c1fa16 | 2003-10-01 03:20:21 +0000 | [diff] [blame] | 222 | * |
| 223 | * Decrement the reference count of a string atom. If the count is |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 224 | * zero, the string associated with the atom is removed from the table. |
| 225 | * |
| 226 | * RETURNS |
Jon Griffiths | 4c1fa16 | 2003-10-01 03:20:21 +0000 | [diff] [blame] | 227 | * Success: 0. |
| 228 | * Failure: atom. |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 229 | */ |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 230 | ATOM WINAPI GlobalDeleteAtom( ATOM atom /* [in] Atom to delete */ ) |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 231 | { |
Eric Pouech | 289889c | 2005-10-29 12:37:42 +0000 | [diff] [blame] | 232 | if (atom >= MAXINTATOM) |
| 233 | { |
| 234 | NTSTATUS status = NtDeleteAtom( atom ); |
| 235 | if (status) |
| 236 | { |
| 237 | SetLastError( RtlNtStatusToDosError( status ) ); |
| 238 | return atom; |
| 239 | } |
| 240 | } |
| 241 | return 0; |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | |
| 245 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 246 | * DeleteAtom (KERNEL32.@) |
Jon Griffiths | 4c1fa16 | 2003-10-01 03:20:21 +0000 | [diff] [blame] | 247 | * |
| 248 | * Decrement the reference count of a string atom. If the count becomes |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 249 | * zero, the string associated with the atom is removed from the table. |
| 250 | * |
| 251 | * RETURNS |
Jon Griffiths | 4c1fa16 | 2003-10-01 03:20:21 +0000 | [diff] [blame] | 252 | * Success: 0. |
| 253 | * Failure: atom |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 254 | */ |
| 255 | ATOM WINAPI DeleteAtom( ATOM atom /* [in] Atom to delete */ ) |
| 256 | { |
Eric Pouech | 289889c | 2005-10-29 12:37:42 +0000 | [diff] [blame] | 257 | NTSTATUS status; |
| 258 | RTL_ATOM_TABLE table; |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 259 | |
Eric Pouech | 289889c | 2005-10-29 12:37:42 +0000 | [diff] [blame] | 260 | if (atom >= MAXINTATOM) |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 261 | { |
Eric Pouech | 289889c | 2005-10-29 12:37:42 +0000 | [diff] [blame] | 262 | if (!(table = get_local_table( 0 ))) return atom; |
| 263 | status = RtlDeleteAtomFromAtomTable( table, atom ); |
| 264 | if (status) |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 265 | { |
Eric Pouech | 289889c | 2005-10-29 12:37:42 +0000 | [diff] [blame] | 266 | SetLastError( RtlNtStatusToDosError( status ) ); |
| 267 | return atom; |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 268 | } |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 269 | } |
Eric Pouech | 289889c | 2005-10-29 12:37:42 +0000 | [diff] [blame] | 270 | return 0; |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | |
| 274 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 275 | * GlobalFindAtomA (KERNEL32.@) |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 276 | * |
Jon Griffiths | 4c1fa16 | 2003-10-01 03:20:21 +0000 | [diff] [blame] | 277 | * Get the atom associated with a string. |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 278 | * |
| 279 | * RETURNS |
Jon Griffiths | 4c1fa16 | 2003-10-01 03:20:21 +0000 | [diff] [blame] | 280 | * Success: The associated atom. |
| 281 | * Failure: 0. |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 282 | */ |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 283 | ATOM WINAPI GlobalFindAtomA( LPCSTR str /* [in] Pointer to string to search for */ ) |
| 284 | { |
Eric Pouech | 289889c | 2005-10-29 12:37:42 +0000 | [diff] [blame] | 285 | ATOM atom = 0; |
| 286 | |
| 287 | if (!check_integral_atom( str, &atom )) |
| 288 | { |
| 289 | WCHAR buffer[MAX_ATOM_LEN]; |
| 290 | DWORD len = MultiByteToWideChar( CP_ACP, 0, str, strlen(str), buffer, MAX_ATOM_LEN ); |
| 291 | |
| 292 | if (!len) SetLastError( ERROR_INVALID_PARAMETER ); |
| 293 | else |
| 294 | { |
| 295 | NTSTATUS status = NtFindAtom( buffer, len * sizeof(WCHAR), &atom ); |
| 296 | if (status) |
| 297 | { |
| 298 | SetLastError( RtlNtStatusToDosError( status ) ); |
| 299 | atom = 0; |
| 300 | } |
| 301 | } |
| 302 | } |
| 303 | return atom; |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 307 | * FindAtomA (KERNEL32.@) |
Jon Griffiths | 4c1fa16 | 2003-10-01 03:20:21 +0000 | [diff] [blame] | 308 | * |
| 309 | * Get the atom associated with a string. |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 310 | * |
| 311 | * RETURNS |
Jon Griffiths | 4c1fa16 | 2003-10-01 03:20:21 +0000 | [diff] [blame] | 312 | * Success: The associated atom. |
| 313 | * Failure: 0. |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 314 | */ |
| 315 | ATOM WINAPI FindAtomA( LPCSTR str /* [in] Pointer to string to find */ ) |
| 316 | { |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 317 | ATOM atom = 0; |
Eric Pouech | 289889c | 2005-10-29 12:37:42 +0000 | [diff] [blame] | 318 | |
| 319 | if (!check_integral_atom( str, &atom )) |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 320 | { |
Eric Pouech | 289889c | 2005-10-29 12:37:42 +0000 | [diff] [blame] | 321 | WCHAR buffer[MAX_ATOM_LEN + 1]; |
| 322 | DWORD len; |
| 323 | RTL_ATOM_TABLE table; |
| 324 | |
| 325 | len = MultiByteToWideChar( CP_ACP, 0, str, -1, buffer, MAX_ATOM_LEN + 1 ); |
| 326 | if (!len) SetLastError( ERROR_INVALID_PARAMETER ); |
| 327 | else if ((table = get_local_table( 0 ))) |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 328 | { |
Eric Pouech | 289889c | 2005-10-29 12:37:42 +0000 | [diff] [blame] | 329 | NTSTATUS status = RtlLookupAtomInAtomTable( table, buffer, &atom ); |
| 330 | if (status) |
| 331 | { |
| 332 | SetLastError( RtlNtStatusToDosError( status ) ); |
| 333 | atom = 0; |
| 334 | } |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 335 | } |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 336 | } |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 337 | return atom; |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | |
| 341 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 342 | * GlobalFindAtomW (KERNEL32.@) |
Jon Griffiths | 4c1fa16 | 2003-10-01 03:20:21 +0000 | [diff] [blame] | 343 | * |
| 344 | * Unicode version of GlobalFindAtomA. |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 345 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 346 | ATOM WINAPI GlobalFindAtomW( LPCWSTR str ) |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 347 | { |
Eric Pouech | 289889c | 2005-10-29 12:37:42 +0000 | [diff] [blame] | 348 | ATOM atom = 0; |
| 349 | |
| 350 | if (!check_integral_atom( str, &atom )) |
| 351 | { |
| 352 | NTSTATUS status = NtFindAtom( str, strlenW( str ) * sizeof(WCHAR), &atom ); |
| 353 | if (status) |
| 354 | { |
| 355 | SetLastError( RtlNtStatusToDosError( status ) ); |
| 356 | atom = 0; |
| 357 | } |
| 358 | } |
| 359 | return atom; |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | |
| 363 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 364 | * FindAtomW (KERNEL32.@) |
Jon Griffiths | 4c1fa16 | 2003-10-01 03:20:21 +0000 | [diff] [blame] | 365 | * |
| 366 | * Unicode version of FindAtomA. |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 367 | */ |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 368 | ATOM WINAPI FindAtomW( LPCWSTR str ) |
| 369 | { |
Eric Pouech | 289889c | 2005-10-29 12:37:42 +0000 | [diff] [blame] | 370 | ATOM atom = 0; |
| 371 | NTSTATUS status; |
| 372 | RTL_ATOM_TABLE table; |
| 373 | |
| 374 | if ((table = get_local_table( 0 ))) |
| 375 | { |
| 376 | status = RtlLookupAtomInAtomTable( table, str, &atom ); |
| 377 | if (status) |
| 378 | { |
| 379 | SetLastError( RtlNtStatusToDosError( status ) ); |
| 380 | atom = 0; |
| 381 | } |
| 382 | } |
| 383 | return atom; |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 387 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 388 | * GlobalGetAtomNameA (KERNEL32.@) |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 389 | * |
Jon Griffiths | 4c1fa16 | 2003-10-01 03:20:21 +0000 | [diff] [blame] | 390 | * Get a copy of the string associated with an atom. |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 391 | * |
| 392 | * RETURNS |
Jon Griffiths | 4c1fa16 | 2003-10-01 03:20:21 +0000 | [diff] [blame] | 393 | * Success: The length of the returned string in characters. |
| 394 | * Failure: 0. |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 395 | */ |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 396 | UINT WINAPI GlobalGetAtomNameA( |
| 397 | ATOM atom, /* [in] Atom identifier */ |
| 398 | LPSTR buffer, /* [out] Pointer to buffer for atom string */ |
| 399 | INT count ) /* [in] Size of buffer */ |
| 400 | { |
Eric Pouech | 70342db | 2006-01-03 17:35:01 +0100 | [diff] [blame] | 401 | WCHAR tmpW[MAX_ATOM_LEN + 1]; |
| 402 | UINT wlen, len = 0, c; |
| 403 | |
| 404 | if (count <= 0) SetLastError( ERROR_MORE_DATA ); |
| 405 | else if ((wlen = GlobalGetAtomNameW( atom, tmpW, MAX_ATOM_LEN + 1 ))) |
| 406 | { |
| 407 | char tmp[MAX_ATOM_LEN + 1]; |
| 408 | |
| 409 | len = WideCharToMultiByte( CP_ACP, 0, tmpW, wlen, tmp, MAX_ATOM_LEN + 1, NULL, NULL ); |
| 410 | c = min(len, count - 1); |
| 411 | memcpy(buffer, tmp, c); |
| 412 | buffer[c] = '\0'; |
| 413 | if (len >= count) |
| 414 | { |
| 415 | len = 0; |
| 416 | SetLastError( ERROR_MORE_DATA ); |
| 417 | } |
| 418 | } |
| 419 | return len; |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | |
| 423 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 424 | * GetAtomNameA (KERNEL32.@) |
Jon Griffiths | 4c1fa16 | 2003-10-01 03:20:21 +0000 | [diff] [blame] | 425 | * |
| 426 | * Get a copy of the string associated with an atom. |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 427 | * |
| 428 | * RETURNS |
Jon Griffiths | 4c1fa16 | 2003-10-01 03:20:21 +0000 | [diff] [blame] | 429 | * Success: The length of the returned string in characters. |
| 430 | * Failure: 0. |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 431 | */ |
| 432 | UINT WINAPI GetAtomNameA( |
| 433 | ATOM atom, /* [in] Atom */ |
| 434 | LPSTR buffer, /* [out] Pointer to string for atom string */ |
| 435 | INT count) /* [in] Size of buffer */ |
| 436 | { |
Eric Pouech | 70342db | 2006-01-03 17:35:01 +0100 | [diff] [blame] | 437 | WCHAR tmpW[MAX_ATOM_LEN + 1]; |
| 438 | UINT wlen, len = 0, c; |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 439 | |
Eric Pouech | 70342db | 2006-01-03 17:35:01 +0100 | [diff] [blame] | 440 | if (count <= 0) SetLastError( ERROR_MORE_DATA ); |
| 441 | else if ((wlen = GetAtomNameW( atom, tmpW, MAX_ATOM_LEN + 1 ))) |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 442 | { |
Eric Pouech | 70342db | 2006-01-03 17:35:01 +0100 | [diff] [blame] | 443 | char tmp[MAX_ATOM_LEN + 1]; |
| 444 | |
| 445 | len = WideCharToMultiByte( CP_ACP, 0, tmpW, wlen, tmp, MAX_ATOM_LEN + 1, NULL, NULL ); |
| 446 | c = min(len, count - 1); |
| 447 | memcpy(buffer, tmp, c); |
| 448 | buffer[c] = '\0'; |
| 449 | if (len >= count) |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 450 | { |
Eric Pouech | 70342db | 2006-01-03 17:35:01 +0100 | [diff] [blame] | 451 | len = c; |
| 452 | SetLastError( ERROR_MORE_DATA ); |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 453 | } |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 454 | } |
Alexandre Julliard | b849d79 | 2000-02-13 13:56:13 +0000 | [diff] [blame] | 455 | return len; |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 456 | } |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 457 | |
| 458 | |
| 459 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 460 | * GlobalGetAtomNameW (KERNEL32.@) |
Jon Griffiths | 4c1fa16 | 2003-10-01 03:20:21 +0000 | [diff] [blame] | 461 | * |
| 462 | * Unicode version of GlobalGetAtomNameA. |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 463 | */ |
| 464 | UINT WINAPI GlobalGetAtomNameW( ATOM atom, LPWSTR buffer, INT count ) |
| 465 | { |
Eric Pouech | 70342db | 2006-01-03 17:35:01 +0100 | [diff] [blame] | 466 | char ptr[sizeof(ATOM_BASIC_INFORMATION) + MAX_ATOM_LEN * sizeof(WCHAR)]; |
| 467 | ATOM_BASIC_INFORMATION* abi = (ATOM_BASIC_INFORMATION*)ptr; |
| 468 | ULONG ptr_size = sizeof(ATOM_BASIC_INFORMATION) + MAX_ATOM_LEN * sizeof(WCHAR); |
| 469 | NTSTATUS status; |
| 470 | UINT length = 0; |
| 471 | |
| 472 | if (count <= 0) |
| 473 | { |
| 474 | SetLastError( ERROR_MORE_DATA ); |
| 475 | return 0; |
| 476 | } |
| 477 | status = NtQueryInformationAtom( atom, AtomBasicInformation, (void*)ptr, ptr_size, NULL ); |
| 478 | if (status) SetLastError( RtlNtStatusToDosError( status ) ); |
| 479 | else |
| 480 | { |
| 481 | length = min( abi->NameLength / sizeof(WCHAR), count); |
| 482 | memcpy( buffer, abi->Name, length * sizeof(WCHAR) ); |
Eric Pouech | dccd41a | 2006-02-06 11:26:57 +0100 | [diff] [blame] | 483 | /* yes, the string will not be null terminated if the passed buffer |
| 484 | * is one WCHAR too small (and it's not an error) |
| 485 | */ |
Eric Pouech | 70342db | 2006-01-03 17:35:01 +0100 | [diff] [blame] | 486 | if (length < abi->NameLength / sizeof(WCHAR)) |
| 487 | { |
| 488 | SetLastError( ERROR_MORE_DATA ); |
| 489 | length = count; |
| 490 | } |
Eric Pouech | dccd41a | 2006-02-06 11:26:57 +0100 | [diff] [blame] | 491 | else if (length < count) buffer[length] = '\0'; |
Eric Pouech | 70342db | 2006-01-03 17:35:01 +0100 | [diff] [blame] | 492 | } |
| 493 | return length; |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | |
| 497 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 498 | * GetAtomNameW (KERNEL32.@) |
Jon Griffiths | 4c1fa16 | 2003-10-01 03:20:21 +0000 | [diff] [blame] | 499 | * |
| 500 | * Unicode version of GetAtomNameA. |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 501 | */ |
| 502 | UINT WINAPI GetAtomNameW( ATOM atom, LPWSTR buffer, INT count ) |
| 503 | { |
Eric Pouech | 70342db | 2006-01-03 17:35:01 +0100 | [diff] [blame] | 504 | NTSTATUS status; |
| 505 | RTL_ATOM_TABLE table; |
| 506 | DWORD length; |
| 507 | WCHAR tmp[MAX_ATOM_LEN + 1]; |
| 508 | |
| 509 | if (count <= 0) |
| 510 | { |
| 511 | SetLastError( ERROR_MORE_DATA ); |
| 512 | return 0; |
| 513 | } |
| 514 | if (!(table = get_local_table( 0 ))) return 0; |
| 515 | length = sizeof(tmp); |
| 516 | status = RtlQueryAtomInAtomTable( table, atom, NULL, NULL, tmp, &length ); |
| 517 | if (status) |
| 518 | { |
| 519 | SetLastError( RtlNtStatusToDosError( status ) ); |
| 520 | return 0; |
| 521 | } |
| 522 | length = min(length, (count - 1) * sizeof(WCHAR)); |
| 523 | if (length) memcpy(buffer, tmp, length); |
| 524 | else SetLastError( ERROR_INSUFFICIENT_BUFFER ); |
| 525 | length /= sizeof(WCHAR); |
| 526 | buffer[length] = '\0'; |
| 527 | return length; |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 528 | } |