diff options
author | George Hazan <george.hazan@gmail.com> | 2012-06-02 20:55:18 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2012-06-02 20:55:18 +0000 |
commit | 78c0815c4118fe24ab78cce2dc48a6232dcd824a (patch) | |
tree | 8512c50df70b8dd80c919e88ade3419207c95956 /plugins/MirOTR/libgcrypt-1.4.6/random | |
parent | ce816d83a8c75808e0eb06832592bffefe4a8dc4 (diff) |
- code cleaning
git-svn-id: http://svn.miranda-ng.org/main/trunk@270 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/MirOTR/libgcrypt-1.4.6/random')
-rw-r--r-- | plugins/MirOTR/libgcrypt-1.4.6/random/random-csprng.c | 8 | ||||
-rw-r--r-- | plugins/MirOTR/libgcrypt-1.4.6/random/rndegd.c | 28 | ||||
-rw-r--r-- | plugins/MirOTR/libgcrypt-1.4.6/random/rndlinux.c | 18 | ||||
-rw-r--r-- | plugins/MirOTR/libgcrypt-1.4.6/random/rndunix.c | 56 |
4 files changed, 55 insertions, 55 deletions
diff --git a/plugins/MirOTR/libgcrypt-1.4.6/random/random-csprng.c b/plugins/MirOTR/libgcrypt-1.4.6/random/random-csprng.c index 6ab868ae37..16fe9db998 100644 --- a/plugins/MirOTR/libgcrypt-1.4.6/random/random-csprng.c +++ b/plugins/MirOTR/libgcrypt-1.4.6/random/random-csprng.c @@ -747,7 +747,7 @@ read_seed_file (void) #else fd = open( seed_file_name, O_RDONLY ); #endif - if( fd == -1 && errno == ENOENT) + if ( fd == -1 && errno == ENOENT) { allow_seed_file_update = 1; return 0; @@ -972,7 +972,7 @@ read_pool (byte *buffer, size_t length, int level) needed = length - pool_balance; if (needed < POOLSIZE/2) needed = POOLSIZE/2; - else if( needed > POOLSIZE ) + else if ( needed > POOLSIZE ) BUG (); read_random_source (RANDOM_ORIGIN_EXTRAPOLL, needed, GCRY_VERY_STRONG_RANDOM); @@ -1183,14 +1183,14 @@ do_fast_random_poll (void) #elif HAVE_GETTIMEOFDAY { struct timeval tv; - if( gettimeofday( &tv, NULL ) ) + if ( gettimeofday( &tv, NULL ) ) BUG(); add_randomness( &tv.tv_sec, sizeof(tv.tv_sec), RANDOM_ORIGIN_FASTPOLL ); add_randomness( &tv.tv_usec, sizeof(tv.tv_usec), RANDOM_ORIGIN_FASTPOLL ); } #elif HAVE_CLOCK_GETTIME { struct timespec tv; - if( clock_gettime( CLOCK_REALTIME, &tv ) == -1 ) + if ( clock_gettime( CLOCK_REALTIME, &tv ) == -1 ) BUG(); add_randomness( &tv.tv_sec, sizeof(tv.tv_sec), RANDOM_ORIGIN_FASTPOLL ); add_randomness( &tv.tv_nsec, sizeof(tv.tv_nsec), RANDOM_ORIGIN_FASTPOLL ); diff --git a/plugins/MirOTR/libgcrypt-1.4.6/random/rndegd.c b/plugins/MirOTR/libgcrypt-1.4.6/random/rndegd.c index 63a5e0f162..ba82a52616 100644 --- a/plugins/MirOTR/libgcrypt-1.4.6/random/rndegd.c +++ b/plugins/MirOTR/libgcrypt-1.4.6/random/rndegd.c @@ -58,7 +58,7 @@ my_make_filename (const char *first_part, const char *second_part) n += strlen (second_part) + 1; home = NULL; - if( *first_part == '~' && first_part[1] == '/' + if ( *first_part == '~' && first_part[1] == '/' && (home = getenv("HOME")) && *home ) n += strlen(home); @@ -83,9 +83,9 @@ do_write( int fd, void *buf, size_t nbytes ) while( nleft > 0 ) { nwritten = write( fd, buf, nleft); - if( nwritten < 0 ) + if ( nwritten < 0 ) { - if( errno == EINTR ) + if ( errno == EINTR ) continue; return -1; } @@ -107,9 +107,9 @@ do_read( int fd, void *buf, size_t nbytes ) n = read(fd, (char*)buf + nread, nbytes ); } while( n == -1 && errno == EINTR ); - if( n == -1) + if ( n == -1) return nread? nread:-1; - if( n == 0) + if ( n == 0) return -1; nread += n; nbytes -= n; @@ -221,9 +221,9 @@ _gcry_rndegd_gather_random (void (*add)(const void*, size_t, int nbytes; int do_restart = 0; - if( !length ) + if ( !length ) return 0; - if( !level ) + if ( !level ) return 0; restart: @@ -236,20 +236,20 @@ _gcry_rndegd_gather_random (void (*add)(const void*, size_t, /* First time we do it with a non blocking request */ buffer[0] = 1; /* non blocking */ buffer[1] = nbytes; - if( do_write( fd, buffer, 2 ) == -1 ) + if ( do_write( fd, buffer, 2 ) == -1 ) log_fatal("can't write to the EGD: %s\n", strerror(errno) ); n = do_read( fd, buffer, 1 ); - if( n == -1 ) + if ( n == -1 ) { log_error("read error on EGD: %s\n", strerror(errno)); do_restart = 1; goto restart; } n = buffer[0]; - if( n ) + if ( n ) { n = do_read( fd, buffer, n ); - if( n == -1 ) + if ( n == -1 ) { log_error("read error on EGD: %s\n", strerror(errno)); do_restart = 1; @@ -259,7 +259,7 @@ _gcry_rndegd_gather_random (void (*add)(const void*, size_t, length -= n; } - if( length ) + if ( length ) { log_info ( _("Please wait, entropy is being gathered. Do some work if it would\n" @@ -272,10 +272,10 @@ _gcry_rndegd_gather_random (void (*add)(const void*, size_t, buffer[0] = 2; /* blocking */ buffer[1] = nbytes; - if( do_write( fd, buffer, 2 ) == -1 ) + if ( do_write( fd, buffer, 2 ) == -1 ) log_fatal("can't write to the EGD: %s\n", strerror(errno) ); n = do_read( fd, buffer, nbytes ); - if( n == -1 ) + if ( n == -1 ) { log_error("read error on EGD: %s\n", strerror(errno)); do_restart = 1; diff --git a/plugins/MirOTR/libgcrypt-1.4.6/random/rndlinux.c b/plugins/MirOTR/libgcrypt-1.4.6/random/rndlinux.c index 574ef6dcc0..aca72011ea 100644 --- a/plugins/MirOTR/libgcrypt-1.4.6/random/rndlinux.c +++ b/plugins/MirOTR/libgcrypt-1.4.6/random/rndlinux.c @@ -74,9 +74,9 @@ open_device ( const char *name ) struct stat sb; - if( fstat( fd, &sb ) ) + if ( fstat( fd, &sb ) ) log_fatal("stat() off %s failed: %s\n", name, strerror(errno) ); - if( (!S_ISCHR(sb.st_mode)) && (!S_ISFIFO(sb.st_mode)) ) + if ( (!S_ISCHR(sb.st_mode)) && (!S_ISFIFO(sb.st_mode)) ) log_fatal("invalid random device!\n" ); */ return fd; @@ -108,13 +108,13 @@ _gcry_rndlinux_gather_random (void (*add)(const void*, size_t, /* Open the requested device. */ if (level >= 2) { - if( fd_random == -1 ) + if ( fd_random == -1 ) fd_random = open_device ( NAME_OF_DEV_RANDOM ); fd = fd_random; } else { - if( fd_urandom == -1 ) + if ( fd_urandom == -1 ) fd_urandom = open_device ( NAME_OF_DEV_URANDOM ); fd = fd_urandom; } @@ -130,16 +130,16 @@ _gcry_rndlinux_gather_random (void (*add)(const void*, size_t, FD_SET(fd, &rfds); tv.tv_sec = 3; tv.tv_usec = 0; - if( !(rc=select(fd+1, &rfds, NULL, NULL, &tv)) ) + if ( !(rc=select(fd+1, &rfds, NULL, NULL, &tv)) ) { - if( !warn ) + if ( !warn ) { _gcry_random_progress ("need_entropy", 'X', 0, (int)length); warn = 1; } continue; } - else if( rc == -1 ) + else if ( rc == -1 ) { log_error ("select() error: %s\n", strerror(errno)); continue; @@ -149,14 +149,14 @@ _gcry_rndlinux_gather_random (void (*add)(const void*, size_t, { int nbytes = length < sizeof(buffer)? length : sizeof(buffer); n = read(fd, buffer, nbytes ); - if( n >= 0 && n > nbytes ) + if ( n >= 0 && n > nbytes ) { log_error("bogus read from random device (n=%d)\n", n ); n = nbytes; } } while( n == -1 && errno == EINTR ); - if( n == -1 ) + if ( n == -1 ) log_fatal("read error on random device: %s\n", strerror(errno)); (*add)( buffer, n, origin ); length -= n; diff --git a/plugins/MirOTR/libgcrypt-1.4.6/random/rndunix.c b/plugins/MirOTR/libgcrypt-1.4.6/random/rndunix.c index 1faf9abc0e..8f5d30a9ac 100644 --- a/plugins/MirOTR/libgcrypt-1.4.6/random/rndunix.c +++ b/plugins/MirOTR/libgcrypt-1.4.6/random/rndunix.c @@ -529,7 +529,7 @@ slow_poll(FILE *dbgfp, int dbgall, size_t *nbytes ) /* Since popen() is a fairly heavy function, we check to see whether * the executable exists before we try to run it */ if (access(dataSources[i].path, X_OK)) { - if( dbgfp && dbgall ) + if ( dbgfp && dbgall ) fprintf(dbgfp, "%s not present%s\n", dataSources[i].path, dataSources[i].hasAlternative ? ", has alternatives" : ""); @@ -555,7 +555,7 @@ slow_poll(FILE *dbgfp, int dbgall, size_t *nbytes ) /* If there are alternatives for this command, don't try and * execute them */ while (dataSources[i].hasAlternative) { - if( dbgfp && dbgall ) + if ( dbgfp && dbgall ) fprintf(dbgfp, "Skipping %s\n", dataSources[i + 1].path); i++; } @@ -584,7 +584,7 @@ slow_poll(FILE *dbgfp, int dbgall, size_t *nbytes ) /* One of the sources has data available, read it into the buffer */ for (i = 0; dataSources[i].path != NULL; i++) { - if( dataSources[i].pipe && FD_ISSET(dataSources[i].pipeFD, &fds)) { + if ( dataSources[i].pipe && FD_ISSET(dataSources[i].pipeFD, &fds)) { size_t noBytes; if ((noBytes = fread(gather_buffer + bufPos, 1, @@ -603,14 +603,14 @@ slow_poll(FILE *dbgfp, int dbgall, size_t *nbytes ) total = dataSources[i].length / dataSources[i].usefulness; } - if( dbgfp ) + if ( dbgfp ) fprintf(dbgfp, "%s %s contributed %d bytes, " "usefulness = %d\n", dataSources[i].path, (dataSources[i].arg != NULL) ? dataSources[i].arg : "", dataSources[i].length, total); - if( dataSources[i].length ) + if ( dataSources[i].length ) usefulness += total; } dataSources[i].pipe = NULL; @@ -661,7 +661,7 @@ slow_poll(FILE *dbgfp, int dbgall, size_t *nbytes ) } } - if( dbgfp ) { + if ( dbgfp ) { fprintf(dbgfp, "Got %d bytes, usefulness = %d\n", bufPos, usefulness); fflush(dbgfp); } @@ -681,9 +681,9 @@ start_gatherer( int pipefd ) { const char *s = getenv("GNUPG_RNDUNIX_DBG"); - if( s ) { + if ( s ) { dbgfp = (*s=='-' && !s[1])? stdout : fopen(s, "a"); - if( !dbgfp ) + if ( !dbgfp ) log_info("can't open debug file `%s': %s\n", s, strerror(errno) ); else @@ -694,7 +694,7 @@ start_gatherer( int pipefd ) /* close all files but the ones we need */ { int nmax, n1, n2, i; #ifdef _SC_OPEN_MAX - if( (nmax=sysconf( _SC_OPEN_MAX )) < 0 ) { + if ( (nmax=sysconf( _SC_OPEN_MAX )) < 0 ) { #ifdef _POSIX_OPEN_MAX nmax = _POSIX_OPEN_MAX; #else @@ -707,7 +707,7 @@ start_gatherer( int pipefd ) n1 = fileno( stderr ); n2 = dbgfp? fileno( dbgfp ) : -1; for(i=0; i < nmax; i++ ) { - if( i != n1 && i != n2 && i != pipefd ) + if ( i != n1 && i != n2 && i != pipefd ) close(i); } errno = 0; @@ -717,7 +717,7 @@ start_gatherer( int pipefd ) /* Set up the buffer. Not ethat we use a plain standard malloc here. */ gather_buffer_size = GATHER_BUFSIZE; gather_buffer = malloc( gather_buffer_size ); - if( !gather_buffer ) { + if ( !gather_buffer ) { log_error("out of core while allocating the gatherer buffer\n"); exit(2); } @@ -738,7 +738,7 @@ start_gatherer( int pipefd ) fclose(stderr); /* Arrghh!! It's Stuart code!! */ - for(;;) { + for (;;) { GATHER_MSG msg; size_t nbytes; const char *p; @@ -752,20 +752,20 @@ start_gatherer( int pipefd ) p += msg.ndata; while( write( pipefd, &msg, sizeof(msg) ) != sizeof(msg) ) { - if( errno == EINTR ) + if ( errno == EINTR ) continue; - if( errno == EAGAIN ) { + if ( errno == EAGAIN ) { struct timeval tv; tv.tv_sec = 0; tv.tv_usec = 50000; select(0, NULL, NULL, NULL, &tv); continue; } - if( errno == EPIPE ) /* parent has exited, so give up */ + if ( errno == EPIPE ) /* parent has exited, so give up */ exit(0); /* we can't do very much here because stderr is closed */ - if( dbgfp ) + if ( dbgfp ) fprintf(dbgfp, "gatherer can't write to pipe: %s\n", strerror(errno) ); /* we start a new poll to give the system some time */ @@ -789,7 +789,7 @@ read_a_msg( int fd, GATHER_MSG *msg ) do { n = read(fd, buffer, length ); } while( n == -1 && errno == EINTR ); - if( n == -1 ) + if ( n == -1 ) return -1; buffer += n; length -= n; @@ -813,24 +813,24 @@ _gcry_rndunix_gather_random (void (*add)(const void*, size_t, GATHER_MSG msg; size_t n; - if( !level ) + if ( !level ) return 0; - if( !gatherer_pid ) { + if ( !gatherer_pid ) { /* Make sure we are not setuid. */ if ( getuid() != geteuid() ) BUG(); /* time to start the gatherer process */ - if( pipe( pipedes ) ) { + if ( pipe( pipedes ) ) { log_error("pipe() failed: %s\n", strerror(errno)); return -1; } gatherer_pid = fork(); - if( gatherer_pid == -1 ) { + if ( gatherer_pid == -1 ) { log_error("can't for gatherer process: %s\n", strerror(errno)); return -1; } - if( !gatherer_pid ) { + if ( !gatherer_pid ) { start_gatherer( pipedes[1] ); /* oops, can't happen */ return -1; @@ -842,23 +842,23 @@ _gcry_rndunix_gather_random (void (*add)(const void*, size_t, int goodness; ulong subtract; - if( read_a_msg( pipedes[0], &msg ) ) { + if ( read_a_msg( pipedes[0], &msg ) ) { log_error("reading from gatherer pipe failed: %s\n", strerror(errno)); return -1; } - if( level > 1 ) { - if( msg.usefulness > 30 ) + if ( level > 1 ) { + if ( msg.usefulness > 30 ) goodness = 100; else if ( msg.usefulness ) goodness = msg.usefulness * 100 / 30; else goodness = 0; } - else if( level ) { - if( msg.usefulness > 15 ) + else if ( level ) { + if ( msg.usefulness > 15 ) goodness = 100; else if ( msg.usefulness ) goodness = msg.usefulness * 100 / 15; @@ -869,7 +869,7 @@ _gcry_rndunix_gather_random (void (*add)(const void*, size_t, goodness = 100; /* goodness of level 0 is always 100 % */ n = msg.ndata; - if( n > length ) + if ( n > length ) n = length; (*add)( msg.data, n, origin ); |