]> www.infradead.org Git - mtd-utils.git/commitdiff
libmtd: use O_CLOEXEC
authorMike Frysinger <vapier@gentoo.org>
Tue, 7 Jun 2011 06:19:05 +0000 (02:19 -0400)
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Tue, 7 Jun 2011 06:52:51 +0000 (09:52 +0300)
Not strictly necessary, but this is good library behavior and
should carry no runtime overhead.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
include/common.h
lib/libmtd.c

index c37660c50ad4bc81482a58694adf7bae64b21b6e..7ea282c81373f237e8bd9b90cc4ca000371af372 100644 (file)
@@ -23,6 +23,7 @@
 #include <stdlib.h>
 #include <ctype.h>
 #include <string.h>
+#include <fcntl.h>
 #include <errno.h>
 
 #ifndef PROGRAM_NAME
@@ -42,6 +43,10 @@ extern "C" {
 #define min(a, b) MIN(a, b) /* glue for linux kernel source */
 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
 
+#ifndef O_CLOEXEC
+#define O_CLOEXEC 0
+#endif
+
 /* Verbose messages */
 #define bareverbose(verbose, fmt, ...) do {                        \
        if (verbose)                                               \
index 7fabd8067961e20a27e6f6d9734a10e1510be24c..a6518083af7eae5f7b3c69adfc2dc0040d74b2fe 100644 (file)
@@ -77,7 +77,7 @@ static int read_data(const char *file, void *buf, int buf_len)
 {
        int fd, rd, tmp, tmp1;
 
-       fd = open(file, O_RDONLY);
+       fd = open(file, O_RDONLY | O_CLOEXEC);
        if (fd == -1)
                return -1;
 
@@ -201,7 +201,7 @@ static int read_hex_ll(const char *file, long long *value)
        int fd, rd;
        char buf[50];
 
-       fd = open(file, O_RDONLY);
+       fd = open(file, O_RDONLY | O_CLOEXEC);
        if (fd == -1)
                return -1;
 
@@ -253,7 +253,7 @@ static int read_pos_ll(const char *file, long long *value)
        int fd, rd;
        char buf[50];
 
-       fd = open(file, O_RDONLY);
+       fd = open(file, O_RDONLY | O_CLOEXEC);
        if (fd == -1)
                return -1;
 
@@ -538,7 +538,7 @@ static int sysfs_is_supported(struct libmtd *lib)
                return 0;
 
        sprintf(file, lib->mtd_name, num);
-       fd = open(file, O_RDONLY);
+       fd = open(file, O_RDONLY | O_CLOEXEC);
        if (fd == -1)
                return 0;
 
@@ -1193,7 +1193,7 @@ int mtd_write_img(const struct mtd_dev_info *mtd, int fd, int eb, int offs,
                return -1;
        }
 
-       in_fd = open(img_name, O_RDONLY);
+       in_fd = open(img_name, O_RDONLY | O_CLOEXEC);
        if (in_fd == -1)
                return sys_errmsg("cannot open \"%s\"", img_name);