3030#include "strv.h"
3131#include "time-util.h"
3232#include "tmpfile-util.h"
33+ #include "umask-util.h"
3334#include "user-util.h"
3435#include "util.h"
3536
3637int unlink_noerrno (const char * path ) {
3738 PROTECT_ERRNO ;
38- int r ;
39-
40- r = unlink (path );
41- if (r < 0 )
42- return - errno ;
43-
44- return 0 ;
39+ return RET_NERRNO (unlink (path ));
4540}
4641
4742int rmdir_parents (const char * path , const char * stop ) {
@@ -97,8 +92,8 @@ int rename_noreplace(int olddirfd, const char *oldpath, int newdirfd, const char
9792 * want — though not atomic (i.e. for a short period both the new and the old filename will exist). */
9893 if (linkat (olddirfd , oldpath , newdirfd , newpath , 0 ) >= 0 ) {
9994
100- if (unlinkat (olddirfd , oldpath , 0 ) < 0 ) {
101- r = - errno ; /* Backup errno before the following unlinkat() alters it */
95+ r = RET_NERRNO (unlinkat (olddirfd , oldpath , 0 ));
96+ if ( r < 0 ) {
10297 (void ) unlinkat (newdirfd , newpath , 0 );
10398 return r ;
10499 }
@@ -117,10 +112,7 @@ int rename_noreplace(int olddirfd, const char *oldpath, int newdirfd, const char
117112 if (errno != ENOENT )
118113 return - errno ;
119114
120- if (renameat (olddirfd , oldpath , newdirfd , newpath ) < 0 )
121- return - errno ;
122-
123- return 0 ;
115+ return RET_NERRNO (renameat (olddirfd , oldpath , newdirfd , newpath ));
124116}
125117
126118int readlinkat_malloc (int fd , const char * p , char * * ret ) {
@@ -286,14 +278,9 @@ int fchmod_and_chown_with_fallback(int fd, const char *path, mode_t mode, uid_t
286278}
287279
288280int fchmod_umask (int fd , mode_t m ) {
289- mode_t u ;
290- int r ;
291-
292- u = umask (0777 );
293- r = fchmod (fd , m & (~u )) < 0 ? - errno : 0 ;
294- umask (u );
281+ _cleanup_umask_ mode_t u = umask (0777 );
295282
296- return r ;
283+ return RET_NERRNO ( fchmod ( fd , m & (~ u ))) ;
297284}
298285
299286int fchmod_opath (int fd , mode_t m ) {
@@ -822,7 +809,7 @@ int unlinkat_deallocate(int fd, const char *name, UnlinkDeallocateFlags flags) {
822809
823810int open_parent (const char * path , int flags , mode_t mode ) {
824811 _cleanup_free_ char * parent = NULL ;
825- int fd , r ;
812+ int r ;
826813
827814 r = path_extract_directory (path , & parent );
828815 if (r < 0 )
@@ -836,11 +823,7 @@ int open_parent(const char *path, int flags, mode_t mode) {
836823 else if (!FLAGS_SET (flags , O_TMPFILE ))
837824 flags |= O_DIRECTORY |O_RDONLY ;
838825
839- fd = open (parent , flags , mode );
840- if (fd < 0 )
841- return - errno ;
842-
843- return fd ;
826+ return RET_NERRNO (open (parent , flags , mode ));
844827}
845828
846829int conservative_renameat (
0 commit comments