drivers/wifi: Remove unnecessary data structure copy
[coreboot2.git] / payloads / libpayload / curses / PDCurses / win32 / pdcclip.c
blob4feefaee0de3bd43a32c55e92207f99eb7a93f37
1 /* Public Domain Curses */
3 #include "pdcwin.h"
5 RCSID("$Id: pdcclip.c,v 1.30 2008/07/14 04:24:52 wmcbrine Exp $")
7 /*man-start**************************************************************
9 Name: clipboard
11 Synopsis:
12 int PDC_getclipboard(char **contents, long *length);
13 int PDC_setclipboard(const char *contents, long length);
14 int PDC_freeclipboard(char *contents);
15 int PDC_clearclipboard(void);
17 Description:
18 PDC_getclipboard() gets the textual contents of the system's
19 clipboard. This function returns the contents of the clipboard
20 in the contents argument. It is the responsibilitiy of the
21 caller to free the memory returned, via PDC_freeclipboard().
22 The length of the clipboard contents is returned in the length
23 argument.
25 PDC_setclipboard copies the supplied text into the system's
26 clipboard, emptying the clipboard prior to the copy.
28 PDC_clearclipboard() clears the internal clipboard.
30 Return Values:
31 indicator of success/failure of call.
32 PDC_CLIP_SUCCESS the call was successful
33 PDC_CLIP_MEMORY_ERROR unable to allocate sufficient memory for
34 the clipboard contents
35 PDC_CLIP_EMPTY the clipboard contains no text
36 PDC_CLIP_ACCESS_ERROR no clipboard support
38 Portability X/Open BSD SYS V
39 PDC_getclipboard - - -
40 PDC_setclipboard - - -
41 PDC_freeclipboard - - -
42 PDC_clearclipboard - - -
44 **man-end****************************************************************/
46 #ifdef PDC_WIDE
47 # define PDC_TEXT CF_UNICODETEXT
48 #else
49 # define PDC_TEXT CF_OEMTEXT
50 #endif
52 int PDC_getclipboard(char **contents, long *length)
54 HANDLE handle;
55 long len;
57 PDC_LOG(("PDC_getclipboard() - called\n"));
59 if (!OpenClipboard(NULL))
60 return PDC_CLIP_ACCESS_ERROR;
62 if ((handle = GetClipboardData(PDC_TEXT)) == NULL)
64 CloseClipboard();
65 return PDC_CLIP_EMPTY;
68 #ifdef PDC_WIDE
69 len = wcslen((wchar_t *)handle) * 3;
70 #else
71 len = strlen((char *)handle);
72 #endif
73 *contents = (char *)GlobalAlloc(GMEM_FIXED, len + 1);
75 if (!*contents)
77 CloseClipboard();
78 return PDC_CLIP_MEMORY_ERROR;
81 #ifdef PDC_WIDE
82 len = PDC_wcstombs((char *)*contents, (wchar_t *)handle, len);
83 #else
84 strcpy((char *)*contents, (char *)handle);
85 #endif
86 *length = len;
87 CloseClipboard();
89 return PDC_CLIP_SUCCESS;
92 int PDC_setclipboard(const char *contents, long length)
94 HGLOBAL ptr1;
95 LPTSTR ptr2;
97 PDC_LOG(("PDC_setclipboard() - called\n"));
99 if (!OpenClipboard(NULL))
100 return PDC_CLIP_ACCESS_ERROR;
102 ptr1 = GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE,
103 (length + 1) * sizeof(TCHAR));
105 if (!ptr1)
106 return PDC_CLIP_MEMORY_ERROR;
108 ptr2 = GlobalLock(ptr1);
110 #ifdef PDC_WIDE
111 PDC_mbstowcs((wchar_t *)ptr2, contents, length);
112 #else
113 memcpy((char *)ptr2, contents, length + 1);
114 #endif
115 GlobalUnlock(ptr1);
116 EmptyClipboard();
118 if (!SetClipboardData(PDC_TEXT, ptr1))
120 GlobalFree(ptr1);
121 return PDC_CLIP_ACCESS_ERROR;
124 CloseClipboard();
125 GlobalFree(ptr1);
127 return PDC_CLIP_SUCCESS;
130 int PDC_freeclipboard(char *contents)
132 PDC_LOG(("PDC_freeclipboard() - called\n"));
134 GlobalFree(contents);
135 return PDC_CLIP_SUCCESS;
138 int PDC_clearclipboard(void)
140 PDC_LOG(("PDC_clearclipboard() - called\n"));
142 EmptyClipboard();
144 return PDC_CLIP_SUCCESS;