Fixed found Valgrind issues.
[rpn.git] / src / psp / error.c
blob3e18adfdf8b530e557539295939c465bfdbc799f
1 /*******************************************************************************
2 * Reverse Polish Notation calculator. *
3 * Copyright (c) 2007-2008, Samuel Fredrickson <kinghajj@gmail.com> *
4 * All rights reserved. *
5 * *
6 * Redistribution and use in source and binary forms, with or without *
7 * modification, are permitted provided that the following conditions are met: *
8 * * Redistributions of source code must retain the above copyright *
9 * notice, this list of conditions and the following disclaimer. *
10 * * Redistributions in binary form must reproduce the above copyright *
11 * notice, this list of conditions and the following disclaimer in the *
12 * documentation and/or other materials provided with the distribution. *
13 * *
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER ``AS IS'' AND ANY EXPRESS *
15 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED *
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
17 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY *
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR *
20 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER *
21 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT *
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY *
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
24 * DAMAGE. *
25 ******************************************************************************/
27 /*******************************************************************************
28 * error.c - an error-handling function; it just prints the error and exits. *
29 * there's also some output code. *
30 ******************************************************************************/
32 #include "rpn.h"
33 #include <stdarg.h>
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <unistd.h>
38 //! Prints an error to the screen, then exits. This is much simpler than the
39 //! normal RPN_error function.
40 /**
41 * @param msg The message to print.
43 void RPN_error(char *msg)
45 kprintf("\nerror: %s\n\nauto-exiting in 10 seconds...", msg);
46 sleep(10);
47 sceKernelExitGame();
50 #ifndef DOXYGEN_SKIP
51 #define RPNPSP_OUTBUF_SIZE 1024
52 char RPNPSP_output_buffer[RPNPSP_OUTBUF_SIZE];
54 static void clearOutputBuffer()
56 int i;
58 for(i = 0; i < RPNPSP_OUTBUF_SIZE; i++)
60 RPNPSP_output_buffer[i] = 0;
63 #endif // DOXYGEN_SKIP
65 //! Prints to the screen.
66 /**
67 * The PSP, as far as I can tell, cannot use normal printf()-family functions.
68 * So, this uses vsprintf to print to a buffer first. This could potentially be
69 * dangerous, so the buffer is fairly large (1024 bytes) to prevent errors. As
70 * long as you don't print anything longer than 1024 characters long, everything
71 * should be fine.
73 * @param fmt The formatting string.
75 int RPN_printf(char *fmt, ...)
77 va_list args;
79 // Always make sure to clear the buffer!
80 clearOutputBuffer();
82 va_start(args, fmt);
83 vsprintf(RPNPSP_output_buffer, fmt, args);
84 kprintf("%s", RPNPSP_output_buffer);
85 return 0;
88 #ifndef DOXYGEN_SKIP
89 #ifdef RPN_DEBUG
90 int RPN_dprintff(char *func, char *fmt, ...)
92 va_list args;
94 // Always make sure to clear the buffer!
95 RPNPSP_clearOutputBuffer();
97 va_start(args, fmt);
98 vsprintf(RPNPSP_output_buffer, fmt, args);
99 kprintf("%s: %s\n", func, RPNPSP_output_buffer);
100 return 0;
102 #endif
103 #endif // DOXYGEN_SKIP