1
0
mirror of https://github.com/systemd/systemd.git synced 2024-10-29 21:55:36 +03:00
systemd/coccinelle/fopen-unlocked.cocci

72 lines
1.5 KiB
Plaintext
Raw Normal View History

2019-04-04 11:17:16 +03:00
@@
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);
2019-04-04 12:27:08 +03:00
@@
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);
2019-04-04 12:46:44 +03:00
@@
expression f, buf, sz;
@@
- f = open_memstream(&buf, &sz);
+ f = open_memstream_unlocked(&buf, &sz);
if (!f)
return ...;
- (void) __fsetlocking(f, FSETLOCKING_BYCALLER);