os_unix.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. /*************************************************************************/
  2. /* os_unix.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "os_unix.h"
  31. #ifdef UNIX_ENABLED
  32. #include "core/os/thread_dummy.h"
  33. #include "core/project_settings.h"
  34. #include "drivers/unix/dir_access_unix.h"
  35. #include "drivers/unix/file_access_unix.h"
  36. #include "drivers/unix/mutex_posix.h"
  37. #include "drivers/unix/net_socket_posix.h"
  38. #include "drivers/unix/rw_lock_posix.h"
  39. #include "drivers/unix/semaphore_posix.h"
  40. #include "drivers/unix/thread_posix.h"
  41. #include "servers/visual_server.h"
  42. #ifdef __APPLE__
  43. #include <mach-o/dyld.h>
  44. #include <mach/mach_time.h>
  45. #endif
  46. #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
  47. #include <sys/param.h>
  48. #include <sys/sysctl.h>
  49. #endif
  50. #include <assert.h>
  51. #include <dlfcn.h>
  52. #include <errno.h>
  53. #include <poll.h>
  54. #include <signal.h>
  55. #include <stdarg.h>
  56. #include <stdio.h>
  57. #include <stdlib.h>
  58. #include <string.h>
  59. #include <sys/time.h>
  60. #include <sys/wait.h>
  61. #include <unistd.h>
  62. /// Clock Setup function (used by get_ticks_usec)
  63. static uint64_t _clock_start = 0;
  64. #if defined(__APPLE__)
  65. static double _clock_scale = 0;
  66. static void _setup_clock() {
  67. mach_timebase_info_data_t info;
  68. kern_return_t ret = mach_timebase_info(&info);
  69. ERR_FAIL_COND_MSG(ret != 0, "OS CLOCK IS NOT WORKING!");
  70. _clock_scale = ((double)info.numer / (double)info.denom) / 1000.0;
  71. _clock_start = mach_absolute_time() * _clock_scale;
  72. }
  73. #else
  74. #if defined(CLOCK_MONOTONIC_RAW) && !defined(JAVASCRIPT_ENABLED) // This is a better clock on Linux.
  75. #define GODOT_CLOCK CLOCK_MONOTONIC_RAW
  76. #else
  77. #define GODOT_CLOCK CLOCK_MONOTONIC
  78. #endif
  79. static void _setup_clock() {
  80. struct timespec tv_now = { 0, 0 };
  81. ERR_FAIL_COND_MSG(clock_gettime(GODOT_CLOCK, &tv_now) != 0, "OS CLOCK IS NOT WORKING!");
  82. _clock_start = ((uint64_t)tv_now.tv_nsec / 1000L) + (uint64_t)tv_now.tv_sec * 1000000L;
  83. }
  84. #endif
  85. void OS_Unix::debug_break() {
  86. assert(false);
  87. };
  88. static void handle_interrupt(int sig) {
  89. if (ScriptDebugger::get_singleton() == NULL)
  90. return;
  91. ScriptDebugger::get_singleton()->set_depth(-1);
  92. ScriptDebugger::get_singleton()->set_lines_left(1);
  93. }
  94. void OS_Unix::initialize_debugging() {
  95. if (ScriptDebugger::get_singleton() != NULL) {
  96. struct sigaction action;
  97. memset(&action, 0, sizeof(action));
  98. action.sa_handler = handle_interrupt;
  99. sigaction(SIGINT, &action, NULL);
  100. }
  101. }
  102. int OS_Unix::unix_initialize_audio(int p_audio_driver) {
  103. return 0;
  104. }
  105. void OS_Unix::initialize_core() {
  106. #ifdef NO_THREADS
  107. ThreadDummy::make_default();
  108. SemaphoreDummy::make_default();
  109. MutexDummy::make_default();
  110. RWLockDummy::make_default();
  111. #else
  112. ThreadPosix::make_default();
  113. #if !defined(OSX_ENABLED) && !defined(IPHONE_ENABLED)
  114. SemaphorePosix::make_default();
  115. #endif
  116. MutexPosix::make_default();
  117. RWLockPosix::make_default();
  118. #endif
  119. FileAccess::make_default<FileAccessUnix>(FileAccess::ACCESS_RESOURCES);
  120. FileAccess::make_default<FileAccessUnix>(FileAccess::ACCESS_USERDATA);
  121. FileAccess::make_default<FileAccessUnix>(FileAccess::ACCESS_FILESYSTEM);
  122. DirAccess::make_default<DirAccessUnix>(DirAccess::ACCESS_RESOURCES);
  123. DirAccess::make_default<DirAccessUnix>(DirAccess::ACCESS_USERDATA);
  124. DirAccess::make_default<DirAccessUnix>(DirAccess::ACCESS_FILESYSTEM);
  125. #ifndef NO_NETWORK
  126. NetSocketPosix::make_default();
  127. IP_Unix::make_default();
  128. #endif
  129. _setup_clock();
  130. }
  131. void OS_Unix::finalize_core() {
  132. NetSocketPosix::cleanup();
  133. }
  134. void OS_Unix::alert(const String &p_alert, const String &p_title) {
  135. fprintf(stderr, "ALERT: %s: %s\n", p_title.utf8().get_data(), p_alert.utf8().get_data());
  136. }
  137. String OS_Unix::get_stdin_string(bool p_block) {
  138. if (p_block) {
  139. char buff[1024];
  140. String ret = stdin_buf + fgets(buff, 1024, stdin);
  141. stdin_buf = "";
  142. return ret;
  143. }
  144. return "";
  145. }
  146. String OS_Unix::get_name() const {
  147. return "Unix";
  148. }
  149. uint64_t OS_Unix::get_unix_time() const {
  150. return time(NULL);
  151. };
  152. uint64_t OS_Unix::get_system_time_secs() const {
  153. struct timeval tv_now;
  154. gettimeofday(&tv_now, NULL);
  155. return uint64_t(tv_now.tv_sec);
  156. }
  157. uint64_t OS_Unix::get_system_time_msecs() const {
  158. struct timeval tv_now;
  159. gettimeofday(&tv_now, NULL);
  160. return uint64_t(tv_now.tv_sec) * 1000 + uint64_t(tv_now.tv_usec) / 1000;
  161. }
  162. OS::Date OS_Unix::get_date(bool utc) const {
  163. time_t t = time(NULL);
  164. struct tm lt;
  165. if (utc) {
  166. gmtime_r(&t, &lt);
  167. } else {
  168. localtime_r(&t, &lt);
  169. }
  170. Date ret;
  171. ret.year = 1900 + lt.tm_year;
  172. // Index starting at 1 to match OS_Unix::get_date
  173. // and Windows SYSTEMTIME and tm_mon follows the typical structure
  174. // of 0-11, noted here: http://www.cplusplus.com/reference/ctime/tm/
  175. ret.month = (Month)(lt.tm_mon + 1);
  176. ret.day = lt.tm_mday;
  177. ret.weekday = (Weekday)lt.tm_wday;
  178. ret.dst = lt.tm_isdst;
  179. return ret;
  180. }
  181. OS::Time OS_Unix::get_time(bool utc) const {
  182. time_t t = time(NULL);
  183. struct tm lt;
  184. if (utc) {
  185. gmtime_r(&t, &lt);
  186. } else {
  187. localtime_r(&t, &lt);
  188. }
  189. Time ret;
  190. ret.hour = lt.tm_hour;
  191. ret.min = lt.tm_min;
  192. ret.sec = lt.tm_sec;
  193. get_time_zone_info();
  194. return ret;
  195. }
  196. OS::TimeZoneInfo OS_Unix::get_time_zone_info() const {
  197. time_t t = time(NULL);
  198. struct tm lt;
  199. localtime_r(&t, &lt);
  200. char name[16];
  201. strftime(name, 16, "%Z", &lt);
  202. name[15] = 0;
  203. TimeZoneInfo ret;
  204. ret.name = name;
  205. char bias_buf[16];
  206. strftime(bias_buf, 16, "%z", &lt);
  207. int bias;
  208. bias_buf[15] = 0;
  209. sscanf(bias_buf, "%d", &bias);
  210. // convert from ISO 8601 (1 minute=1, 1 hour=100) to minutes
  211. int hour = (int)bias / 100;
  212. int minutes = bias % 100;
  213. if (bias < 0)
  214. ret.bias = hour * 60 - minutes;
  215. else
  216. ret.bias = hour * 60 + minutes;
  217. return ret;
  218. }
  219. void OS_Unix::delay_usec(uint32_t p_usec) const {
  220. struct timespec requested = { static_cast<time_t>(p_usec / 1000000), (static_cast<long>(p_usec) % 1000000) * 1000 };
  221. struct timespec remaining;
  222. while (nanosleep(&requested, &remaining) == -1 && errno == EINTR) {
  223. requested.tv_sec = remaining.tv_sec;
  224. requested.tv_nsec = remaining.tv_nsec;
  225. }
  226. }
  227. uint64_t OS_Unix::get_ticks_usec() const {
  228. #if defined(__APPLE__)
  229. uint64_t longtime = mach_absolute_time() * _clock_scale;
  230. #else
  231. // Unchecked return. Static analyzers might complain.
  232. // If _setup_clock() succeeded, we assume clock_gettime() works.
  233. struct timespec tv_now = { 0, 0 };
  234. clock_gettime(GODOT_CLOCK, &tv_now);
  235. uint64_t longtime = ((uint64_t)tv_now.tv_nsec / 1000L) + (uint64_t)tv_now.tv_sec * 1000000L;
  236. #endif
  237. longtime -= _clock_start;
  238. return longtime;
  239. }
  240. Error OS_Unix::execute(const String &p_path, const List<String> &p_arguments, bool p_blocking, ProcessID *r_child_id, String *r_pipe, int *r_exitcode, bool read_stderr, Mutex *p_pipe_mutex) {
  241. #ifdef __EMSCRIPTEN__
  242. // Don't compile this code at all to avoid undefined references.
  243. // Actual virtual call goes to OS_JavaScript.
  244. ERR_FAIL_V(ERR_BUG);
  245. #else
  246. if (p_blocking && r_pipe) {
  247. String argss;
  248. argss = "\"" + p_path + "\"";
  249. for (int i = 0; i < p_arguments.size(); i++) {
  250. argss += String(" \"") + p_arguments[i] + "\"";
  251. }
  252. if (read_stderr) {
  253. argss += " 2>&1"; // Read stderr too
  254. } else {
  255. argss += " 2>/dev/null"; //silence stderr
  256. }
  257. FILE *f = popen(argss.utf8().get_data(), "r");
  258. ERR_FAIL_COND_V_MSG(!f, ERR_CANT_OPEN, "Cannot pipe stream from process running with following arguments '" + argss + "'.");
  259. char buf[65535];
  260. while (fgets(buf, 65535, f)) {
  261. if (p_pipe_mutex) {
  262. p_pipe_mutex->lock();
  263. }
  264. (*r_pipe) += String::utf8(buf);
  265. if (p_pipe_mutex) {
  266. p_pipe_mutex->unlock();
  267. }
  268. }
  269. int rv = pclose(f);
  270. if (r_exitcode)
  271. *r_exitcode = WEXITSTATUS(rv);
  272. return OK;
  273. }
  274. pid_t pid = fork();
  275. ERR_FAIL_COND_V(pid < 0, ERR_CANT_FORK);
  276. if (pid == 0) {
  277. // is child
  278. if (!p_blocking) {
  279. // For non blocking calls, create a new session-ID so parent won't wait for it.
  280. // This ensures the process won't go zombie at end.
  281. setsid();
  282. }
  283. Vector<CharString> cs;
  284. cs.push_back(p_path.utf8());
  285. for (int i = 0; i < p_arguments.size(); i++)
  286. cs.push_back(p_arguments[i].utf8());
  287. Vector<char *> args;
  288. for (int i = 0; i < cs.size(); i++)
  289. args.push_back((char *)cs[i].get_data());
  290. args.push_back(0);
  291. execvp(p_path.utf8().get_data(), &args[0]);
  292. // still alive? something failed..
  293. fprintf(stderr, "**ERROR** OS_Unix::execute - Could not create child process while executing: %s\n", p_path.utf8().get_data());
  294. raise(SIGKILL);
  295. }
  296. if (p_blocking) {
  297. int status;
  298. waitpid(pid, &status, 0);
  299. if (r_exitcode)
  300. *r_exitcode = WIFEXITED(status) ? WEXITSTATUS(status) : status;
  301. } else {
  302. if (r_child_id)
  303. *r_child_id = pid;
  304. }
  305. return OK;
  306. #endif
  307. }
  308. Error OS_Unix::kill(const ProcessID &p_pid) {
  309. int ret = ::kill(p_pid, SIGKILL);
  310. if (!ret) {
  311. //avoid zombie process
  312. int st;
  313. ::waitpid(p_pid, &st, 0);
  314. }
  315. return ret ? ERR_INVALID_PARAMETER : OK;
  316. }
  317. int OS_Unix::get_process_id() const {
  318. return getpid();
  319. };
  320. bool OS_Unix::has_environment(const String &p_var) const {
  321. return getenv(p_var.utf8().get_data()) != NULL;
  322. }
  323. String OS_Unix::get_locale() const {
  324. if (!has_environment("LANG"))
  325. return "en";
  326. String locale = get_environment("LANG");
  327. int tp = locale.find(".");
  328. if (tp != -1)
  329. locale = locale.substr(0, tp);
  330. return locale;
  331. }
  332. Error OS_Unix::open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path) {
  333. String path = p_path;
  334. if (FileAccess::exists(path) && path.is_rel_path()) {
  335. // dlopen expects a slash, in this case a leading ./ for it to be interpreted as a relative path,
  336. // otherwise it will end up searching various system directories for the lib instead and finally failing.
  337. path = "./" + path;
  338. }
  339. if (!FileAccess::exists(path)) {
  340. //this code exists so gdnative can load .so files from within the executable path
  341. path = get_executable_path().get_base_dir().plus_file(p_path.get_file());
  342. }
  343. if (!FileAccess::exists(path)) {
  344. //this code exists so gdnative can load .so files from a standard unix location
  345. path = get_executable_path().get_base_dir().plus_file("../lib").plus_file(p_path.get_file());
  346. }
  347. p_library_handle = dlopen(path.utf8().get_data(), RTLD_NOW);
  348. ERR_FAIL_COND_V_MSG(!p_library_handle, ERR_CANT_OPEN, "Can't open dynamic library: " + p_path + ". Error: " + dlerror());
  349. return OK;
  350. }
  351. Error OS_Unix::close_dynamic_library(void *p_library_handle) {
  352. if (dlclose(p_library_handle)) {
  353. return FAILED;
  354. }
  355. return OK;
  356. }
  357. Error OS_Unix::get_dynamic_library_symbol_handle(void *p_library_handle, const String p_name, void *&p_symbol_handle, bool p_optional) {
  358. const char *error;
  359. dlerror(); // Clear existing errors
  360. p_symbol_handle = dlsym(p_library_handle, p_name.utf8().get_data());
  361. error = dlerror();
  362. if (error != NULL) {
  363. ERR_FAIL_COND_V_MSG(!p_optional, ERR_CANT_RESOLVE, "Can't resolve symbol " + p_name + ". Error: " + error + ".");
  364. return ERR_CANT_RESOLVE;
  365. }
  366. return OK;
  367. }
  368. Error OS_Unix::set_cwd(const String &p_cwd) {
  369. if (chdir(p_cwd.utf8().get_data()) != 0)
  370. return ERR_CANT_OPEN;
  371. return OK;
  372. }
  373. String OS_Unix::get_environment(const String &p_var) const {
  374. if (getenv(p_var.utf8().get_data()))
  375. return getenv(p_var.utf8().get_data());
  376. return "";
  377. }
  378. bool OS_Unix::set_environment(const String &p_var, const String &p_value) const {
  379. return setenv(p_var.utf8().get_data(), p_value.utf8().get_data(), /* overwrite: */ true) == 0;
  380. }
  381. int OS_Unix::get_processor_count() const {
  382. return sysconf(_SC_NPROCESSORS_CONF);
  383. }
  384. String OS_Unix::get_user_data_dir() const {
  385. String appname = get_safe_dir_name(ProjectSettings::get_singleton()->get("application/config/name"));
  386. if (appname != "") {
  387. bool use_custom_dir = ProjectSettings::get_singleton()->get("application/config/use_custom_user_dir");
  388. if (use_custom_dir) {
  389. String custom_dir = get_safe_dir_name(ProjectSettings::get_singleton()->get("application/config/custom_user_dir_name"), true);
  390. if (custom_dir == "") {
  391. custom_dir = appname;
  392. }
  393. return get_data_path().plus_file(custom_dir);
  394. } else {
  395. return get_data_path().plus_file(get_godot_dir_name()).plus_file("app_userdata").plus_file(appname);
  396. }
  397. }
  398. return ProjectSettings::get_singleton()->get_resource_path();
  399. }
  400. String OS_Unix::get_executable_path() const {
  401. #ifdef __linux__
  402. //fix for running from a symlink
  403. char buf[256];
  404. memset(buf, 0, 256);
  405. ssize_t len = readlink("/proc/self/exe", buf, sizeof(buf));
  406. String b;
  407. if (len > 0) {
  408. b.parse_utf8(buf, len);
  409. }
  410. if (b == "") {
  411. WARN_PRINT("Couldn't get executable path from /proc/self/exe, using argv[0]");
  412. return OS::get_executable_path();
  413. }
  414. return b;
  415. #elif defined(__OpenBSD__) || defined(__NetBSD__)
  416. char resolved_path[MAXPATHLEN];
  417. realpath(OS::get_executable_path().utf8().get_data(), resolved_path);
  418. return String(resolved_path);
  419. #elif defined(__FreeBSD__)
  420. int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
  421. char buf[MAXPATHLEN];
  422. size_t len = sizeof(buf);
  423. if (sysctl(mib, 4, buf, &len, NULL, 0) != 0) {
  424. WARN_PRINT("Couldn't get executable path from sysctl");
  425. return OS::get_executable_path();
  426. }
  427. String b;
  428. b.parse_utf8(buf);
  429. return b;
  430. #elif defined(__APPLE__)
  431. char temp_path[1];
  432. uint32_t buff_size = 1;
  433. _NSGetExecutablePath(temp_path, &buff_size);
  434. char *resolved_path = new char[buff_size + 1];
  435. if (_NSGetExecutablePath(resolved_path, &buff_size) == 1)
  436. WARN_PRINT("MAXPATHLEN is too small");
  437. String path(resolved_path);
  438. delete[] resolved_path;
  439. return path;
  440. #else
  441. ERR_PRINT("Warning, don't know how to obtain executable path on this OS! Please override this function properly.");
  442. return OS::get_executable_path();
  443. #endif
  444. }
  445. void UnixTerminalLogger::log_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, ErrorType p_type) {
  446. if (!should_log(true)) {
  447. return;
  448. }
  449. const char *err_details;
  450. if (p_rationale && p_rationale[0])
  451. err_details = p_rationale;
  452. else
  453. err_details = p_code;
  454. // Disable color codes if stdout is not a TTY.
  455. // This prevents Godot from writing ANSI escape codes when redirecting
  456. // stdout and stderr to a file.
  457. const bool tty = isatty(fileno(stdout));
  458. const char *red = tty ? "\E[0;31m" : "";
  459. const char *red_bold = tty ? "\E[1;31m" : "";
  460. const char *yellow = tty ? "\E[0;33m" : "";
  461. const char *yellow_bold = tty ? "\E[1;33m" : "";
  462. const char *magenta = tty ? "\E[0;35m" : "";
  463. const char *magenta_bold = tty ? "\E[1;35m" : "";
  464. const char *cyan = tty ? "\E[0;36m" : "";
  465. const char *cyan_bold = tty ? "\E[1;36m" : "";
  466. const char *reset = tty ? "\E[0m" : "";
  467. const char *bold = tty ? "\E[1m" : "";
  468. switch (p_type) {
  469. case ERR_WARNING:
  470. logf_error("%sWARNING: %s: %s%s%s\n", yellow_bold, p_function, reset, bold, err_details);
  471. logf_error("%s At: %s:%i.%s\n", yellow, p_file, p_line, reset);
  472. break;
  473. case ERR_SCRIPT:
  474. logf_error("%sSCRIPT ERROR: %s: %s%s%s\n", magenta_bold, p_function, reset, bold, err_details);
  475. logf_error("%s At: %s:%i.%s\n", magenta, p_file, p_line, reset);
  476. break;
  477. case ERR_SHADER:
  478. logf_error("%sSHADER ERROR: %s: %s%s%s\n", cyan_bold, p_function, reset, bold, err_details);
  479. logf_error("%s At: %s:%i.%s\n", cyan, p_file, p_line, reset);
  480. break;
  481. case ERR_ERROR:
  482. default:
  483. logf_error("%sERROR: %s: %s%s%s\n", red_bold, p_function, reset, bold, err_details);
  484. logf_error("%s At: %s:%i.%s\n", red, p_file, p_line, reset);
  485. break;
  486. }
  487. }
  488. UnixTerminalLogger::~UnixTerminalLogger() {}
  489. OS_Unix::OS_Unix() {
  490. Vector<Logger *> loggers;
  491. loggers.push_back(memnew(UnixTerminalLogger));
  492. _set_logger(memnew(CompositeLogger(loggers)));
  493. }
  494. #endif