Debian Codegraph @

ddio/lnxio.cpp

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 --- HISTORICAL COMMENTS FOLLOW ---
19
20 * $Logfile: /DescentIII/Main/ddio_lnx/lnxio.cpp $
21 * $Revision: 1.6 $
22 * $Date: 2004/02/25 00:04:06 $
23 * $Author: ryan $
24 *
25 * Linux IO routines
26 *
27 * $Log: lnxio.cpp,v $
28 * Revision 1.6 2004/02/25 00:04:06 ryan
29 * Removed loki_utils dependency and ported to MacOS X (runs, but incomplete).
30 *
31 * Revision 1.5 2000/05/29 05:20:13 icculus
32 * Removed a real repetitive mprintf().
33 *
34 * Revision 1.4 2000/05/29 05:19:17 icculus
35 * Serial behaviour is now correct (and the Rock'n'Ride works!). A
36 * little more debugging code was added.
37 *
38 * Revision 1.3 2000/04/25 06:10:27 icculus
39 * Added buttloads of debug information, and fixed some more glitches.
40 *
41 * Revision 1.2 2000/04/24 03:18:53 icculus
42 * Serial port i/o code written, so I can ROCK'n'RIDE it!
43 *
44 * Revision 1.1.1.1 2000/04/18 00:00:33 icculus
45 * initial checkin
46 *
47 *
48 * 5 7/14/99 9:06p Jeff
49 * added comment header
50 *
51 * $NoKeywords: $
52 */
53
54 // ----------------------------------------------------------------------------
55 // Linux IO System Main Library Interface
56 // ----------------------------------------------------------------------------
57
58 #include <cstdarg>
59 #include <cstdio>
60
61 #ifdef MACOSX
62 #include <mach-o/dyld.h>
63 #endif
64
65 #ifdef WIN32
66 #include <windows.h>
67 #endif
68
69 #include "application.h"cxx . . $ `<file>/lib/application.h`/
70 #include "ddio.h"cxx . . $ `<file>/ddio/ddio.h`/
71 #include "pserror.h"cxx . . $ `<file>/misc/pserror.h`/
72
73 bool DDIO_initcxx . . $ DDIO_init. = false;
74 oeLnxApplicationcxx . . $ oeLnxApplication# *Lnx_app_objcxx . . $ Lnx_app_obj. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
75
76 // ----------------------------------------------------------------------------
77 // Initialization and destruction functions
78 // ----------------------------------------------------------------------------
79
80 bool ddio_InternalInitcxx . . $ ddio_InternalInit(4aa02e9b14a147be).(ddio_init_infocxx . . $ ddio_init_info# *init_info) {
81 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "DDIO: ddio_InternalInit() called.");
82 Lnx_app_objcxx . . $ Lnx_app_obj. = (oeLnxApplicationcxx . . $ oeLnxApplication# *)init_info->objcxx . . $ ddio_init_info#obj.;
83 DDIO_initcxx . . $ DDIO_init. = true;
84 return true;
85 }
86
87 void ddio_InternalClosecxx . . $ ddio_InternalClose(49f6e7a06ebc5aa8).() {
88 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "DDIO: ddio_InternalClose() called.");
89
90 if (DDIO_initcxx . . $ DDIO_init.) {
91 DDIO_initcxx . . $ DDIO_init. = false;
92 Lnx_app_objcxx . . $ Lnx_app_obj. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
93 } // if
94
95 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "DDIO: ddio_InternalClose() returning.");
96 }
97
98 void ddio_DebugMessagecxx . . $ ddio_DebugMessage(c490c57a897d7f54).(unsigned err, char *fmt, ...) {
99 char buf[128];
100 va_listcxx . . $ va_list# arglist;
101
102 va_startcxx . . $ `<external>/8105065126723003039/stdarg.h:50:9`!(arglist, fmt);
103 std::vsnprintfcxx . . $ std/vsnprintf(348eb892742d8727).(buf, sizeof(buf), fmt, arglist);
104 va_endcxx . . $ `<external>/8105065126723003039/stdarg.h:52:9`!(arglist);
105
106 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "%s\n", buf);
107 }
108
109 bool ddio_GetBinaryPathcxx . . $ ddio_GetBinaryPath(ccee65ad8ce1f171).(char *exec_path, size_t len) {
110 #ifdef MACOSX
111 if (exec_path == NULL || len == 0) {
112 fprintf(stderr, "Invalid arguments\n");
113 return false;
114 }
115
116 uint32_t size = (uint32_t)len;
117 if (_NSGetExecutablePath(exec_path, &size) != 0) {
118 fprintf(stderr, "Buffer too small; need size %u\n", size);
119 return false;
120 }
121 #elif defined(__LINUX__cxx . . $ `<external>/8627488274992530813/SDL_platform.h:61:9`!)
122 if (realpath("/proc/self/exe", exec_path) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) {
123 perror("realpath");
124 return false;
125 }
126 #else
127 if (GetModuleFileName(NULL, exec_path, len) == 0) {
128 DWORD error = GetLastError();
129 Error("GetModuleFileName failed!");
130 return false;
131 }
132 exec_path[len - 1] = '\0';
133 return true;
134
135 #endif
136 exec_path[len - 1] = '\0';
137 return true;
138 }