Changeset 69aaf14


Ignore:
Timestamp:
2008-04-02T15:40:33Z (13 years ago)
Author:
Jelmer Vernooij <jelmer@…>
Branches:
master
Children:
6ff51ff
Parents:
fa75134 (diff), 5f5d433 (diff), 5be87b2 (diff), 4af7b4f (diff), f1e7407 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge several portability improvements.

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • bitlbee.h

    rfa75134 r69aaf14  
    9595#define g_main_quit             __PLEASE_USE_B_MAIN_QUIT__
    9696
    97 #ifndef F_OK
    98 #define F_OK 0
    99 #endif
    100 
    10197#ifndef G_GNUC_MALLOC
    10298/* Doesn't exist in GLib <=2.4 while everything else in BitlBee should
  • configure

    rfa75134 r69aaf14  
    7474--ssl=...       SSL library to use (gnutls, nss, openssl, bogus, auto)
    7575                                                        $ssl
     76
     77--target=...    Cross compilation target                same as host
    7678EOF
    7779                exit;
     
    132134EOF
    133135
     136if [ -n "$target" ]; then
     137        PKG_CONFIG_PATH=/usr/$target/lib/pkgconfig
     138        PATH=/usr/$target/bin:$PATH
     139        CC=$target-cc
     140        LD=$target-ld
     141fi
     142
    134143if [ "$debug" = "1" ]; then
    135144        [ -z "$CFLAGS" ] && CFLAGS=-g
     
    158167echo "CC=$CC" >> Makefile.settings;
    159168
    160 if [ -n "$LD" ]; then
    161         echo "LD=$LD" >> Makefile.settings;
    162 elif type ld > /dev/null 2> /dev/null; then
    163         echo "LD=ld" >> Makefile.settings;
    164 else
    165         echo 'Cannot find ld, aborting.'
    166         exit 1;
    167 fi
     169if [ -z "$LD" ]; then
     170        if type ld > /dev/null 2> /dev/null; then
     171                LD=ld
     172        else
     173                echo 'Cannot find ld, aborting.'
     174                exit 1;
     175        fi
     176fi
     177
     178echo "LD=$LD" >> Makefile.settings
    168179
    169180if [ -z "$PKG_CONFIG" ]; then
     
    213224detect_gnutls()
    214225{
    215         if libgnutls-config --version > /dev/null 2> /dev/null; then
     226        if $PKG_CONFIG --exists gnutls; then
     227                cat <<EOF>>Makefile.settings
     228EFLAGS+=`$PKG_CONFIG --libs gnutls`
     229CFLAGS+=`$PKG_CONFIG --cflags gnutls`
     230EOF
     231                ssl=gnutls
     232                ret=1
     233        elif libgnutls-config --version > /dev/null 2> /dev/null; then
    216234                cat <<EOF>>Makefile.settings
    217235EFLAGS+=`libgnutls-config --libs`
     
    489507esac
    490508
     509if [ -n "$target" ]; then
     510        echo "Cross-compiling for: $target"
     511fi
     512
    491513echo
    492514echo 'Configuration done:'
  • lib/misc.c

    rfa75134 r69aaf14  
    392392}
    393393
    394 /* A pretty reliable random number generator. Tries to use the /dev/random
    395    devices first, and falls back to the random number generator from libc
    396    when it fails. Opens randomizer devices with O_NONBLOCK to make sure a
    397    lack of entropy won't halt BitlBee. */
    398 void random_bytes( unsigned char *buf, int count )
    399 {
    400         static int use_dev = -1;
    401        
    402         /* Actually this probing code isn't really necessary, is it? */
    403         if( use_dev == -1 )
    404         {
    405                 if( access( "/dev/random", R_OK ) == 0 || access( "/dev/urandom", R_OK ) == 0 )
    406                         use_dev = 1;
    407                 else
    408                 {
    409                         use_dev = 0;
    410                         srand( ( getpid() << 16 ) ^ time( NULL ) );
    411                 }
    412         }
    413        
    414         if( use_dev )
    415         {
    416                 int fd;
    417                
    418                 /* At least on Linux, /dev/random can block if there's not
    419                    enough entropy. We really don't want that, so if it can't
    420                    give anything, use /dev/urandom instead. */
    421                 if( ( fd = open( "/dev/random", O_RDONLY | O_NONBLOCK ) ) >= 0 )
    422                         if( read( fd, buf, count ) == count )
    423                         {
    424                                 close( fd );
    425                                 return;
    426                         }
    427                 close( fd );
    428                
    429                 /* urandom isn't supposed to block at all, but just to be
    430                    sure. If it blocks, we'll disable use_dev and use the libc
    431                    randomizer instead. */
    432                 if( ( fd = open( "/dev/urandom", O_RDONLY | O_NONBLOCK ) ) >= 0 )
    433                         if( read( fd, buf, count ) == count )
    434                         {
    435                                 close( fd );
    436                                 return;
    437                         }
    438                 close( fd );
    439                
    440                 /* If /dev/random blocks once, we'll still try to use it
    441                    again next time. If /dev/urandom also fails for some
    442                    reason, stick with libc during this session. */
    443                
    444                 use_dev = 0;
    445                 srand( ( getpid() << 16 ) ^ time( NULL ) );
    446         }
    447        
    448         if( !use_dev )
    449         {
    450                 int i;
    451                
    452                 /* Possibly the LSB of rand() isn't very random on some
    453                    platforms. Seems okay on at least Linux and OSX though. */
    454                 for( i = 0; i < count; i ++ )
    455                         buf[i] = rand() & 0xff;
    456         }
    457 }
    458 
    459394int is_bool( char *value )
    460395{
  • storage_xml.c

    rfa75134 r69aaf14  
    2929#include "arc.h"
    3030#include "md5.h"
     31#include <glib/gstdio.h>
    3132
    3233typedef enum
     
    243244static void xml_init( void )
    244245{
    245         if( access( global.conf->configdir, F_OK ) != 0 )
     246        if( ! g_file_test( global.conf->configdir, G_FILE_TEST_EXISTS ) )
    246247                log_message( LOGLVL_WARNING, "The configuration directory `%s' does not exist. Configuration won't be saved.", global.conf->configdir );
    247         else if( access( global.conf->configdir, R_OK ) != 0 || access( global.conf->configdir, W_OK ) != 0 )
     248        else if( ! g_file_test( global.conf->configdir, G_FILE_TEST_EXISTS ) || g_access( global.conf->configdir, W_OK ) != 0 )
    248249                log_message( LOGLVL_WARNING, "Permission problem: Can't read/write from/to `%s'.", global.conf->configdir );
    249250}
     
    372373        g_free( path2 );
    373374       
    374         if( !overwrite && access( path, F_OK ) != -1 )
     375        if( !overwrite && g_file_test( path, G_FILE_TEST_EXISTS ) )
    375376                return STORAGE_ALREADY_EXISTS;
    376377       
  • unix.c

    rfa75134 r69aaf14  
    219219        return( (double) time->tv_sec + (double) time->tv_usec / 1000000 );
    220220}
     221
     222/* A pretty reliable random number generator. Tries to use the /dev/random
     223   devices first, and falls back to the random number generator from libc
     224   when it fails. Opens randomizer devices with O_NONBLOCK to make sure a
     225   lack of entropy won't halt BitlBee. */
     226void random_bytes( unsigned char *buf, int count )
     227{
     228        static int use_dev = -1;
     229       
     230        /* Actually this probing code isn't really necessary, is it? */
     231        if( use_dev == -1 )
     232        {
     233                if( access( "/dev/random", R_OK ) == 0 || access( "/dev/urandom", R_OK ) == 0 )
     234                        use_dev = 1;
     235                else
     236                {
     237                        use_dev = 0;
     238                        srand( ( getpid() << 16 ) ^ time( NULL ) );
     239                }
     240        }
     241       
     242        if( use_dev )
     243        {
     244                int fd;
     245               
     246                /* At least on Linux, /dev/random can block if there's not
     247                   enough entropy. We really don't want that, so if it can't
     248                   give anything, use /dev/urandom instead. */
     249                if( ( fd = open( "/dev/random", O_RDONLY | O_NONBLOCK ) ) >= 0 )
     250                        if( read( fd, buf, count ) == count )
     251                        {
     252                                close( fd );
     253                                return;
     254                        }
     255                close( fd );
     256               
     257                /* urandom isn't supposed to block at all, but just to be
     258                   sure. If it blocks, we'll disable use_dev and use the libc
     259                   randomizer instead. */
     260                if( ( fd = open( "/dev/urandom", O_RDONLY | O_NONBLOCK ) ) >= 0 )
     261                        if( read( fd, buf, count ) == count )
     262                        {
     263                                close( fd );
     264                                return;
     265                        }
     266                close( fd );
     267               
     268                /* If /dev/random blocks once, we'll still try to use it
     269                   again next time. If /dev/urandom also fails for some
     270                   reason, stick with libc during this session. */
     271               
     272                use_dev = 0;
     273                srand( ( getpid() << 16 ) ^ time( NULL ) );
     274        }
     275       
     276        if( !use_dev )
     277        {
     278                int i;
     279               
     280                /* Possibly the LSB of rand() isn't very random on some
     281                   platforms. Seems okay on at least Linux and OSX though. */
     282                for( i = 0; i < count; i ++ )
     283                        buf[i] = rand() & 0xff;
     284        }
     285}
     286
     287
Note: See TracChangeset for help on using the changeset viewer.