diff options
author | Stefan Reinauer <stefan.reinauer@coreboot.org> | 2015-11-10 09:00:41 -0800 |
---|---|---|
committer | Stefan Reinauer <stefan.reinauer@coreboot.org> | 2015-11-11 21:38:48 +0100 |
commit | 4f85a1eb76d1e7109bcc60ba6f3262a5654ac61b (patch) | |
tree | e996818c6aa6b6f702a6c805c447c20724eff265 /payloads/libpayload/curses/PDCurses/dos/pdcclip.c | |
parent | 2ea24dabd658b8396e0abf79318a538ef0f3a5b8 (diff) |
libpayload: Rename PDCurses-3.4 to PDCurses
Change-Id: If881ec130833c7e7e62caa3d31e350a531f5bc8e
Signed-off-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
Reviewed-on: http://review.coreboot.org/12398
Tested-by: build bot (Jenkins)
Reviewed-by: Patrick Georgi <pgeorgi@google.com>
Diffstat (limited to 'payloads/libpayload/curses/PDCurses/dos/pdcclip.c')
-rw-r--r-- | payloads/libpayload/curses/PDCurses/dos/pdcclip.c | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/payloads/libpayload/curses/PDCurses/dos/pdcclip.c b/payloads/libpayload/curses/PDCurses/dos/pdcclip.c new file mode 100644 index 0000000000..c5fa29108a --- /dev/null +++ b/payloads/libpayload/curses/PDCurses/dos/pdcclip.c @@ -0,0 +1,129 @@ +/* Public Domain Curses */ + +#include "pdcdos.h" + +RCSID("$Id: pdcclip.c,v 1.33 2008/07/13 16:08:17 wmcbrine Exp $") + +#include <stdlib.h> + +/*man-start************************************************************** + + Name: clipboard + + Synopsis: + int PDC_getclipboard(char **contents, long *length); + int PDC_setclipboard(const char *contents, long length); + int PDC_freeclipboard(char *contents); + int PDC_clearclipboard(void); + + Description: + PDC_getclipboard() gets the textual contents of the system's + clipboard. This function returns the contents of the clipboard + in the contents argument. It is the responsibilitiy of the + caller to free the memory returned, via PDC_freeclipboard(). + The length of the clipboard contents is returned in the length + argument. + + PDC_setclipboard copies the supplied text into the system's + clipboard, emptying the clipboard prior to the copy. + + PDC_clearclipboard() clears the internal clipboard. + + Return Values: + indicator of success/failure of call. + PDC_CLIP_SUCCESS the call was successful + PDC_CLIP_MEMORY_ERROR unable to allocate sufficient memory for + the clipboard contents + PDC_CLIP_EMPTY the clipboard contains no text + PDC_CLIP_ACCESS_ERROR no clipboard support + + Portability X/Open BSD SYS V + PDC_getclipboard - - - + PDC_setclipboard - - - + PDC_freeclipboard - - - + PDC_clearclipboard - - - + +**man-end****************************************************************/ + +/* global clipboard contents, should be NULL if none set */ + +static char *pdc_DOS_clipboard = NULL; + +int PDC_getclipboard(char **contents, long *length) +{ + int len; + + PDC_LOG(("PDC_getclipboard() - called\n")); + + if (!pdc_DOS_clipboard) + return PDC_CLIP_EMPTY; + + len = strlen(pdc_DOS_clipboard); + if ((*contents = malloc(len + 1)) == NULL) + return PDC_CLIP_MEMORY_ERROR; + + strcpy(*contents, pdc_DOS_clipboard); + *length = len; + + return PDC_CLIP_SUCCESS; +} + +int PDC_setclipboard(const char *contents, long length) +{ + PDC_LOG(("PDC_setclipboard() - called\n")); + + if (pdc_DOS_clipboard) + { + free(pdc_DOS_clipboard); + pdc_DOS_clipboard = NULL; + } + + if (contents) + { + if ((pdc_DOS_clipboard = malloc(length + 1)) == NULL) + return PDC_CLIP_MEMORY_ERROR; + + strcpy(pdc_DOS_clipboard, contents); + } + + return PDC_CLIP_SUCCESS; +} + +int PDC_freeclipboard(char *contents) +{ + PDC_LOG(("PDC_freeclipboard() - called\n")); + + /* should we also free empty the system clipboard? probably not */ + + if (contents) + { + + /* NOTE: We free the memory, but we can not set caller's pointer + to NULL, so if caller calls again then will try to access + free'd memory. We 1st overwrite memory with a string so if + caller tries to use free memory they won't get what they + expect & hopefully notice. */ + + /* memset(contents, 0xFD, strlen(contents)); */ + + if (strlen(contents) >= strlen("PDCURSES")) + strcpy(contents, "PDCURSES"); + + free(contents); + } + + return PDC_CLIP_SUCCESS; +} + +int PDC_clearclipboard(void) +{ + PDC_LOG(("PDC_clearclipboard() - called\n")); + + if (pdc_DOS_clipboard) + { + free(pdc_DOS_clipboard); + pdc_DOS_clipboard = NULL; + } + + return PDC_CLIP_SUCCESS; +} |