1 //===-- Platform.cpp --------------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // this file is only relevant for Visual C++ 11 #if defined( _WIN32 ) 12 13 #include <process.h> 14 #include <assert.h> 15 #include <stdlib.h> 16 17 #include "Platform.h" 18 19 // the control handler or SIGINT handler 20 static sighandler_t _ctrlHandler = NULL; 21 22 // the default console control handler 23 BOOL 24 WINAPI CtrlHandler (DWORD ctrlType) 25 { 26 if ( _ctrlHandler != NULL ) 27 { 28 _ctrlHandler( 0 ); 29 return TRUE; 30 } 31 return FALSE; 32 } 33 34 int 35 ioctl (int d, int request, ...) 36 { 37 switch ( request ) 38 { 39 // request the console windows size 40 case ( TIOCGWINSZ ): 41 { 42 va_list vl; 43 va_start(vl,request); 44 // locate the window size structure on stack 45 winsize *ws = va_arg(vl, winsize*); 46 // get screen buffer information 47 CONSOLE_SCREEN_BUFFER_INFO info; 48 if ( GetConsoleScreenBufferInfo( GetStdHandle( STD_OUTPUT_HANDLE ), &info ) == TRUE ) 49 // fill in the columns 50 ws->ws_col = info.dwMaximumWindowSize.X; 51 va_end(vl); 52 return 0; 53 } 54 break; 55 default: 56 assert( !"Not implemented!" ); 57 } 58 return -1; 59 } 60 61 int 62 kill (pid_t pid, int sig) 63 { 64 // is the app trying to kill itself 65 if ( pid == getpid( ) ) 66 exit( sig ); 67 // 68 assert( !"Not implemented!" ); 69 return -1; 70 } 71 72 int 73 tcsetattr (int fd, int optional_actions, const struct termios *termios_p) 74 { 75 assert( !"Not implemented!" ); 76 return -1; 77 } 78 79 int 80 tcgetattr (int fildes, struct termios *termios_p) 81 { 82 // assert( !"Not implemented!" ); 83 // error return value (0=success) 84 return -1; 85 } 86 87 #ifdef _MSC_VER 88 sighandler_t 89 signal (int sig, sighandler_t sigFunc) 90 { 91 switch ( sig ) 92 { 93 case ( SIGINT ): 94 { 95 _ctrlHandler = sigFunc; 96 SetConsoleCtrlHandler( CtrlHandler, TRUE ); 97 } 98 break; 99 case ( SIGPIPE ): 100 case ( SIGWINCH ): 101 case ( SIGTSTP ): 102 case ( SIGCONT ): 103 // ignore these for now 104 break; 105 default: 106 assert( !"Not implemented!" ); 107 } 108 return 0; 109 } 110 #endif 111 112 #endif 113