+ if (r < 0) return -1;
+
+ return 0;
+}
+
+static int fishdescriptor_donate(const char *path, const int *fds) {
+ int r;
+ int carrier=-1;
+
+ carrier = socket(AF_UNIX, SOCK_STREAM, 0);
+ if (carrier < 0) goto out;
+
+ struct sockaddr_un suna;
+ memset(suna,0,&suna);
+ suna.sun_family = AF_UNIX;
+ if (strlen(path) >= sizeof(suna.sun_path)) { outno = E2BIG; goto out; }
+ strcpy(suna.sun_path, path);
+
+ int r = connect(carrier, &suna, sizeof(suna));
+ if (r) goto out;
+
+ int nfds;
+ for (nfds=0; fds[nfds] > 0; nfds++);
+
+ r = fishdescriptor_sendmsg_fds(carrier, nfds, fds);
+ if (r) goto out;
+
+ r = 0;
+ out:
+ if (carrier >= 0) close(carrier);
+ return r;