FreeNOS
StdioLog.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Niek Linnenbank
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef __HOST__
19 #include <FreeNOS/User.h>
20 #endif /* __HOST__ */
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <unistd.h>
24 #include <string.h>
25 #include "StdioLog.h"
26 
28 {
29 }
30 
31 void StdioLog::write(const char *str)
32 {
33  const ssize_t result = ::write(1, str, strlen(str));
34 
35  // We do not really care about this result. Writing to standard
36  // output is either working or not. If this fails, a higher-level
37  // test and/or assert will catch the error.
38  (void) result;
39 }
40 
41 void StdioLog::terminate() const
42 {
43 #ifndef __HOST__
44  PrivExec(Panic);
45 #endif /* __HOST__ */
47 }
EXIT_FAILURE
#define EXIT_FAILURE
Unsuccessful termination.
Definition: stdlib.h:36
StdioLog::StdioLog
StdioLog()
Constructor.
Definition: StdioLog.cpp:27
strlen
size_t strlen(const char *str)
Calculate the length of a string.
Definition: strlen.cpp:21
string.h
Panic
@ Panic
Definition: PrivExec.h:40
PrivExec
API::Result PrivExec(const PrivOperation op, const Address param=0)
Prototype for user applications.
Definition: PrivExec.h:52
StdioLog::terminate
virtual void terminate() const
Terminate the program using exit()
Definition: StdioLog.cpp:41
Log
Logging class.
Definition: Log.h:96
StdioLog.h
stdio.h
unistd.h
StdioLog::write
virtual void write(const char *str)
Write to the standard output.
Definition: StdioLog.cpp:31
ssize_t
slong ssize_t
Used for a count of bytes or an error indication.
Definition: types.h:38
stdlib.h
exit
C void exit(int status)
Terminate a process.
Definition: exit.cpp:21