Stun Server  Compliant with the latest RFCs including 5389, 5769, and 5780
discover the local host's own external IP address
getconsolewidth.cpp
Go to the documentation of this file.
1 /*
2  Copyright 2011 John Selbie
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 */
16 
17 
18 #include "commonincludes.hpp"
19 #include "oshelper.h"
20 
21 #ifndef _WIN32
22 #include <sys/ioctl.h>
23 #endif
24 
25 const size_t DEFAULT_CONSOLE_WIDTH = 80;
26 
27 static size_t GetConsoleWidthUnix()
28 {
29  // this ioctl call on file id 0 (stdin) works on MacOSX and Linux. So it's probably universal
30  struct winsize ws = {};
31  int ret;
32  size_t retvalue = DEFAULT_CONSOLE_WIDTH;
33  ret = ioctl(0, TIOCGWINSZ, &ws);
34  if ((ret != -1) && (ws.ws_col > 0))
35  {
36  retvalue = ws.ws_col;
37  }
38  return retvalue;
39 }
40 
42 {
43 #ifdef _WIN32
44  return DEFAULT_CONSOLE_WIDTH; // todo - call appropriate console apis when we port to windows
45 #else
46  return GetConsoleWidthUnix();
47 #endif
48 }
49 
static size_t GetConsoleWidthUnix()
size_t GetConsoleWidth()
const size_t DEFAULT_CONSOLE_WIDTH