clang-format Mosh
Run clang-format over the Mosh source tree. This is a large change and
has been factored into its own commit for auditability. Reproduce it
with
find . -name \*.cc -or -name \*.h | while read f; do clang-format -i --style=file $f; done
This commit is contained in:
committed by
Alex Chernyakhovsky
parent
0b15dc94fa
commit
3acaa1c4d3
+10
-8
@@ -38,17 +38,19 @@
|
||||
|
||||
#include "src/crypto/crypto.h"
|
||||
|
||||
static void dos_detected( const char *expression, const char *file, int line, const char *function )
|
||||
static void dos_detected( const char* expression, const char* file, int line, const char* function )
|
||||
{
|
||||
char buffer[ 2048 ];
|
||||
snprintf( buffer, 2048, "Illegal counterparty input (possible denial of service) in function %s at %s:%d, failed test: %s\n",
|
||||
function, file, line, expression );
|
||||
char buffer[2048];
|
||||
snprintf( buffer,
|
||||
2048,
|
||||
"Illegal counterparty input (possible denial of service) in function %s at %s:%d, failed test: %s\n",
|
||||
function,
|
||||
file,
|
||||
line,
|
||||
expression );
|
||||
throw Crypto::CryptoException( buffer );
|
||||
}
|
||||
|
||||
#define dos_assert(expr) \
|
||||
((expr) \
|
||||
? (void)0 \
|
||||
: dos_detected (#expr, __FILE__, __LINE__, __func__ ))
|
||||
#define dos_assert( expr ) ( ( expr ) ? (void)0 : dos_detected( #expr, __FILE__, __LINE__, __func__ ) )
|
||||
|
||||
#endif
|
||||
|
||||
@@ -36,16 +36,17 @@
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
|
||||
static void fatal_error( const char *expression, const char *file, int line, const char *function )
|
||||
static void fatal_error( const char* expression, const char* file, int line, const char* function )
|
||||
{
|
||||
fprintf( stderr, "Fatal assertion failure in function %s at %s:%d\nFailed test: %s\n",
|
||||
function, file, line, expression );
|
||||
fprintf( stderr,
|
||||
"Fatal assertion failure in function %s at %s:%d\nFailed test: %s\n",
|
||||
function,
|
||||
file,
|
||||
line,
|
||||
expression );
|
||||
abort();
|
||||
}
|
||||
|
||||
#define fatal_assert(expr) \
|
||||
((expr) \
|
||||
? (void)0 \
|
||||
: fatal_error (#expr, __FILE__, __LINE__, __func__ ))
|
||||
#define fatal_assert( expr ) ( ( expr ) ? (void)0 : fatal_error( #expr, __FILE__, __LINE__, __func__ ) )
|
||||
|
||||
#endif
|
||||
|
||||
+13
-13
@@ -45,7 +45,6 @@
|
||||
|
||||
#include "src/util/locale_utils.h"
|
||||
|
||||
|
||||
const std::string LocaleVar::str( void ) const
|
||||
{
|
||||
if ( name.empty() ) {
|
||||
@@ -57,22 +56,22 @@ const std::string LocaleVar::str( void ) const
|
||||
const LocaleVar get_ctype( void )
|
||||
{
|
||||
/* Reimplement the search logic, just for diagnostics */
|
||||
if ( const char *all = getenv( "LC_ALL" ) ) {
|
||||
if ( const char* all = getenv( "LC_ALL" ) ) {
|
||||
return LocaleVar( "LC_ALL", all );
|
||||
} else if ( const char *ctype = getenv( "LC_CTYPE" ) ) {
|
||||
} else if ( const char* ctype = getenv( "LC_CTYPE" ) ) {
|
||||
return LocaleVar( "LC_CTYPE", ctype );
|
||||
} else if ( const char *lang = getenv( "LANG" ) ) {
|
||||
} else if ( const char* lang = getenv( "LANG" ) ) {
|
||||
return LocaleVar( "LANG", lang );
|
||||
}
|
||||
return LocaleVar( "", "" );
|
||||
}
|
||||
|
||||
const char *locale_charset( void )
|
||||
const char* locale_charset( void )
|
||||
{
|
||||
static const char ASCII_name[] = "US-ASCII";
|
||||
|
||||
/* Produce more pleasant name of US-ASCII */
|
||||
const char *ret = nl_langinfo( CODESET );
|
||||
const char* ret = nl_langinfo( CODESET );
|
||||
|
||||
if ( strcmp( ret, "ANSI_X3.4-1968" ) == 0 ) {
|
||||
ret = ASCII_name;
|
||||
@@ -81,16 +80,17 @@ const char *locale_charset( void )
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool is_utf8_locale( void ) {
|
||||
bool is_utf8_locale( void )
|
||||
{
|
||||
/* Verify locale calls for UTF-8 */
|
||||
if ( strcmp( locale_charset(), "UTF-8" ) != 0 &&
|
||||
strcmp( locale_charset(), "utf-8" ) != 0 ) {
|
||||
if ( strcmp( locale_charset(), "UTF-8" ) != 0 && strcmp( locale_charset(), "utf-8" ) != 0 ) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void set_native_locale( void ) {
|
||||
void set_native_locale( void )
|
||||
{
|
||||
/* Adopt native locale */
|
||||
if ( NULL == setlocale( LC_ALL, "" ) ) {
|
||||
int saved_errno = errno;
|
||||
@@ -98,8 +98,7 @@ void set_native_locale( void ) {
|
||||
LocaleVar ctype( get_ctype() );
|
||||
fprintf( stderr, "The locale requested by %s isn't available here.\n", ctype.str().c_str() );
|
||||
if ( !ctype.name.empty() ) {
|
||||
fprintf( stderr, "Running `locale-gen %s' may be necessary.\n\n",
|
||||
ctype.value.c_str() );
|
||||
fprintf( stderr, "Running `locale-gen %s' may be necessary.\n\n", ctype.value.c_str() );
|
||||
}
|
||||
} else {
|
||||
errno = saved_errno;
|
||||
@@ -108,7 +107,8 @@ void set_native_locale( void ) {
|
||||
}
|
||||
}
|
||||
|
||||
void clear_locale_variables( void ) {
|
||||
void clear_locale_variables( void )
|
||||
{
|
||||
unsetenv( "LANG" );
|
||||
unsetenv( "LANGUAGE" );
|
||||
unsetenv( "LC_CTYPE" );
|
||||
|
||||
@@ -35,17 +35,16 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
class LocaleVar {
|
||||
public:
|
||||
class LocaleVar
|
||||
{
|
||||
public:
|
||||
const std::string name, value;
|
||||
LocaleVar( const char *s_name, const char *s_value )
|
||||
: name( s_name ), value( s_value )
|
||||
{}
|
||||
LocaleVar( const char* s_name, const char* s_value ) : name( s_name ), value( s_value ) {}
|
||||
const std::string str( void ) const;
|
||||
};
|
||||
|
||||
const LocaleVar get_ctype( void );
|
||||
const char *locale_charset( void );
|
||||
const char* locale_charset( void );
|
||||
bool is_utf8_locale( void );
|
||||
void set_native_locale( void );
|
||||
void clear_locale_variables( void );
|
||||
|
||||
+41
-45
@@ -32,7 +32,7 @@
|
||||
|
||||
#include "src/include/config.h"
|
||||
|
||||
#if !defined(HAVE_FORKPTY) || !defined(HAVE_CFMAKERAW)
|
||||
#if !defined( HAVE_FORKPTY ) || !defined( HAVE_CFMAKERAW )
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
@@ -46,15 +46,13 @@
|
||||
#include "src/util/pty_compat.h"
|
||||
|
||||
#ifndef HAVE_FORKPTY
|
||||
pid_t my_forkpty( int *amaster, char *name,
|
||||
const struct termios *termp,
|
||||
const struct winsize *winp )
|
||||
{
|
||||
pid_t my_forkpty( int* amaster, char* name, const struct termios* termp, const struct winsize* winp )
|
||||
{
|
||||
/* For Solaris and AIX */
|
||||
int master, slave;
|
||||
char *slave_name;
|
||||
pid_t pid;
|
||||
|
||||
int master, slave;
|
||||
char* slave_name;
|
||||
pid_t pid;
|
||||
|
||||
#ifdef _AIX
|
||||
#define PTY_DEVICE "/dev/ptc"
|
||||
#else
|
||||
@@ -73,7 +71,7 @@ pid_t my_forkpty( int *amaster, char *name,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ( unlockpt(master) < 0 ) {
|
||||
if ( unlockpt( master ) < 0 ) {
|
||||
perror( "unlockpt" );
|
||||
close( master );
|
||||
return -1;
|
||||
@@ -94,8 +92,7 @@ pid_t my_forkpty( int *amaster, char *name,
|
||||
}
|
||||
|
||||
#ifndef _AIX
|
||||
if ( ioctl(slave, I_PUSH, "ptem") < 0 ||
|
||||
ioctl(slave, I_PUSH, "ldterm") < 0 ) {
|
||||
if ( ioctl( slave, I_PUSH, "ptem" ) < 0 || ioctl( slave, I_PUSH, "ldterm" ) < 0 ) {
|
||||
perror( "ioctl(I_PUSH)" );
|
||||
close( slave );
|
||||
close( master );
|
||||
@@ -106,7 +103,7 @@ pid_t my_forkpty( int *amaster, char *name,
|
||||
if ( amaster != NULL )
|
||||
*amaster = master;
|
||||
|
||||
if ( name != NULL)
|
||||
if ( name != NULL )
|
||||
strcpy( name, slave_name );
|
||||
|
||||
if ( termp != NULL ) {
|
||||
@@ -122,7 +119,7 @@ pid_t my_forkpty( int *amaster, char *name,
|
||||
w.ws_col = 80;
|
||||
w.ws_xpixel = 0;
|
||||
w.ws_ypixel = 0;
|
||||
if ( ioctl( slave, TIOCSWINSZ, &w) < 0 ) {
|
||||
if ( ioctl( slave, TIOCSWINSZ, &w ) < 0 ) {
|
||||
perror( "ioctl TIOCSWINSZ" );
|
||||
exit( 1 );
|
||||
}
|
||||
@@ -135,51 +132,50 @@ pid_t my_forkpty( int *amaster, char *name,
|
||||
|
||||
pid = fork();
|
||||
switch ( pid ) {
|
||||
case -1: /* Error */
|
||||
perror( "fork()" );
|
||||
return -1;
|
||||
case 0: /* Child */
|
||||
if ( setsid() < 0 )
|
||||
perror( "setsid" );
|
||||
#ifdef TIOCSCTTY
|
||||
if ( ioctl( slave, TIOCSCTTY, NULL ) < 0 ) {
|
||||
perror( "ioctl" );
|
||||
case -1: /* Error */
|
||||
perror( "fork()" );
|
||||
return -1;
|
||||
}
|
||||
case 0: /* Child */
|
||||
if ( setsid() < 0 )
|
||||
perror( "setsid" );
|
||||
#ifdef TIOCSCTTY
|
||||
if ( ioctl( slave, TIOCSCTTY, NULL ) < 0 ) {
|
||||
perror( "ioctl" );
|
||||
return -1;
|
||||
}
|
||||
#else
|
||||
{
|
||||
{
|
||||
int dummy_fd;
|
||||
dummy_fd = open (slave_name, O_RDWR);
|
||||
if (dummy_fd < 0) {
|
||||
perror( "open(slave_name)" );
|
||||
return -1;
|
||||
dummy_fd = open( slave_name, O_RDWR );
|
||||
if ( dummy_fd < 0 ) {
|
||||
perror( "open(slave_name)" );
|
||||
return -1;
|
||||
}
|
||||
close (dummy_fd);
|
||||
}
|
||||
close( dummy_fd );
|
||||
}
|
||||
#endif /* TIOCSCTTY */
|
||||
close( master );
|
||||
dup2( slave, STDIN_FILENO );
|
||||
dup2( slave, STDOUT_FILENO );
|
||||
dup2( slave, STDERR_FILENO );
|
||||
return 0;
|
||||
default: /* Parent */
|
||||
close( slave );
|
||||
return pid;
|
||||
close( master );
|
||||
dup2( slave, STDIN_FILENO );
|
||||
dup2( slave, STDOUT_FILENO );
|
||||
dup2( slave, STDERR_FILENO );
|
||||
return 0;
|
||||
default: /* Parent */
|
||||
close( slave );
|
||||
return pid;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_CFMAKERAW
|
||||
void my_cfmakeraw( struct termios *termios_p )
|
||||
void my_cfmakeraw( struct termios* termios_p )
|
||||
{
|
||||
termios_p->c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP
|
||||
| INLCR | IGNCR | ICRNL | IXON);
|
||||
termios_p->c_iflag &= ~( IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON );
|
||||
termios_p->c_oflag &= ~OPOST;
|
||||
termios_p->c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
|
||||
termios_p->c_cflag &= ~(CSIZE | PARENB);
|
||||
termios_p->c_lflag &= ~( ECHO | ECHONL | ICANON | ISIG | IEXTEN );
|
||||
termios_p->c_cflag &= ~( CSIZE | PARENB );
|
||||
termios_p->c_cflag |= CS8;
|
||||
|
||||
termios_p->c_cc[VMIN] = 1; // read() is satisfied after 1 char
|
||||
termios_p->c_cc[VMIN] = 1; // read() is satisfied after 1 char
|
||||
termios_p->c_cc[VTIME] = 0; // No timer
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -36,16 +36,14 @@
|
||||
#include "src/include/config.h"
|
||||
|
||||
#ifndef HAVE_FORKPTY
|
||||
# define forkpty my_forkpty
|
||||
#define forkpty my_forkpty
|
||||
#endif
|
||||
#ifndef HAVE_CFMAKERAW
|
||||
# define cfmakeraw my_cfmakeraw
|
||||
#define cfmakeraw my_cfmakeraw
|
||||
#endif
|
||||
|
||||
pid_t my_forkpty( int *amaster, char *name,
|
||||
const struct termios *termp,
|
||||
const struct winsize *winp );
|
||||
pid_t my_forkpty( int* amaster, char* name, const struct termios* termp, const struct winsize* winp );
|
||||
|
||||
void my_cfmakeraw( struct termios *termios_p );
|
||||
void my_cfmakeraw( struct termios* termios_p );
|
||||
|
||||
#endif
|
||||
|
||||
+2
-2
@@ -43,6 +43,6 @@ void Select::handle_signal( int signum )
|
||||
fatal_assert( signum >= 0 );
|
||||
fatal_assert( signum <= MAX_SIGNAL_NUMBER );
|
||||
|
||||
Select &sel = get_instance();
|
||||
sel.got_signal[ signum ] = 1;
|
||||
Select& sel = get_instance();
|
||||
sel.got_signal[signum] = 1;
|
||||
}
|
||||
|
||||
+35
-36
@@ -48,9 +48,11 @@
|
||||
Any signals blocked by calling sigprocmask() outside this code will still be
|
||||
received during Select::select(). So don't do that. */
|
||||
|
||||
class Select {
|
||||
class Select
|
||||
{
|
||||
public:
|
||||
static Select &get_instance( void ) {
|
||||
static Select& get_instance( void )
|
||||
{
|
||||
/* COFU may or may not be thread-safe, depending on compiler */
|
||||
static Select instance;
|
||||
return instance;
|
||||
@@ -59,12 +61,10 @@ public:
|
||||
private:
|
||||
Select()
|
||||
: max_fd( -1 )
|
||||
/* These initializations are not used; they are just
|
||||
here to appease -Weffc++. */
|
||||
, all_fds( dummy_fd_set )
|
||||
, read_fds( dummy_fd_set )
|
||||
, empty_sigset( dummy_sigset )
|
||||
, consecutive_polls( 0 )
|
||||
/* These initializations are not used; they are just
|
||||
here to appease -Weffc++. */
|
||||
,
|
||||
all_fds( dummy_fd_set ), read_fds( dummy_fd_set ), empty_sigset( dummy_sigset ), consecutive_polls( 0 )
|
||||
{
|
||||
FD_ZERO( &all_fds );
|
||||
FD_ZERO( &read_fds );
|
||||
@@ -75,16 +75,15 @@ private:
|
||||
|
||||
void clear_got_signal( void )
|
||||
{
|
||||
for ( volatile sig_atomic_t *p = got_signal;
|
||||
p < got_signal + sizeof( got_signal ) / sizeof( *got_signal );
|
||||
for ( volatile sig_atomic_t* p = got_signal; p < got_signal + sizeof( got_signal ) / sizeof( *got_signal );
|
||||
p++ ) {
|
||||
*p = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* not implemented */
|
||||
Select( const Select & );
|
||||
Select &operator=( const Select & );
|
||||
Select( const Select& );
|
||||
Select& operator=( const Select& );
|
||||
|
||||
public:
|
||||
void add_fd( int fd )
|
||||
@@ -95,10 +94,7 @@ public:
|
||||
FD_SET( fd, &all_fds );
|
||||
}
|
||||
|
||||
void clear_fds( void )
|
||||
{
|
||||
FD_ZERO( &all_fds );
|
||||
}
|
||||
void clear_fds( void ) { FD_ZERO( &all_fds ); }
|
||||
|
||||
static void add_signal( int signum )
|
||||
{
|
||||
@@ -123,7 +119,7 @@ public:
|
||||
/* timeout unit: milliseconds; negative timeout means wait forever */
|
||||
int select( int timeout )
|
||||
{
|
||||
memcpy( &read_fds, &all_fds, sizeof( read_fds ) );
|
||||
memcpy( &read_fds, &all_fds, sizeof( read_fds ) );
|
||||
clear_got_signal();
|
||||
|
||||
/* Rate-limit and warn about polls. */
|
||||
@@ -132,35 +128,35 @@ public:
|
||||
}
|
||||
if ( timeout == 0 && ++consecutive_polls >= MAX_POLLS ) {
|
||||
if ( verbose > 1 && consecutive_polls == MAX_POLLS ) {
|
||||
fprintf( stderr, "%s: got %d polls, rate limiting.\n", __func__, MAX_POLLS );
|
||||
fprintf( stderr, "%s: got %d polls, rate limiting.\n", __func__, MAX_POLLS );
|
||||
}
|
||||
timeout = 1;
|
||||
} else if ( timeout != 0 && consecutive_polls ) {
|
||||
if ( verbose > 1 && consecutive_polls >= MAX_POLLS ) {
|
||||
fprintf( stderr, "%s: got %d consecutive polls\n", __func__, consecutive_polls );
|
||||
fprintf( stderr, "%s: got %d consecutive polls\n", __func__, consecutive_polls );
|
||||
}
|
||||
consecutive_polls = 0;
|
||||
}
|
||||
|
||||
#ifdef HAVE_PSELECT
|
||||
struct timespec ts;
|
||||
struct timespec *tsp = NULL;
|
||||
struct timespec* tsp = NULL;
|
||||
|
||||
if ( timeout >= 0 ) {
|
||||
ts.tv_sec = timeout / 1000;
|
||||
ts.tv_nsec = 1000000 * (long( timeout ) % 1000);
|
||||
ts.tv_sec = timeout / 1000;
|
||||
ts.tv_nsec = 1000000 * ( long( timeout ) % 1000 );
|
||||
tsp = &ts;
|
||||
}
|
||||
|
||||
int ret = ::pselect( max_fd + 1, &read_fds, NULL, NULL, tsp, &empty_sigset );
|
||||
#else
|
||||
struct timeval tv;
|
||||
struct timeval *tvp = NULL;
|
||||
struct timeval* tvp = NULL;
|
||||
sigset_t old_sigset;
|
||||
|
||||
if ( timeout >= 0 ) {
|
||||
tv.tv_sec = timeout / 1000;
|
||||
tv.tv_usec = 1000 * (long( timeout ) % 1000);
|
||||
tv.tv_sec = timeout / 1000;
|
||||
tv.tv_usec = 1000 * ( long( timeout ) % 1000 );
|
||||
tvp = &tv;
|
||||
}
|
||||
|
||||
@@ -174,11 +170,11 @@ public:
|
||||
if ( ret == 0 || ( ret == -1 && errno == EINTR ) ) {
|
||||
/* Look for and report Cygwin select() bug. */
|
||||
if ( ret == 0 ) {
|
||||
for ( int fd = 0; fd <= max_fd; fd++ ) {
|
||||
if ( FD_ISSET( fd, &read_fds ) ) {
|
||||
fprintf( stderr, "select(): nfds = 0 but read fd %d is set\n", fd );
|
||||
}
|
||||
}
|
||||
for ( int fd = 0; fd <= max_fd; fd++ ) {
|
||||
if ( FD_ISSET( fd, &read_fds ) ) {
|
||||
fprintf( stderr, "select(): nfds = 0 but read fd %d is set\n", fd );
|
||||
}
|
||||
}
|
||||
}
|
||||
/* The user should process events as usual. */
|
||||
FD_ZERO( &read_fds );
|
||||
@@ -205,8 +201,8 @@ public:
|
||||
fatal_assert( signum >= 0 );
|
||||
fatal_assert( signum <= MAX_SIGNAL_NUMBER );
|
||||
/* XXX This requires a guard against concurrent signals. */
|
||||
bool rv = got_signal[ signum ];
|
||||
got_signal[ signum ] = 0;
|
||||
bool rv = got_signal[signum];
|
||||
got_signal[signum] = 0;
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -214,13 +210,16 @@ public:
|
||||
bool any_signal( void ) const
|
||||
{
|
||||
bool rv = false;
|
||||
for (int i = 0; i < MAX_SIGNAL_NUMBER; i++) {
|
||||
rv |= got_signal[ i ];
|
||||
for ( int i = 0; i < MAX_SIGNAL_NUMBER; i++ ) {
|
||||
rv |= got_signal[i];
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
static void set_verbose( unsigned int s_verbose ) { verbose = s_verbose; }
|
||||
static void set_verbose( unsigned int s_verbose )
|
||||
{
|
||||
verbose = s_verbose;
|
||||
}
|
||||
|
||||
private:
|
||||
static const int MAX_SIGNAL_NUMBER = 64;
|
||||
@@ -234,7 +233,7 @@ private:
|
||||
|
||||
/* We assume writes to got_signal are atomic, though we also try to mask out
|
||||
concurrent signal handlers. */
|
||||
volatile sig_atomic_t got_signal[ MAX_SIGNAL_NUMBER + 1 ];
|
||||
volatile sig_atomic_t got_signal[MAX_SIGNAL_NUMBER + 1];
|
||||
|
||||
fd_set all_fds, read_fds;
|
||||
|
||||
|
||||
+3
-4
@@ -37,13 +37,12 @@
|
||||
|
||||
#include "src/util/swrite.h"
|
||||
|
||||
int swrite( int fd, const char *str, ssize_t len )
|
||||
int swrite( int fd, const char* str, ssize_t len )
|
||||
{
|
||||
ssize_t total_bytes_written = 0;
|
||||
ssize_t bytes_to_write = ( len >= 0 ) ? len : (ssize_t) strlen( str );
|
||||
ssize_t bytes_to_write = ( len >= 0 ) ? len : (ssize_t)strlen( str );
|
||||
while ( total_bytes_written < bytes_to_write ) {
|
||||
ssize_t bytes_written = write( fd, str + total_bytes_written,
|
||||
bytes_to_write - total_bytes_written );
|
||||
ssize_t bytes_written = write( fd, str + total_bytes_written, bytes_to_write - total_bytes_written );
|
||||
if ( bytes_written <= 0 ) {
|
||||
perror( "write" );
|
||||
return -1;
|
||||
|
||||
+1
-1
@@ -33,6 +33,6 @@
|
||||
#ifndef SWRITE_HPP
|
||||
#define SWRITE_HPP
|
||||
|
||||
int swrite( int fd, const char *str, ssize_t len = -1 );
|
||||
int swrite( int fd, const char* str, ssize_t len = -1 );
|
||||
|
||||
#endif
|
||||
|
||||
+11
-11
@@ -44,15 +44,15 @@
|
||||
#include <mach/mach_time.h>
|
||||
#endif
|
||||
#if HAVE_GETTIMEOFDAY
|
||||
#include <sys/time.h>
|
||||
#include <cstdio>
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
// On Apple systems CLOCK_MONOTONIC is unfortunately able to go
|
||||
// backwards in time. This breaks mosh when system is returning from
|
||||
// suspend as described in ticket #1014. To avoid this issue prefer
|
||||
// CLOCK_MONOTONIC_RAW on Apple systems when available.
|
||||
#if defined(__APPLE__) && defined(CLOCK_MONOTONIC_RAW)
|
||||
#if defined( __APPLE__ ) && defined( CLOCK_MONOTONIC_RAW )
|
||||
#define CLOCKTYPE CLOCK_MONOTONIC_RAW
|
||||
#else
|
||||
#define CLOCKTYPE CLOCK_MONOTONIC
|
||||
@@ -79,11 +79,11 @@ void freeze_timestamp( void )
|
||||
struct timespec tp;
|
||||
|
||||
if (
|
||||
#if defined(__APPLE__) && defined(__MACH__)
|
||||
// Check for presence, for OS X SDK >= 10.12 and runtime < 10.12
|
||||
&clock_gettime != NULL &&
|
||||
#if defined( __APPLE__ ) && defined( __MACH__ )
|
||||
// Check for presence, for OS X SDK >= 10.12 and runtime < 10.12
|
||||
&clock_gettime != NULL &&
|
||||
#endif
|
||||
clock_gettime( CLOCKTYPE, &tp ) == 0 ) {
|
||||
clock_gettime( CLOCKTYPE, &tp ) == 0 ) {
|
||||
uint64_t millis = tp.tv_nsec / 1000000;
|
||||
millis += uint64_t( tp.tv_sec ) * 1000;
|
||||
|
||||
@@ -97,8 +97,8 @@ void freeze_timestamp( void )
|
||||
static mach_timebase_info_data_t s_timebase_info;
|
||||
static double absolute_to_millis = 0.0;
|
||||
|
||||
if (absolute_to_millis == 0.0) {
|
||||
if (ERR_SUCCESS == mach_timebase_info(&s_timebase_info)) {
|
||||
if ( absolute_to_millis == 0.0 ) {
|
||||
if ( ERR_SUCCESS == mach_timebase_info( &s_timebase_info ) ) {
|
||||
absolute_to_millis = 1e-6 * s_timebase_info.numer / s_timebase_info.denom;
|
||||
} else
|
||||
absolute_to_millis = -1.0;
|
||||
@@ -106,7 +106,7 @@ void freeze_timestamp( void )
|
||||
|
||||
// NB: mach_absolute_time() returns "absolute time units"
|
||||
// We need to apply a conversion to get milliseconds.
|
||||
if (absolute_to_millis > 0.0) {
|
||||
if ( absolute_to_millis > 0.0 ) {
|
||||
millis_cache = mach_absolute_time() * absolute_to_millis;
|
||||
return;
|
||||
}
|
||||
@@ -115,7 +115,7 @@ void freeze_timestamp( void )
|
||||
// Not monotonic.
|
||||
// NOTE: If time steps backwards, timeouts may be confused.
|
||||
struct timeval tv;
|
||||
if ( gettimeofday(&tv, NULL) ) {
|
||||
if ( gettimeofday( &tv, NULL ) ) {
|
||||
perror( "gettimeofday" );
|
||||
} else {
|
||||
uint64_t millis = tv.tv_usec / 1000;
|
||||
@@ -125,6 +125,6 @@ void freeze_timestamp( void )
|
||||
return;
|
||||
}
|
||||
#else
|
||||
# error "gettimeofday() unavailable-- required as timer of last resort"
|
||||
#error "gettimeofday() unavailable-- required as timer of last resort"
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user