Import upstream u-boot 1.1.4
[u-boot.git] / board / MAI / bios_emulator / scitech / src / pm / tests / save.c
1 /****************************************************************************
2 *
3 *                   SciTech OS Portability Manager Library
4 *
5 *  ========================================================================
6 *
7 *    The contents of this file are subject to the SciTech MGL Public
8 *    License Version 1.0 (the "License"); you may not use this file
9 *    except in compliance with the License. You may obtain a copy of
10 *    the License at http://www.scitechsoft.com/mgl-license.txt
11 *
12 *    Software distributed under the License is distributed on an
13 *    "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
14 *    implied. See the License for the specific language governing
15 *    rights and limitations under the License.
16 *
17 *    The Original Code is Copyright (C) 1991-1998 SciTech Software, Inc.
18 *
19 *    The Initial Developer of the Original Code is SciTech Software, Inc.
20 *    All Rights Reserved.
21 *
22 *  ========================================================================
23 *
24 * Language:     ANSI C
25 * Environment:  Linux/QNX
26 *
27 * Description:  Program to save the console state state so that it can
28 *               be later restored if the program crashed while the console
29 *               was in graphics mode.
30 *
31 ****************************************************************************/
32
33 #include <stdlib.h>
34 #include <stdio.h>
35 #include "pmapi.h"
36
37 int main(void)
38 {
39     PM_HWND hwndConsole;
40     ulong   stateSize;
41     void    *stateBuf;
42     FILE    *f;
43
44     /* Allocate a buffer to save console state and save the state */
45     hwndConsole = PM_openConsole(0,0,0,0,0,true);
46     stateSize = PM_getConsoleStateSize();
47     if ((stateBuf = PM_malloc(stateSize)) == NULL) {
48         PM_closeConsole(hwndConsole);
49         printf("Unable to allocate console state buffer!\n");
50         return -1;
51         }
52     PM_saveConsoleState(stateBuf,0);
53
54     /* Restore the console state on exit */
55     PM_restoreConsoleState(stateBuf,0);
56     PM_closeConsole(hwndConsole);
57
58     /* Write the saved console state buffer to disk */
59     if ((f = fopen("/etc/pmsave.dat","wb")) == NULL)
60         printf("Unable to open /etc/pmsave/dat for writing!\n");
61     else {
62         fwrite(&stateSize,1,sizeof(stateSize),f);
63         fwrite(stateBuf,1,stateSize,f);
64         fclose(f);
65         printf("Console state successfully saved to /etc/pmsave.dat\n");
66         }
67     PM_free(stateBuf);
68     return 0;
69 }