Update configure to generate config.h
[yaz-moved-to-github.git] / src / unix.c
index 6aebb25..56dacc4 100644 (file)
@@ -1,14 +1,14 @@
-/*
- * Copyright (C) 1995-2007, Index Data ApS
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) 1995-2010 Index Data
  * See the file LICENSE for details.
- *
- * $Id: unix.c,v 1.19 2007-06-05 05:42:07 adam Exp $
- * UNIX socket COMSTACK. By Morten Bøgeskov.
  */
 /**
  * \file unix.c
  * \brief Implements UNIX domain socket COMSTACK
  */
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
 
 #ifndef WIN32
 
@@ -41,7 +41,7 @@
 #endif
 
 #include <yaz/unix.h>
-#include <yaz/nmem.h>
+#include <yaz/errno.h>
 
 #ifndef YAZ_SOCKLEN_T
 #define YAZ_SOCKLEN_T int
@@ -55,7 +55,7 @@
 #endif
 #endif
 
-static int unix_close(COMSTACK h);
+static void unix_close(COMSTACK h);
 static int unix_put(COMSTACK h, char *buf, int size);
 static int unix_get(COMSTACK h, char **buf, int *bufsize);
 static int unix_connect(COMSTACK h, void *address);
@@ -68,7 +68,7 @@ static int unix_listen(COMSTACK h, char *raddr, int *addrlen,
 static int unix_set_blocking(COMSTACK p, int blocking);
 
 static COMSTACK unix_accept(COMSTACK h);
-static char *unix_addrstr(COMSTACK h);
+static const char *unix_addrstr(COMSTACK h);
 static void *unix_straddr(COMSTACK h, const char *str);
 
 #ifndef SUN_LEN
@@ -90,7 +90,7 @@ typedef struct unix_state
 
     int written;  /* -1 if we aren't writing */
     int towrite;  /* to verify against user input */
-    int (*complete)(const unsigned char *buf, int len); /* length/comple. */
+    int (*complete)(const char *buf, int len); /* length/complete. */
     struct sockaddr_un addr;  /* returned by cs_straddr */
     int uid;
     int gid;
@@ -160,7 +160,6 @@ COMSTACK unix_type(int s, int flags, int protocol, void *vp)
     p->state = new_socket ? CS_ST_UNBND : CS_ST_IDLE; /* state of line */
     p->event = CS_NONE;
     p->cerrno = 0;
-    p->stackerr = 0;
     p->user = 0;
 
     state->altbuf = 0;
@@ -309,8 +308,7 @@ static int unix_more(COMSTACK h)
 {
     unix_state *sp = (unix_state *)h->cprivate;
 
-    return sp->altlen && (*sp->complete)((unsigned char *) sp->altbuf,
-                                         sp->altlen);
+    return sp->altlen && (*sp->complete)(sp->altbuf, sp->altlen);
 }
 
 /*
@@ -429,8 +427,16 @@ static int unix_bind(COMSTACK h, void *address, int mode)
         h->cerrno = CSYSERR;
         return -1;
     }
-    chown(path, sp->uid, sp->gid);
-    chmod(path, sp->umask != -1 ? sp->umask : 0666);
+    if (chown(path, sp->uid, sp->gid))
+    {
+        h->cerrno = CSYSERR;
+        return -1;
+    }
+    if (chmod(path, sp->umask != -1 ? sp->umask : 0666))
+    {
+        h->cerrno = CSYSERR;
+        return -1;
+    }
     if (mode == CS_SERVER && listen(h->iofile, 100) < 0)
     {
         h->cerrno = CSYSERR;
@@ -575,7 +581,7 @@ static int unix_get(COMSTACK h, char **buf, int *bufsize)
         sp->altsize = tmpi;
     }
     h->io_pending = 0;
-    while (!(berlen = (*sp->complete)((unsigned char *)*buf, hasread)))
+    while (!(berlen = (*sp->complete)(*buf, hasread)))
     {
         if (!*bufsize)
         {
@@ -697,7 +703,7 @@ static int unix_put(COMSTACK h, char *buf, int size)
     return 0;
 }
 
-static int unix_close(COMSTACK h)
+static void unix_close(COMSTACK h)
 {
     unix_state *sp = (struct unix_state *)h->cprivate;
 
@@ -710,10 +716,9 @@ static int unix_close(COMSTACK h)
         xfree(sp->altbuf);
     xfree(sp);
     xfree(h);
-    return 0;
 }
 
-static char *unix_addrstr(COMSTACK h)
+static const char *unix_addrstr(COMSTACK h)
 {
     unix_state *sp = (struct unix_state *)h->cprivate;
     char *buf = sp->buf;
@@ -741,6 +746,7 @@ static int unix_set_blocking(COMSTACK p, int flags)
 /*
  * Local variables:
  * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
  * indent-tabs-mode: nil
  * End:
  * vim: shiftwidth=4 tabstop=8 expandtab