Several fixes to make dma build on non-BSD OS's:
- replace open(..., O_EXLOCK) with a new open_locked() routine;
- define the __unused function attribute;
- do not redefine PATH_MAX.

All of these are taken from the Ringlet Subversion repository:
http://svn.ringlet.net/svn/ringlet/mail/dma/
http://svn.ringlet.net/cgi-bin/viewvc/viewvc.cgi/ringlet/mail/dma/

--- a/dma.c
+++ b/dma.c
@@ -74,6 +74,8 @@
 static int daemonize = 1;
 struct config *config;
 
+static int open_locked(const char *, int);
+
 char *
 hostname(void)
 {
@@ -542,7 +544,7 @@
 	}
 
 	/* mailx removes users mailspool file if empty, so open with O_CREAT */
-	mbox = open(fn, O_WRONLY | O_EXLOCK | O_APPEND | O_CREAT);
+	mbox = open_locked(fn, O_WRONLY | O_APPEND | O_CREAT);
 	if (mbox < 0) {
 		syslog(LOG_ERR, "%s: local delivery deferred: can not open `%s': %m",
 		       it->queueid, fn);
@@ -703,7 +705,7 @@
 			continue;
 		if (asprintf(&queuefn, "%s/%s", config->spooldir, de->d_name) < 0)
 			goto fail;
-		fd = open(queuefn, O_RDONLY|O_EXLOCK|O_NONBLOCK);
+		fd = open_locked(queuefn, O_RDONLY|O_NONBLOCK);
 		if (fd < 0) {
 			/* Ignore locked files */
 			if (errno == EWOULDBLOCK)
@@ -962,3 +964,24 @@
 	/* NOTREACHED */
 	return (0);
 }
+
+static int
+open_locked(const char *fname, int flags)
+{
+#ifndef O_EXLOCK
+	int fd, save_errno;
+
+	fd = open(fname, flags, 0);
+	if (fd < 0)
+		return(fd);
+	if (flock(fd, LOCK_EX|((flags & O_NONBLOCK)? LOCK_NB: 0)) < 0) {
+		save_errno = errno;
+		close(fd);
+		errno = save_errno;
+		return(-1);
+	}
+	return(fd);
+#else
+	return(open(fname, flags|O_EXLOCK));
+#endif
+}
--- a/dma.h
+++ b/dma.h
@@ -46,6 +46,13 @@
 #include <stdint.h>
 #include <stdio.h>
 
+#ifndef __unused
+#ifdef __GNUC__
+#define __unused	__attribute__((unused))
+#else
+#define __unused
+#endif  /* __GNUC__ */
+#endif
 
 #define VERSION	"DragonFly Mail Agent"
 
@@ -53,7 +60,9 @@
 #define MIN_RETRY	300		/* 5 minutes */
 #define MAX_RETRY	(3*60*60)	/* retry at least every 3 hours */
 #define MAX_TIMEOUT	(5*24*60*60)	/* give up after 5 days */
+#ifndef PATH_MAX
 #define PATH_MAX	1024		/* Max path len */
+#endif
 #define	SMTP_PORT	25		/* Default SMTP port */
 #define CON_TIMEOUT	120		/* Connection timeout */
 
