summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStef Walter <stef@memberwebs.com>2005-09-19 16:59:09 +0000
committerStef Walter <stef@memberwebs.com>2005-09-19 16:59:09 +0000
commit954286029633ab21387a3e9dc7f1dfb1bd1108e2 (patch)
treebdf2b2af367c2653ef6861010970c0ec1daaf66e
parentf1dff7c43d00083bb9c10c2c0dbe820a96227ac6 (diff)
Solaris multi threading fixes.
-rw-r--r--ChangeLog1
-rw-r--r--common/compat.c27
-rw-r--r--configure.in2
3 files changed, 25 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index e107c7c..6876a14 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,7 @@
- Fix warnings when compiled with gcc 4.0
- Handle empty addresses properly in logs.
- Don't let exchange send it's strange binary data through the proxy
+ - More Solaris fixes :(
1.5 [2005-07-31]
- Handle condition of server refusing data transfers more gracefully.
diff --git a/common/compat.c b/common/compat.c
index 9828a41..40e4c73 100644
--- a/common/compat.c
+++ b/common/compat.c
@@ -270,6 +270,7 @@ ssize_t getdelim(char** lineptr, size_t* n, int delim, FILE* stream)
{
size_t written = 0;
int allocated, ch;
+ ssize_t ret = -1;
char* p;
if(!n || !lineptr || !stream)
@@ -281,6 +282,11 @@ ssize_t getdelim(char** lineptr, size_t* n, int delim, FILE* stream)
/* Track whether we allocated this or not */
allocated = !(*lineptr);
+#ifdef HAVE_FLOCKFILE
+ /* Affects performance on Solaris. */
+ flockfile(stream);
+#endif
+
for(;;)
{
if(!*lineptr)
@@ -289,26 +295,32 @@ ssize_t getdelim(char** lineptr, size_t* n, int delim, FILE* stream)
/* Reallocate if we need more space */
if(written == *n - 1)
{
- *n = *n ? 256 : *n * 2;
+ *n = *n ? *n * 2 : 256;
if(!(p = (char*)realloc(*lineptr, *n)))
{
if(allocated && *lineptr)
free(*lineptr);
errno = ENOMEM;
- return -1;
+ ret = -1;
+ goto finally;
}
*lineptr = p;
}
while(written < *n - 1)
{
+#ifdef HAVE_FLOCKFILE
+ ch = getc_unlocked(stream);
+#else
ch = fgetc(stream);
+#endif
if(ferror(stream))
{
if(allocated && *lineptr)
free(*lineptr);
- return -1;
+ ret = -1;
+ goto finally;
}
if(ch != EOF)
@@ -318,10 +330,17 @@ ssize_t getdelim(char** lineptr, size_t* n, int delim, FILE* stream)
if(ch == EOF || ch == delim)
{
(*lineptr)[written] = 0;
- return written ? written : -1;
+ ret = written ? written : -1;
+ goto finally;
}
}
}
+finally:
+
+#ifdef HAVE_FLOCKFILE
+ funlockfile(stream);
+#endif
+ return ret;
}
#endif
diff --git a/configure.in b/configure.in
index 6f1acbe..ec3fd34 100644
--- a/configure.in
+++ b/configure.in
@@ -107,7 +107,7 @@ AC_CHECK_GLOBAL(__argv)
AC_CHECK_FUNCS([memset strerror malloc realloc getopt strchr tolower getaddrinfo], ,
[echo "ERROR: Required function missing"; exit 1])
AC_CHECK_FUNCS([strlwr strlcat strlcpy strncat strncpy setenv daemon])
-AC_CHECK_FUNCS([getline getdelim])
+AC_CHECK_FUNCS([getline getdelim flockfile])
# Have to resolve this for the path below
if test "${prefix}" = "NONE"; then