[libglnx] Don't touch errno in glnx_fd_close
- From: Alexander Larsson <alexl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libglnx] Don't touch errno in glnx_fd_close
- Date: Thu, 10 Mar 2016 22:26:46 +0000 (UTC)
commit 69d8a597f768f811f7c924a784af834f637eeb20
Author: Alexander Larsson <alexl redhat com>
Date: Thu Mar 10 23:12:07 2016 +0100
Don't touch errno in glnx_fd_close
We're ignoring the result from the close, but it can still affect
errno, which is bad if you use this in functions that sets
errno, because errno can unexpectedly change after you've set it.
glnx-local-alloc.h | 9 +++++++--
1 files changed, 7 insertions(+), 2 deletions(-)
---
diff --git a/glnx-local-alloc.h b/glnx-local-alloc.h
index af5af4b..f628b61 100644
--- a/glnx-local-alloc.h
+++ b/glnx-local-alloc.h
@@ -21,6 +21,7 @@
#pragma once
#include <gio/gio.h>
+#include <errno.h>
G_BEGIN_DECLS
@@ -195,13 +196,17 @@ GLNX_DEFINE_CLEANUP_FUNCTION0(GKeyFile*, glnx_local_keyfile_unref, g_key_file_un
static inline void
glnx_cleanup_close_fdp (int *fdp)
{
- int fd;
+ int fd, errsv;
g_assert (fdp);
fd = *fdp;
if (fd != -1)
- (void) close (fd);
+ {
+ errsv = errno;
+ (void) close (fd);
+ errno = errsv;
+ }
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]