Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
#include "noerr.h"
#include <unistd.h>
#include <errno.h>
+#include <stdlib.h>
int close_noerr(int fd)
{
errno = saved_errno;
return ret;
}
+
+void free_noerr(void *p)
+{
+ int saved_errno = errno;
+ free(p);
+ errno = saved_errno;
+}
*/
int unlink_noerr(const char *pathname);
+/**
+ * free_noerr - free memory without stomping errno.
+ * @p: the pointer to free.
+ *
+ * errno is saved and restored across the call to free: the standard leaves
+ * that undefined.
+ */
+void free_noerr(void *p);
#endif /* NOERR_H */
int fd;
FILE *fp;
- plan_tests(15);
+ plan_tests(16);
/* Should fail to unlink. */
ok1(unlink(name) != 0);
ok1(errno == ENOENT);
ok1(errno == 100);
unlink(name);
+ errno = 101;
+ free_noerr(malloc(7));
+ ok1(errno == 101);
+
return exit_status();
}