From e4cbb982b0a4fb2cc47b60442bac5015ea2c4321 Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Fri, 8 Aug 2003 02:46:40 +0000 Subject: threads.c -> thread.c, be consistent. --- src/interfaces/libpq/Makefile | 8 ++-- src/port/thread.c | 87 +++++++++++++++++++++++++++++++++++++++++++ src/port/threads.c | 87 ------------------------------------------- 3 files changed, 91 insertions(+), 91 deletions(-) create mode 100644 src/port/thread.c delete mode 100644 src/port/threads.c diff --git a/src/interfaces/libpq/Makefile b/src/interfaces/libpq/Makefile index 47263b34de..e8b5eedab8 100644 --- a/src/interfaces/libpq/Makefile +++ b/src/interfaces/libpq/Makefile @@ -4,7 +4,7 @@ # # Copyright (c) 1994, Regents of the University of California # -# $Header: /cvsroot/pgsql/src/interfaces/libpq/Makefile,v 1.83 2003/06/17 17:58:54 petere Exp $ +# $Header: /cvsroot/pgsql/src/interfaces/libpq/Makefile,v 1.84 2003/08/08 02:46:40 momjian Exp $ # #------------------------------------------------------------------------- @@ -23,7 +23,7 @@ override CPPFLAGS := -I$(srcdir) $(CPPFLAGS) $(THREAD_CFLAGS) -DFRONTEND -DSYSCO OBJS= fe-auth.o fe-connect.o fe-exec.o fe-misc.o fe-print.o fe-lobj.o \ fe-protocol2.o fe-protocol3.o pqexpbuffer.o pqsignal.o fe-secure.o \ dllist.o md5.o ip.o wchar.o encnames.o \ - $(filter crypt.o getaddrinfo.o inet_aton.o snprintf.o strerror.o path.o threads.o, $(LIBOBJS)) + $(filter crypt.o getaddrinfo.o inet_aton.o snprintf.o strerror.o path.o thread.o, $(LIBOBJS)) # Add libraries that libpq depends (or might depend) on into the @@ -46,7 +46,7 @@ backend_src = $(top_srcdir)/src/backend # For port modules, this only happens if configure decides the module # is needed (see filter hack in OBJS, above). -crypt.c getaddrinfo.c inet_aton.c snprintf.c strerror.c path.c threads.c: %.c : $(top_srcdir)/src/port/%.c +crypt.c getaddrinfo.c inet_aton.c snprintf.c strerror.c path.c thread.c: %.c : $(top_srcdir)/src/port/%.c rm -f $@ && $(LN_S) $< . # compile this with thread flags @@ -79,4 +79,4 @@ uninstall: uninstall-lib rm -f $(DESTDIR)$(includedir)/libpq-fe.h $(DESTDIR)$(includedir_internal)/libpq-int.h $(includedir_internal)/pqexpbuffer.h clean distclean maintainer-clean: clean-lib - rm -f $(OBJS) crypt.c getaddrinfo.c inet_aton.c snprintf.c strerror.c path.c dllist.c md5.c ip.c wchar.c encnames.c threads.c + rm -f $(OBJS) crypt.c getaddrinfo.c inet_aton.c snprintf.c strerror.c path.c dllist.c md5.c ip.c wchar.c encnames.c thread.c diff --git a/src/port/thread.c b/src/port/thread.c new file mode 100644 index 0000000000..8eb5bf5482 --- /dev/null +++ b/src/port/thread.c @@ -0,0 +1,87 @@ +/*------------------------------------------------------------------------- + * + * threads.c + * + * Prototypes and macros around system calls, used to help make + * threaded libraries reentrant and safe to use from threaded applications. + * + * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group + * + * $Id: thread.c,v 1.1 2003/08/08 02:46:40 momjian Exp $ + * + *------------------------------------------------------------------------- + */ + +#include "postgres.h" + +/* + * Wrapper around strerror and strerror_r to use the former if it is + * available and also return a more useful value (the error string). + */ +char * +pqStrerror(int errnum, char *strerrbuf, size_t buflen) +{ +#if defined(USE_THREADS) && defined(HAVE_STRERROR_R) + /* reentrant strerror_r is available */ + /* some early standards had strerror_r returning char * */ + strerror_r(errnum, strerrbuf, buflen); + return (strerrbuf); +#else + /* no strerror_r() available, just use strerror */ + return strerror(errnum); +#endif +} + +/* + * Wrapper around getpwuid() or getpwuid_r() to mimic POSIX getpwuid_r() + * behaviour, if it is not available. + */ +int +pqGetpwuid(uid_t uid, struct passwd * resultbuf, char *buffer, + size_t buflen, struct passwd ** result) +{ +#if defined(USE_THREADS) && defined(HAVE_GETPWUID_R) + + /* + * broken (well early POSIX draft) getpwuid_r() which returns 'struct + * passwd *' + */ + *result = getpwuid_r(uid, resultbuf, buffer, buflen); +#else + /* no getpwuid_r() available, just use getpwuid() */ + *result = getpwuid(uid); +#endif + return (*result == NULL) ? -1 : 0; +} + +/* + * Wrapper around gethostbyname() or gethostbyname_r() to mimic + * POSIX gethostbyname_r() behaviour, if it is not available. + */ +int +pqGethostbyname(const char *name, + struct hostent * resbuf, + char *buf, size_t buflen, + struct hostent ** result, + int *herrno) +{ +#if defined(USE_THREADS) && defined(HAVE_GETHOSTBYNAME_R) + + /* + * broken (well early POSIX draft) gethostbyname_r() which returns + * 'struct hostent *' + */ + *result = gethostbyname_r(name, resbuf, buf, buflen, herrno); + return (*result == NULL) ? -1 : 0; +#else + /* no gethostbyname_r(), just use gethostbyname() */ + *result = gethostbyname(name); + if (*result != NULL) + return 0; + else + { + *herrno = h_errno; + return -1; + } +#endif +} diff --git a/src/port/threads.c b/src/port/threads.c deleted file mode 100644 index 659f5cd100..0000000000 --- a/src/port/threads.c +++ /dev/null @@ -1,87 +0,0 @@ -/*------------------------------------------------------------------------- - * - * threads.c - * - * Prototypes and macros around system calls, used to help make - * threaded libraries reentrant and safe to use from threaded applications. - * - * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group - * - * $Id: threads.c,v 1.2 2003/08/04 00:43:33 momjian Exp $ - * - *------------------------------------------------------------------------- - */ - -#include "postgres.h" - -/* - * Wrapper around strerror and strerror_r to use the former if it is - * available and also return a more useful value (the error string). - */ -char * -pqStrerror(int errnum, char *strerrbuf, size_t buflen) -{ -#if defined(USE_THREADS) && defined(HAVE_STRERROR_R) - /* reentrant strerror_r is available */ - /* some early standards had strerror_r returning char * */ - strerror_r(errnum, strerrbuf, buflen); - return (strerrbuf); -#else - /* no strerror_r() available, just use strerror */ - return strerror(errnum); -#endif -} - -/* - * Wrapper around getpwuid() or getpwuid_r() to mimic POSIX getpwuid_r() - * behaviour, if it is not available. - */ -int -pqGetpwuid(uid_t uid, struct passwd * resultbuf, char *buffer, - size_t buflen, struct passwd ** result) -{ -#if defined(USE_THREADS) && defined(HAVE_GETPWUID_R) - - /* - * broken (well early POSIX draft) getpwuid_r() which returns 'struct - * passwd *' - */ - *result = getpwuid_r(uid, resultbuf, buffer, buflen); -#else - /* no getpwuid_r() available, just use getpwuid() */ - *result = getpwuid(uid); -#endif - return (*result == NULL) ? -1 : 0; -} - -/* - * Wrapper around gethostbyname() or gethostbyname_r() to mimic - * POSIX gethostbyname_r() behaviour, if it is not available. - */ -int -pqGethostbyname(const char *name, - struct hostent * resbuf, - char *buf, size_t buflen, - struct hostent ** result, - int *herrno) -{ -#if defined(USE_THREADS) && defined(HAVE_GETHOSTBYNAME_R) - - /* - * broken (well early POSIX draft) gethostbyname_r() which returns - * 'struct hostent *' - */ - *result = gethostbyname_r(name, resbuf, buf, buflen, herrno); - return (*result == NULL) ? -1 : 0; -#else - /* no gethostbyname_r(), just use gethostbyname() */ - *result = gethostbyname(name); - if (*result != NULL) - return 0; - else - { - *herrno = h_errno; - return -1; - } -#endif -} -- cgit v1.2.3