Ejemplo n.º 1
0
def config_sys_socket_h(ctx, builder):
    '''
    Test for the posix sys/socket.h header, which provides network sockets.

    @param builder: C builder
    '''

    if not builder.check_header_exists('sys/socket.h'):
        raise MissingHeader('sys/socket.h')

    socket_h = Record()

    code = '''
        #include <sys/types.h>
        #include <sys/socket.h>

        extern int accept(int s, struct sockaddr* addr, %s* addrlen);
    '''

    logger.check('determing type of socklen_t')
    for t in 'socklen_t', 'unsigned int', 'int':
        if builder.try_compile(code % t):
            logger.passed('ok ' + t)
            socket_h.socklen_t = t
            break
    else:
        logger.failed()
        raise ConfigFailed('failed to detect type of socklen_t')

    return socket_h
Ejemplo n.º 2
0
def config_pthread_h(ctx, builder):
    '''
    Test for the posix pthread.h header, which provides posix threads.

    @param builder: C builder
    '''

    if not builder.check_header_exists('pthread.h'):
        raise MissingHeader('pthread.h')

    pthread_h = Record()

    code = '''
        #include <pthread.h>

        void* start(void* data) { return NULL; }

        int main(int argc, char** argv) {
            pthread_t thr;
            pthread_attr_t attr;
            pthread_attr_init(&attr);
            pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
            int res = pthread_create(&thr, &attr, start, NULL);
            pthread_attr_destroy(&attr);
            return res;
        }
    '''

    logger.check('detecting pthread link flags')
    for flags in [], ['-lpthread'], ['-pthread'], ['-pthreads']:
        if builder.try_run(code, lkwargs={'flags': flags}):
            logger.passed('ok %r' % ' '.join(flags))
            pthread_h.flags = flags
            break
    else:
        logger.failed()
        raise ConfigFailed('failed to link pthread program')

    return pthread_h