This commit is contained in:
chris
2002-11-04 12:29:06 +00:00
parent 09e55647de
commit 83c173350b
21 changed files with 732 additions and 34 deletions

18
config/Makefile.am Normal file
View File

@@ -0,0 +1,18 @@
#
# config/Makefile.am:
# Automake file for the extra config droppings.
#
# $Id$
#
EXTRA_DIST = hostentp_ghba_r.c int_ghba_r.c pthread.c
AUX_DIST = config.guess \
config.sub \
install-sh \
ltconfig \
ltmain.sh \
missing \
mkinstalldirs
MAINTERCLEANFILES = $(AUX_DIST)

39
config/hostentp_ghba_r.c Normal file
View File

@@ -0,0 +1,39 @@
/*
* hostentp_ghba_r.c:
* Test program to see whether gethostbyaddr_r takes 7 arguments and returns
* struct hostent*.
*/
static const char rcsid[] = "$Id$";
#include <sys/types.h>
#include <errno.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <netinet/in.h>
int main(void) {
struct in_addr localhost;
struct hostent hostbuf, *hp;
char *buf;
int herr;
size_t buflen = 1024;
localhost.s_addr = htonl(INADDR_LOOPBACK);
buf = malloc(buflen);
while ((hp = gethostbyaddr_r((char*)&localhost, sizeof(struct in_addr),
AF_INET, &hostbuf, buf, buflen, &herr))
== NULL
&& errno == ERANGE)
buf = (char*)realloc(buf, buflen *= 2);
/* We assume that the loopback address can always be resolved if
* gethostbyaddr_r is actually working. */
if (hp == NULL) {
fprintf(stderr, "errno = %d, herr = %d\n", errno, herr);
return -1;
} else
return 0;
}

38
config/int_ghba_r.c Normal file
View File

@@ -0,0 +1,38 @@
/*
* int_ghba_r.c:
* Test program to see whether gethostbyaddr_r takes 8 arguments and returns
* int.
*/
static const char rcsid[] = "$Id$";
#include <sys/types.h>
#include <errno.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <netinet/in.h>
int main(void) {
struct in_addr localhost;
struct hostent hostbuf, *hp;
char *buf;
int res, herr;
size_t buflen = 1024;
localhost.s_addr = htonl(INADDR_LOOPBACK);
buf = malloc(buflen);
while ((res = gethostbyaddr_r((char*)&localhost, sizeof localhost, AF_INET,
&hostbuf, buf, buflen, &hp, &herr))
== ERANGE)
buf = (char*)realloc(buf, buflen *= 2);
/* We assume that the loopback address can always be resolved if
* gethostbyaddr_r is actually working. */
if (res || hp == NULL) {
fprintf(stderr, "errno = %d, herr = %d, res = %d\n", errno, herr, res);
return -1;
} else
return 0;
}

62
config/pthread.c Normal file
View File

@@ -0,0 +1,62 @@
/*
* pthread.c:
* Tiny test program to see whether POSIX threads work.
*/
static const char rcsid[] = "$Id$";
#include <sys/types.h>
#include <errno.h>
#include <pthread.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
static int return_value = -1;
void *worker_thread(void *v) {
/* Record successful return and signal parent to wake up. */
return_value = 0;
pthread_mutex_lock(&mtx);
pthread_cond_signal(&cond);
pthread_mutex_unlock(&mtx);
while (1)
pause();
}
/* Start a thread, and have it set a variable to some other value, then signal
* a condition variable. If this doesn't happen within some set time, we assume
* that something's gone badly wrong and abort (for instance, the thread never
* got started). */
int main(void) {
pthread_t thr;
int res;
struct timespec deadline = {0};
if ((res = pthread_mutex_lock(&mtx)) != 0
|| (res = pthread_create(&thr, NULL, worker_thread, NULL)) != 0) {
fprintf(stderr, "%s\n", strerror(res));
return -1;
}
/* Thread should now be running; we should wait on the condition
* variable. */
do
deadline.tv_sec = 2 + time(NULL);
while ((res = pthread_cond_timedwait(&cond, &mtx, &deadline)) == EINTR);
if (res != 0) {
fprintf(stderr, "%s\n", strerror(res));
return -1;
}
if ((res = pthread_cancel(thr)) != 0
|| (res = pthread_join(thr, NULL)) != 0) {
fprintf(stderr, "%s\n", strerror(res));
return -1;
}
return return_value;
}