1
0
mirror of https://github.com/systemd/systemd synced 2024-07-01 07:34:28 +00:00
systemd/coccinelle/fopen-unlocked.cocci
Zbigniew Jędrzejewski-Szmek 64b92d637c licensing: add spdx to our .cocci files
Since those are chunks of code based on our codebase, it's easiest to use the
same license.
2021-10-01 14:45:00 +02:00

73 lines
1.6 KiB
Plaintext

/* SPDX-License-Identifier: LGPL-2.1-or-later */
@@
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;
@@
expression f, path, p;
@@
r = fopen_temporary(path, &f, &p);
if (r < 0)
return ...;
- (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
@@
expression f, g, path, p;
@@
r = fopen_temporary_label(path, g, &f, &p);
if (r < 0)
return ...;
- (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
@@
expression f, fd, options;
@@
- f = fdopen(fd, options);
+ r = fdopen_unlocked(fd, options, &f);
+ if (r < 0) {
- if (!f) {
...
- return -errno;
+ return r;
}
- (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
@@
expression f, buf, sz;
@@
- f = open_memstream(&buf, &sz);
+ f = open_memstream_unlocked(&buf, &sz);
if (!f)
return ...;
- (void) __fsetlocking(f, FSETLOCKING_BYCALLER);