-fishdescriptor-donate.so: donate.o
- $(CC) -shared -Wl,-soname $(LIBCANON) -o $@ $< $(LIBS)
+OPTIMISE = -O2
+DEBUG = -g
+
+CFLAGS = -Wall -Werror -Wwrite-strings
+CFLAGS += $(OPTIMISE) $(DEBUG)
+
+MAJOR=1
+MINOR=0
+LIBCANON= libfishdescriptor-donate.so.$(MAJOR)
+LIBTARGET= $(LIBCANON).$(MINOR)
+
+$(LIBTARGET): donate.o
+ $(CC) -shared -Wl,-soname -Wl,$(LIBCANON) -o $@ $< $(LIBS)
donate.o: donate.c
#include <stdlib.h>
#include <errno.h>
+#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
int carrier=-1;
carrier = socket(AF_UNIX, SOCK_STREAM, 0);
- if (carrier < 0) goto out;
+ if (carrier < 0) { r=-1; goto out; }
struct sockaddr_un suna;
memset(&suna,0,sizeof(suna));
suna.sun_family = AF_UNIX;
- if (strlen(path) >= sizeof(suna.sun_path)) { errno = E2BIG; goto out; }
+ if (strlen(path) >= sizeof(suna.sun_path)) { errno=E2BIG; r=-1; goto out; }
strcpy(suna.sun_path, path);
r = connect(carrier, (const struct sockaddr*)&suna, sizeof(suna));
out:
if (carrier >= 0) close(carrier);
r = !r ? 0 : !errno ? EIO : errno;
- esave = errno;
+ errno = esave;
return r;
}