1 /***************************************************************************
2  * Copyright (c) 2024 Microsoft Corporation
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the MIT License which is available at
6  * https://opensource.org/licenses/MIT.
7  *
8  * SPDX-License-Identifier: MIT
9  **************************************************************************/
10 
11 
12 /**************************************************************************/
13 /**************************************************************************/
14 /**                                                                       */
15 /** GUIX Component                                                        */
16 /**                                                                       */
17 /**   System Management (System)                                          */
18 /**                                                                       */
19 /**************************************************************************/
20 
21 #define GX_SOURCE_CODE
22 
23 
24 /* Include necessary system files.  */
25 
26 #include "gx_api.h"
27 #include "gx_system.h"
28 
29 
30 /**************************************************************************/
31 /*                                                                        */
32 /*  FUNCTION                                               RELEASE        */
33 /*                                                                        */
34 /*    _gx_system_clipboard_put                            PORTABLE C      */
35 /*                                                           6.1          */
36 /*  AUTHOR                                                                */
37 /*                                                                        */
38 /*    Kenneth Maxwell, Microsoft Corporation                              */
39 /*                                                                        */
40 /*  DESCRIPTION                                                           */
41 /*                                                                        */
42 /*    This service puts data to clipboard.                                */
43 /*                                                                        */
44 /*  INPUT                                                                 */
45 /*                                                                        */
46 /*    data                                  Pointer the copied data       */
47 /*    data_size                             The number of bytes to copy   */
48 /*                                                                        */
49 /*  OUTPUT                                                                */
50 /*                                                                        */
51 /*    status                                Completion status             */
52 /*                                                                        */
53 /*  CALLS                                                                 */
54 /*                                                                        */
55 /*    _gx_system_memory_allocator           Application defined memory    */
56 /*                                            allocation function         */
57 /*    _gx_system_memory_free                Application defined memory    */
58 /*                                            free function               */
59 /*                                                                        */
60 /*  CALLED BY                                                             */
61 /*                                                                        */
62 /*    GUIX Internal Code                                                  */
63 /*                                                                        */
64 /*  RELEASE HISTORY                                                       */
65 /*                                                                        */
66 /*    DATE              NAME                      DESCRIPTION             */
67 /*                                                                        */
68 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
69 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
70 /*                                            resulting in version 6.1    */
71 /*                                                                        */
72 /**************************************************************************/
_gx_system_clipboard_put(VOID * data,UINT data_size)73 UINT  _gx_system_clipboard_put(VOID *data, UINT data_size)
74 {
75 
76     if ((!_gx_system_memory_allocator) ||
77         (!_gx_system_memory_free))
78     {
79         return GX_SYSTEM_MEMORY_ERROR;
80     }
81 
82     if (_gx_system_clipboard)
83     {
84         _gx_system_memory_free(_gx_system_clipboard);
85     }
86 
87     _gx_system_clipboard = _gx_system_memory_allocator(data_size);
88 
89     /* Verify the memory allocation was successful. */
90     if(_gx_system_clipboard == GX_NULL)
91     {
92         return GX_SYSTEM_MEMORY_ERROR;
93     }
94 
95     _gx_system_clipboard_size = data_size;
96 
97     memcpy(_gx_system_clipboard, data, data_size); /* Use case of memcpy is verified. */
98 
99     return(GX_SUCCESS);
100 }
101 
102