comparison util.c @ 1983:a7b753e260a2 mame_interp

Merge from default
author Michael Pavone <pavone@retrodev.com>
date Sat, 09 May 2020 23:39:44 -0700
parents cd163b230cf9
children 441d5d6cea2f
comparison
equal deleted inserted replaced
1937:cafde1255ad3 1983:a7b753e260a2
5 #include <stdint.h> 5 #include <stdint.h>
6 #include <stdarg.h> 6 #include <stdarg.h>
7 7
8 #include <sys/types.h> 8 #include <sys/types.h>
9 #include <sys/stat.h> 9 #include <sys/stat.h>
10 #include <unistd.h>
11 #include <errno.h> 10 #include <errno.h>
12 11
13 #ifdef __ANDROID__ 12 #ifdef __ANDROID__
14 #include <android/log.h> 13 #include <android/log.h>
15 #define info_puts(msg) __android_log_write(ANDROID_LOG_INFO, "BlastEm", msg) 14 #define info_puts(msg) __android_log_write(ANDROID_LOG_INFO, "BlastEm", msg)
440 } 439 }
441 va_end(args); 440 va_end(args);
442 exit(1); 441 exit(1);
443 } 442 }
444 443
444 #ifndef _WIN32
445 #include <unistd.h>
446 #endif
447
445 void warning(char *format, ...) 448 void warning(char *format, ...)
446 { 449 {
447 va_list args; 450 va_list args;
448 va_start(args, format); 451 va_start(args, format);
449 #ifndef _WIN32 452 #ifndef _WIN32
530 { 533 {
531 output_enabled = 0; 534 output_enabled = 0;
532 } 535 }
533 536
534 #ifdef _WIN32 537 #ifdef _WIN32
538 #define WINVER 0x501
539 #include <winsock2.h>
535 #include <windows.h> 540 #include <windows.h>
536 #include <shlobj.h> 541 #include <shlobj.h>
537 542
538 char * get_home_dir() 543 char * get_home_dir()
539 { 544 {
677 } 682 }
678 free(parent); 683 free(parent);
679 return CreateDirectory(path, NULL); 684 return CreateDirectory(path, NULL);
680 } 685 }
681 686
687 static WSADATA wsa_data;
688 static void socket_cleanup(void)
689 {
690 WSACleanup();
691 }
692
693 void socket_init(void)
694 {
695 static uint8_t started;
696 if (!started) {
697 started = 1;
698 WSAStartup(MAKEWORD(2,2), &wsa_data);
699 atexit(socket_cleanup);
700 }
701 }
702
703 int socket_blocking(int sock, int should_block)
704 {
705 u_long param = !should_block;
706 if (ioctlsocket(sock, FIONBIO, &param)) {
707 return WSAGetLastError();
708 }
709 return 0;
710 }
711
712 void socket_close(int sock)
713 {
714 closesocket(sock);
715 }
716
717 int socket_last_error(void)
718 {
719 return WSAGetLastError();
720 }
721
722 int socket_error_is_wouldblock(void)
723 {
724 return WSAGetLastError() == WSAEWOULDBLOCK;
725 }
726
682 #else 727 #else
728 #include <fcntl.h>
729 #include <signal.h>
730
731 void socket_init(void)
732 {
733 //SIGPIPE on network sockets is not desired
734 //would be better to do this in a more limited way,
735 //but the alternatives are not portable
736 signal(SIGPIPE, SIG_IGN);
737 }
738
739 int socket_blocking(int sock, int should_block)
740 {
741 if (fcntl(sock, F_SETFL, should_block ? 0 : O_NONBLOCK)) {
742 return errno;
743 }
744 return 0;
745 }
746
747 void socket_close(int sock)
748 {
749 close(sock);
750 }
751
752 int socket_last_error(void)
753 {
754 return errno;
755 }
756
757 int socket_error_is_wouldblock(void)
758 {
759 return errno == EAGAIN || errno == EWOULDBLOCK;
760 }
683 761
684 char * get_home_dir() 762 char * get_home_dir()
685 { 763 {
686 return getenv("HOME"); 764 return getenv("HOME");
687 } 765 }