Moved all references to file descriptors out of the generic object
[wine] / memory / atom.c
1 /*
2  * Atom table functions
3  *
4  * Copyright 1993, 1994, 1995 Alexandre Julliard
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
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 /*
22  * Warning: The code assumes that LocalAlloc() returns a block aligned
23  * on a 4-bytes boundary (because of the shifting done in
24  * HANDLETOATOM).  If this is not the case, the allocation code will
25  * have to be changed.
26  */
27
28 #include "config.h"
29 #include "wine/port.h"
30
31 #include <stdlib.h>
32 #include <stdio.h>
33 #include <string.h>
34 #include <ctype.h>
35
36 #include "windef.h"
37 #include "winbase.h"
38 #include "winerror.h"
39
40 #include "wine/server.h"
41 #include "wine/unicode.h"
42 #include "wine/winbase16.h"
43 #include "global.h"
44 #include "instance.h"
45 #include "stackframe.h"
46
47 #include "wine/debug.h"
48
49 WINE_DEFAULT_DEBUG_CHANNEL(atom);
50
51 #define DEFAULT_ATOMTABLE_SIZE    37
52 #define MAX_ATOM_LEN              255
53
54 #define ATOMTOHANDLE(atom)        ((HANDLE16)(atom) << 2)
55 #define HANDLETOATOM(handle)      ((ATOM)(0xc000 | ((handle) >> 2)))
56
57 typedef struct
58 {
59     HANDLE16    next;
60     WORD        refCount;
61     BYTE        length;
62     BYTE        str[1];
63 } ATOMENTRY;
64
65 typedef struct
66 {
67     WORD        size;
68     HANDLE16    entries[1];
69 } ATOMTABLE;
70
71
72 /***********************************************************************
73  *           ATOM_GetTable
74  *
75  * Return a pointer to the atom table of a given segment, creating
76  * it if necessary.
77  *
78  * RETURNS
79  *      Pointer to table: Success
80  *      NULL: Failure
81  */
82 static ATOMTABLE *ATOM_GetTable( BOOL create  /* [in] Create */ )
83 {
84     INSTANCEDATA *ptr = MapSL( MAKESEGPTR( CURRENT_DS, 0 ) );
85     if (ptr->atomtable)
86     {
87         ATOMTABLE *table = (ATOMTABLE *)((char *)ptr + ptr->atomtable);
88         if (table->size) return table;
89     }
90     if (!create) return NULL;
91     if (!InitAtomTable16( 0 )) return NULL;
92     /* Reload ptr in case it moved in linear memory */
93     ptr = MapSL( MAKESEGPTR( CURRENT_DS, 0 ) );
94     return (ATOMTABLE *)((char *)ptr + ptr->atomtable);
95 }
96
97
98 /***********************************************************************
99  *           ATOM_Hash
100  * RETURNS
101  *      The hash value for the input string
102  */
103 static WORD ATOM_Hash(
104             WORD entries, /* [in] Total number of entries */
105             LPCSTR str,   /* [in] Pointer to string to hash */
106             WORD len      /* [in] Length of string */
107 ) {
108     WORD i, hash = 0;
109
110     TRACE("%x, %s, %x\n", entries, str, len);
111
112     for (i = 0; i < len; i++) hash ^= toupper(str[i]) + i;
113     return hash % entries;
114 }
115
116
117 /***********************************************************************
118  *           ATOM_IsIntAtomA
119  */
120 static BOOL ATOM_IsIntAtomA(LPCSTR atomstr,WORD *atomid)
121 {
122     UINT atom = 0;
123     if (!HIWORD(atomstr)) atom = LOWORD(atomstr);
124     else
125     {
126         if (*atomstr++ != '#') return FALSE;
127         while (*atomstr >= '0' && *atomstr <= '9')
128         {
129             atom = atom * 10 + *atomstr - '0';
130             atomstr++;
131         }
132         if (*atomstr) return FALSE;
133     }
134     if (atom >= MAXINTATOM)
135     {
136         SetLastError( ERROR_INVALID_PARAMETER );
137         atom = 0;
138     }
139     *atomid = atom;
140     return TRUE;
141 }
142
143
144 /***********************************************************************
145  *           ATOM_IsIntAtomW
146  */
147 static BOOL ATOM_IsIntAtomW(LPCWSTR atomstr,WORD *atomid)
148 {
149     UINT atom = 0;
150     if (!HIWORD(atomstr)) atom = LOWORD(atomstr);
151     else
152     {
153         if (*atomstr++ != '#') return FALSE;
154         while (*atomstr >= '0' && *atomstr <= '9')
155         {
156             atom = atom * 10 + *atomstr - '0';
157             atomstr++;
158         }
159         if (*atomstr) return FALSE;
160     }
161     if (atom >= MAXINTATOM)
162     {
163         SetLastError( ERROR_INVALID_PARAMETER );
164         atom = 0;
165     }
166     *atomid = atom;
167     return TRUE;
168 }
169
170
171 /***********************************************************************
172  *           ATOM_MakePtr
173  *
174  * Make an ATOMENTRY pointer from a handle (obtained from GetAtomHandle()).
175  */
176 static inline ATOMENTRY *ATOM_MakePtr( HANDLE16 handle /* [in] Handle */ )
177 {
178     return MapSL( MAKESEGPTR( CURRENT_DS, handle ) );
179 }
180
181
182 /***********************************************************************
183  *           InitAtomTable   (KERNEL.68)
184  */
185 WORD WINAPI InitAtomTable16( WORD entries )
186 {
187     int i;
188     HANDLE16 handle;
189     ATOMTABLE *table;
190
191       /* Allocate the table */
192
193     if (!entries) entries = DEFAULT_ATOMTABLE_SIZE;  /* sanity check */
194     handle = LocalAlloc16( LMEM_FIXED, sizeof(ATOMTABLE) + (entries-1) * sizeof(HANDLE16) );
195     if (!handle) return 0;
196     table = MapSL( MAKESEGPTR( CURRENT_DS, handle ) );
197     table->size = entries;
198     for (i = 0; i < entries; i++) table->entries[i] = 0;
199
200       /* Store a pointer to the table in the instance data */
201
202     ((INSTANCEDATA *)MapSL( MAKESEGPTR( CURRENT_DS, 0 )))->atomtable = handle;
203     return handle;
204 }
205
206 /***********************************************************************
207  *           GetAtomHandle   (KERNEL.73)
208  */
209 HANDLE16 WINAPI GetAtomHandle16( ATOM atom )
210 {
211     if (atom < MAXINTATOM) return 0;
212     return ATOMTOHANDLE( atom );
213 }
214
215
216 /***********************************************************************
217  *           AddAtom   (KERNEL.70)
218  *
219  * Windows DWORD aligns the atom entry size.
220  * The remaining unused string space created by the alignment
221  * gets padded with '\0's in a certain way to ensure
222  * that at least one trailing '\0' remains.
223  *
224  * RETURNS
225  *      Atom: Success
226  *      0: Failure
227  */
228 ATOM WINAPI AddAtom16( LPCSTR str )
229 {
230     char buffer[MAX_ATOM_LEN+1];
231     WORD hash;
232     HANDLE16 entry;
233     ATOMENTRY * entryPtr;
234     ATOMTABLE * table;
235     int len, ae_len;
236     WORD        iatom;
237
238     if (ATOM_IsIntAtomA( str, &iatom )) return iatom;
239
240     TRACE("%s\n",debugstr_a(buffer));
241
242     /* Make a copy of the string to be sure it doesn't move in linear memory. */
243     lstrcpynA( buffer, str, sizeof(buffer) );
244
245     len = strlen( buffer );
246     if (!(table = ATOM_GetTable( TRUE ))) return 0;
247
248     hash = ATOM_Hash( table->size, buffer, len );
249     entry = table->entries[hash];
250     while (entry)
251     {
252         entryPtr = ATOM_MakePtr( entry );
253         if ((entryPtr->length == len) &&
254             (!strncasecmp( entryPtr->str, buffer, len )))
255         {
256             entryPtr->refCount++;
257             TRACE("-- existing 0x%x\n", entry);
258             return HANDLETOATOM( entry );
259         }
260         entry = entryPtr->next;
261     }
262
263     ae_len = (sizeof(ATOMENTRY)+len+3) & ~3;
264     entry = LocalAlloc16( LMEM_FIXED, ae_len );
265     if (!entry) return 0;
266     /* Reload the table ptr in case it moved in linear memory */
267     table = ATOM_GetTable( FALSE );
268     entryPtr = ATOM_MakePtr( entry );
269     entryPtr->next = table->entries[hash];
270     entryPtr->refCount = 1;
271     entryPtr->length = len;
272     /* Some applications _need_ the '\0' padding provided by this strncpy */
273     strncpy( entryPtr->str, buffer, ae_len - sizeof(ATOMENTRY) + 1 );
274     entryPtr->str[ae_len - sizeof(ATOMENTRY)] = '\0';
275     table->entries[hash] = entry;
276     TRACE("-- new 0x%x\n", entry);
277     return HANDLETOATOM( entry );
278 }
279
280
281 /***********************************************************************
282  *           DeleteAtom   (KERNEL.71)
283  */
284 ATOM WINAPI DeleteAtom16( ATOM atom )
285 {
286     ATOMENTRY * entryPtr;
287     ATOMTABLE * table;
288     HANDLE16 entry, *prevEntry;
289     WORD hash;
290
291     if (atom < MAXINTATOM) return 0;  /* Integer atom */
292
293     TRACE("0x%x\n",atom);
294
295     if (!(table = ATOM_GetTable( FALSE ))) return 0;
296     entry = ATOMTOHANDLE( atom );
297     entryPtr = ATOM_MakePtr( entry );
298
299     /* Find previous atom */
300     hash = ATOM_Hash( table->size, entryPtr->str, entryPtr->length );
301     prevEntry = &table->entries[hash];
302     while (*prevEntry && *prevEntry != entry)
303     {
304         ATOMENTRY * prevEntryPtr = ATOM_MakePtr( *prevEntry );
305         prevEntry = &prevEntryPtr->next;
306     }
307     if (!*prevEntry) return atom;
308
309     /* Delete atom */
310     if (--entryPtr->refCount == 0)
311     {
312         *prevEntry = entryPtr->next;
313         LocalFree16( entry );
314     }
315     return 0;
316 }
317
318
319 /***********************************************************************
320  *           FindAtom   (KERNEL.69)
321  */
322 ATOM WINAPI FindAtom16( LPCSTR str )
323 {
324     ATOMTABLE * table;
325     WORD hash,iatom;
326     HANDLE16 entry;
327     int len;
328
329     TRACE("%s\n",debugstr_a(str));
330
331     if (ATOM_IsIntAtomA( str, &iatom )) return iatom;
332     if ((len = strlen( str )) > 255) len = 255;
333     if (!(table = ATOM_GetTable( FALSE ))) return 0;
334     hash = ATOM_Hash( table->size, str, len );
335     entry = table->entries[hash];
336     while (entry)
337     {
338         ATOMENTRY * entryPtr = ATOM_MakePtr( entry );
339         if ((entryPtr->length == len) &&
340             (!strncasecmp( entryPtr->str, str, len )))
341         {
342             TRACE("-- found %x\n", entry);
343             return HANDLETOATOM( entry );
344         }
345         entry = entryPtr->next;
346     }
347     TRACE("-- not found\n");
348     return 0;
349 }
350
351
352 /***********************************************************************
353  *           GetAtomName   (KERNEL.72)
354  */
355 UINT16 WINAPI GetAtomName16( ATOM atom, LPSTR buffer, INT16 count )
356 {
357     ATOMTABLE * table;
358     ATOMENTRY * entryPtr;
359     HANDLE16 entry;
360     char * strPtr;
361     UINT len;
362     char text[8];
363
364     TRACE("%x\n",atom);
365
366     if (!count) return 0;
367     if (atom < MAXINTATOM)
368     {
369         sprintf( text, "#%d", atom );
370         len = strlen(text);
371         strPtr = text;
372     }
373     else
374     {
375        if (!(table = ATOM_GetTable( FALSE ))) return 0;
376         entry = ATOMTOHANDLE( atom );
377         entryPtr = ATOM_MakePtr( entry );
378         len = entryPtr->length;
379         strPtr = entryPtr->str;
380     }
381     if (len >= count) len = count-1;
382     memcpy( buffer, strPtr, len );
383     buffer[len] = '\0';
384     return len;
385 }
386
387 /***********************************************************************
388  *           InitAtomTable   (KERNEL32.@)
389  */
390 BOOL WINAPI InitAtomTable( DWORD entries )
391 {
392     BOOL ret;
393     SERVER_START_REQ( init_atom_table )
394     {
395         req->entries = entries;
396         ret = !wine_server_call_err( req );
397     }
398     SERVER_END_REQ;
399     return ret;
400 }
401
402
403 static ATOM ATOM_AddAtomA( LPCSTR str, BOOL local )
404 {
405     ATOM atom = 0;
406     if (!ATOM_IsIntAtomA( str, &atom ))
407     {
408         WCHAR buffer[MAX_ATOM_LEN];
409
410         DWORD len = MultiByteToWideChar( CP_ACP, 0, str, strlen(str), buffer, MAX_ATOM_LEN );
411         if (!len)
412         {
413             SetLastError( ERROR_INVALID_PARAMETER );
414             return 0;
415         }
416         SERVER_START_REQ( add_atom )
417         {
418             wine_server_add_data( req, buffer, len * sizeof(WCHAR) );
419             req->local = local;
420             if (!wine_server_call_err(req)) atom = reply->atom;
421         }
422         SERVER_END_REQ;
423     }
424     TRACE( "(%s) %s -> %x\n", local ? "local" : "global", debugstr_a(str), atom );
425     return atom;
426 }
427
428
429 /***********************************************************************
430  *           GlobalAddAtomA   (KERNEL32.@)
431  *
432  * Adds a character string to the global atom table and returns a unique
433  * value identifying the string.
434  *
435  * RETURNS
436  *      Atom: Success
437  *      0: Failure
438  */
439 ATOM WINAPI GlobalAddAtomA( LPCSTR str /* [in] Pointer to string to add */ )
440 {
441     return ATOM_AddAtomA( str, FALSE );
442 }
443
444
445 /***********************************************************************
446  *           AddAtomA   (KERNEL32.@)
447  * Adds a string to the atom table and returns the atom identifying the
448  * string.
449  *
450  * RETURNS
451  *      Atom: Success
452  *      0: Failure
453  */
454 ATOM WINAPI AddAtomA( LPCSTR str /* [in] Pointer to string to add */ )
455 {
456     return ATOM_AddAtomA( str, TRUE );
457 }
458
459
460 static ATOM ATOM_AddAtomW( LPCWSTR str, BOOL local )
461 {
462     ATOM atom = 0;
463     if (!ATOM_IsIntAtomW( str, &atom ))
464     {
465         DWORD len = strlenW(str);
466         if (len > MAX_ATOM_LEN)
467         {
468             SetLastError( ERROR_INVALID_PARAMETER );
469             return 0;
470         }
471         SERVER_START_REQ( add_atom )
472         {
473             req->local = local;
474             wine_server_add_data( req, str, len * sizeof(WCHAR) );
475             if (!wine_server_call_err(req)) atom = reply->atom;
476         }
477         SERVER_END_REQ;
478     }
479     TRACE( "(%s) %s -> %x\n", local ? "local" : "global", debugstr_w(str), atom );
480     return atom;
481 }
482
483
484 /***********************************************************************
485  *           GlobalAddAtomW   (KERNEL32.@)
486  */
487 ATOM WINAPI GlobalAddAtomW( LPCWSTR str )
488 {
489     return ATOM_AddAtomW( str, FALSE );
490 }
491
492
493 /***********************************************************************
494  *           AddAtomW   (KERNEL32.@)
495  */
496 ATOM WINAPI AddAtomW( LPCWSTR str )
497 {
498     return ATOM_AddAtomW( str, TRUE );
499 }
500
501
502 static ATOM ATOM_DeleteAtom( ATOM atom,  BOOL local)
503 {
504     TRACE( "(%s) %x\n", local ? "local" : "global", atom );
505     if (atom >= MAXINTATOM)
506     {
507         SERVER_START_REQ( delete_atom )
508         {
509             req->atom = atom;
510             req->local = local;
511             wine_server_call_err( req );
512         }
513         SERVER_END_REQ;
514     }
515     return 0;
516 }
517
518
519 /***********************************************************************
520  *           GlobalDeleteAtom   (KERNEL32.@)
521  * Decrements the reference count of a string atom.  If the count is
522  * zero, the string associated with the atom is removed from the table.
523  *
524  * RETURNS
525  *      0: Success
526  *      Atom: Failure
527  */
528 ATOM WINAPI GlobalDeleteAtom( ATOM atom /* [in] Atom to delete */ )
529 {
530     return ATOM_DeleteAtom( atom, FALSE);
531 }
532
533
534 /***********************************************************************
535  *           DeleteAtom   (KERNEL32.@)
536  * Decrements the reference count of a string atom.  If count becomes
537  * zero, the string associated with the atom is removed from the table.
538  *
539  * RETURNS
540  *      0: Success
541  *      Atom: Failure
542  */
543 ATOM WINAPI DeleteAtom( ATOM atom /* [in] Atom to delete */ )
544 {
545     return ATOM_DeleteAtom( atom, TRUE );
546 }
547
548
549 static ATOM ATOM_FindAtomA( LPCSTR str, BOOL local )
550 {
551     ATOM atom = 0;
552     if (!ATOM_IsIntAtomA( str, &atom ))
553     {
554         WCHAR buffer[MAX_ATOM_LEN];
555
556         DWORD len = MultiByteToWideChar( CP_ACP, 0, str, strlen(str), buffer, MAX_ATOM_LEN );
557         if (!len)
558         {
559             SetLastError( ERROR_INVALID_PARAMETER );
560             return 0;
561         }
562         SERVER_START_REQ( find_atom )
563         {
564             req->local = local;
565             wine_server_add_data( req, buffer, len * sizeof(WCHAR) );
566             if (!wine_server_call_err(req)) atom = reply->atom;
567         }
568         SERVER_END_REQ;
569     }
570     TRACE( "(%s) %s -> %x\n", local ? "local" : "global", debugstr_a(str), atom );
571     return atom;
572 }
573
574
575 /***********************************************************************
576  *           GlobalFindAtomA   (KERNEL32.@)
577  *
578  * Searches the atom table for the string and returns the atom
579  * associated with it.
580  *
581  * RETURNS
582  *      Atom: Success
583  *      0: Failure
584  */
585 ATOM WINAPI GlobalFindAtomA( LPCSTR str /* [in] Pointer to string to search for */ )
586 {
587     return ATOM_FindAtomA( str, FALSE );
588 }
589
590 /***********************************************************************
591  *           FindAtomA   (KERNEL32.@)
592  * Searches the local atom table for the string and returns the atom
593  * associated with that string.
594  *
595  * RETURNS
596  *      Atom: Success
597  *      0: Failure
598  */
599 ATOM WINAPI FindAtomA( LPCSTR str /* [in] Pointer to string to find */ )
600 {
601     return ATOM_FindAtomA( str, TRUE );
602 }
603
604
605 static ATOM ATOM_FindAtomW( LPCWSTR str, BOOL local )
606 {
607     ATOM atom = 0;
608     if (!ATOM_IsIntAtomW( str, &atom ))
609     {
610         DWORD len = strlenW(str);
611         if (len > MAX_ATOM_LEN)
612         {
613             SetLastError( ERROR_INVALID_PARAMETER );
614             return 0;
615         }
616         SERVER_START_REQ( find_atom )
617         {
618             wine_server_add_data( req, str, len * sizeof(WCHAR) );
619             req->local = local;
620             if (!wine_server_call_err( req )) atom = reply->atom;
621         }
622         SERVER_END_REQ;
623     }
624     TRACE( "(%s) %s -> %x\n", local ? "local" : "global", debugstr_w(str), atom );
625     return atom;
626 }
627
628
629 /***********************************************************************
630  *           GlobalFindAtomW   (KERNEL32.@)
631  */
632 ATOM WINAPI GlobalFindAtomW( LPCWSTR str )
633 {
634     return ATOM_FindAtomW( str, FALSE );
635 }
636
637
638 /***********************************************************************
639  *           FindAtomW   (KERNEL32.@)
640  */
641 ATOM WINAPI FindAtomW( LPCWSTR str )
642 {
643     return ATOM_FindAtomW( str, TRUE );
644 }
645
646
647 static UINT ATOM_GetAtomNameA( ATOM atom, LPSTR buffer, INT count, BOOL local )
648 {
649     INT len;
650
651     if (count <= 0)
652     {
653         SetLastError( ERROR_MORE_DATA );
654         return 0;
655     }
656     if (atom < MAXINTATOM)
657     {
658         char name[8];
659         if (!atom)
660         {
661             SetLastError( ERROR_INVALID_PARAMETER );
662             return 0;
663         }
664         len = sprintf( name, "#%d", atom );
665         lstrcpynA( buffer, name, count );
666     }
667     else
668     {
669         WCHAR full_name[MAX_ATOM_LEN];
670
671         len = 0;
672         SERVER_START_REQ( get_atom_name )
673         {
674             req->atom = atom;
675             req->local = local;
676             wine_server_set_reply( req, full_name, sizeof(full_name) );
677             if (!wine_server_call_err( req ))
678             {
679                 len = WideCharToMultiByte( CP_ACP, 0, full_name,
680                                            wine_server_reply_size(reply) / sizeof(WCHAR),
681                                            buffer, count - 1, NULL, NULL );
682                 if (!len) len = count; /* overflow */
683                 else buffer[len] = 0;
684             }
685         }
686         SERVER_END_REQ;
687     }
688
689     if (len && count <= len)
690     {
691         SetLastError( ERROR_MORE_DATA );
692         buffer[count-1] = 0;
693         return 0;
694     }
695     TRACE( "(%s) %x -> %s\n", local ? "local" : "global", atom, debugstr_a(buffer) );
696     return len;
697 }
698
699
700 /***********************************************************************
701  *           GlobalGetAtomNameA   (KERNEL32.@)
702  *
703  * Retrieves a copy of the string associated with an atom.
704  *
705  * RETURNS
706  *      Length of string in characters: Success
707  *      0: Failure
708  */
709 UINT WINAPI GlobalGetAtomNameA(
710               ATOM atom,    /* [in]  Atom identifier */
711               LPSTR buffer, /* [out] Pointer to buffer for atom string */
712               INT count )   /* [in]  Size of buffer */
713 {
714     return ATOM_GetAtomNameA( atom, buffer, count, FALSE );
715 }
716
717
718 /***********************************************************************
719  *           GetAtomNameA   (KERNEL32.@)
720  * Retrieves a copy of the string associated with the atom.
721  *
722  * RETURNS
723  *      Length of string: Success
724  *      0: Failure
725  */
726 UINT WINAPI GetAtomNameA(
727               ATOM atom,    /* [in]  Atom */
728               LPSTR buffer, /* [out] Pointer to string for atom string */
729               INT count)    /* [in]  Size of buffer */
730 {
731     return ATOM_GetAtomNameA( atom, buffer, count, TRUE );
732 }
733
734
735 static UINT ATOM_GetAtomNameW( ATOM atom, LPWSTR buffer, INT count, BOOL local )
736 {
737     INT len;
738
739     if (count <= 0)
740     {
741         SetLastError( ERROR_MORE_DATA );
742         return 0;
743     }
744     if (atom < MAXINTATOM)
745     {
746         char name[8];
747         if (!atom)
748         {
749             SetLastError( ERROR_INVALID_PARAMETER );
750             return 0;
751         }
752         sprintf( name, "#%d", atom );
753         len = MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, count );
754         if (!len) buffer[count-1] = 0;  /* overflow */
755     }
756     else
757     {
758         WCHAR full_name[MAX_ATOM_LEN];
759
760         len = 0;
761         SERVER_START_REQ( get_atom_name )
762         {
763             req->atom = atom;
764             req->local = local;
765             wine_server_set_reply( req, full_name, sizeof(full_name) );
766             if (!wine_server_call_err( req ))
767             {
768                 len = wine_server_reply_size(reply) / sizeof(WCHAR);
769                 if (count > len) count = len + 1;
770                 memcpy( buffer, full_name, (count-1) * sizeof(WCHAR) );
771                 buffer[count-1] = 0;
772             }
773         }
774         SERVER_END_REQ;
775         if (!len) return 0;
776     }
777     TRACE( "(%s) %x -> %s\n", local ? "local" : "global", atom, debugstr_w(buffer) );
778     return len;
779 }
780
781
782 /***********************************************************************
783  *           GlobalGetAtomNameW   (KERNEL32.@)
784  */
785 UINT WINAPI GlobalGetAtomNameW( ATOM atom, LPWSTR buffer, INT count )
786 {
787     return ATOM_GetAtomNameW( atom, buffer, count, FALSE);
788 }
789
790
791 /***********************************************************************
792  *           GetAtomNameW   (KERNEL32.@)
793  */
794 UINT WINAPI GetAtomNameW( ATOM atom, LPWSTR buffer, INT count )
795 {
796     return ATOM_GetAtomNameW( atom, buffer, count, TRUE );
797 }