summaryrefslogtreecommitdiff
path: root/coccinelle/fopen-unlocked.cocci
diff options
context:
space:
mode:
Diffstat (limited to 'coccinelle/fopen-unlocked.cocci')
-rw-r--r--coccinelle/fopen-unlocked.cocci37
1 files changed, 37 insertions, 0 deletions
diff --git a/coccinelle/fopen-unlocked.cocci b/coccinelle/fopen-unlocked.cocci
new file mode 100644
index 0000000000..93b993dd55
--- /dev/null
+++ b/coccinelle/fopen-unlocked.cocci
@@ -0,0 +1,37 @@
+@@
+expression f, path, options;
+@@
+- f = fopen(path, options);
+- if (!f)
+- return -errno;
+- (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
++ r = fopen_unlocked(path, options, &f);
++ if (r < 0)
++ return r;
+@@
+expression f, path, options;
+@@
+- f = fopen(path, options);
+- if (!f) {
+- if (errno == ENOENT)
+- return -ESRCH;
+- return -errno;
+- }
+- (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
++ r = fopen_unlocked(path, options, &f);
++ if (r == -ENOENT)
++ return -ESRCH;
++ if (r < 0)
++ return r;
+@@
+expression f, path, options;
+@@
+- f = fopen(path, options);
+- if (!f)
+- return errno == ENOENT ? -ESRCH : -errno;
+- (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
++ r = fopen_unlocked(path, options, &f);
++ if (r == -ENOENT)
++ return -ESRCH;
++ if (r < 0)
++ return r;