fd = dup(fd);
if (fd == -1)
return 0;
- fcntl(fd, F_SETFD, FD_CLOEXEC);
+ solv_setcloexec(fd, 1);
fp = solv_xfopen_fd(fn, fd, mode);
if (!fp) {
close(fd);
if (!fp)
return 0;
if (fileno(fp) != -1)
- fcntl(fileno(fp), F_SETFD, FD_CLOEXEC);
+ solv_setcloexec(fileno(fp), 1);
sfp = solv_calloc(1, sizeof(SolvFp));
sfp->fp = fp;
return sfp;
void cloexec(bool state) {
if (!$self->fp || fileno($self->fp) == -1)
return;
- fcntl(fileno($self->fp), F_SETFD, state ? FD_CLOEXEC : 0);
+ solv_setcloexec(fileno($self->fp), state);
}
}
solv_realloc;
solv_realloc2;
solv_replacebadutf8;
+ solv_setcloexec;
solv_sort;
solv_strdup;
solv_timems;
if (store->pagefd == -1)
can_seek = 0;
else
- fcntl(store->pagefd, F_SETFD, FD_CLOEXEC);
+ solv_setcloexec(store->pagefd, 1);
#ifdef DEBUG_PAGING
fprintf(stderr, "can %sseek\n", can_seek ? "" : "NOT ");
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
+#include <fcntl.h>
#include <sys/time.h>
#include "util.h"
return r - subtract;
}
+int
+solv_setcloexec(int fd, int state)
+{
+ return fcntl(fd, F_SETFD, state ? FD_CLOEXEC : 0) == 0;
+}
+
/* bsd's qsort_r has different arguments, so we define our
own version in case we need to do some clever mapping
extern char *solv_strdup(const char *);
extern void solv_oom(size_t, size_t);
extern unsigned int solv_timems(unsigned int subtract);
+extern int solv_setcloexec(int fd, int state);
extern void solv_sort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *, void *), void *compard);
extern char *solv_dupjoin(const char *str1, const char *str2, const char *str3);
extern char *solv_dupappend(const char *str1, const char *str2, const char *str3);