summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2012-06-22 11:17:38 +0100
committerPádraig Brady <P@draigBrady.com>2012-06-22 11:17:38 +0100
commit30a604e631291b80b9812e03e0f325489ae0d77e (patch)
treedd6c760b0e161c416e1f95ab9c78c76a11981dc9 /src
parent4cfca3916d878afdd0d0b111354f30decc41e8f5 (diff)
downloadcoreutils-30a604e631291b80b9812e03e0f325489ae0d77e.tar.xz
maint: refactor common mode bits used to create files
* src/system.h (MODE_RW_UGO): The new refactored define (666). * src/mkfifo.c: Use the new define. * src/mknod.c: Likewise. * src/split.c: Likewise. * src/system.h: Likewise. * src/touch.c: Likewise. * src/truncate.c: Likewise. Suggested-by: Jim Meyering
Diffstat (limited to 'src')
-rw-r--r--src/dd.c2
-rw-r--r--src/mkfifo.c2
-rw-r--r--src/mknod.c2
-rw-r--r--src/split.c3
-rw-r--r--src/system.h3
-rw-r--r--src/touch.c5
-rw-r--r--src/truncate.c4
7 files changed, 9 insertions, 12 deletions
diff --git a/src/dd.c b/src/dd.c
index 163d514c0..d93733683 100644
--- a/src/dd.c
+++ b/src/dd.c
@@ -2211,7 +2211,7 @@ main (int argc, char **argv)
}
else
{
- mode_t perms = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
+ mode_t perms = MODE_RW_UGO;
int opts
= (output_flags
| (conversions_mask & C_NOCREAT ? 0 : O_CREAT)
diff --git a/src/mkfifo.c b/src/mkfifo.c
index e5c871d14..e524c44c9 100644
--- a/src/mkfifo.c
+++ b/src/mkfifo.c
@@ -114,7 +114,7 @@ main (int argc, char **argv)
_("failed to set default file creation context to %s"),
quote (scontext));
- newmode = (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
+ newmode = MODE_RW_UGO;
if (specified_mode)
{
struct mode_change *change = mode_compile (specified_mode);
diff --git a/src/mknod.c b/src/mknod.c
index 3a6d695af..dc158b440 100644
--- a/src/mknod.c
+++ b/src/mknod.c
@@ -120,7 +120,7 @@ main (int argc, char **argv)
}
}
- newmode = (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
+ newmode = MODE_RW_UGO;
if (specified_mode)
{
struct mode_change *change = mode_compile (specified_mode);
diff --git a/src/split.c b/src/split.c
index 53ee2719d..46d2511ae 100644
--- a/src/split.c
+++ b/src/split.c
@@ -362,8 +362,7 @@ create (const char *name)
{
if (verbose)
fprintf (stdout, _("creating file %s\n"), quote (name));
- return open (name, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
- (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH));
+ return open (name, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, MODE_RW_UGO);
}
else
{
diff --git a/src/system.h b/src/system.h
index 06f09cba6..5e3b3cbde 100644
--- a/src/system.h
+++ b/src/system.h
@@ -30,6 +30,9 @@ you must include <sys/types.h> before including this file
#include <sys/stat.h>
+/* Commonly used file permission combination. */
+#define MODE_RW_UGO (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)
+
#if !defined HAVE_MKFIFO
# define mkfifo(name, mode) mknod (name, (mode) | S_IFIFO, 0)
#endif
diff --git a/src/touch.c b/src/touch.c
index 368516e7d..5976a34c9 100644
--- a/src/touch.c
+++ b/src/touch.c
@@ -131,11 +131,8 @@ touch (const char *file)
else if (! (no_create || no_dereference))
{
/* Try to open FILE, creating it if necessary. */
- int default_permissions =
- S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
fd = fd_reopen (STDIN_FILENO, file,
- O_WRONLY | O_CREAT | O_NONBLOCK | O_NOCTTY,
- default_permissions);
+ O_WRONLY | O_CREAT | O_NONBLOCK | O_NOCTTY, MODE_RW_UGO);
/* Don't save a copy of errno if it's EISDIR, since that would lead
touch to give a bogus diagnostic for e.g., 'touch /' (assuming
diff --git a/src/truncate.c b/src/truncate.c
index e37ab3800..c1e966617 100644
--- a/src/truncate.c
+++ b/src/truncate.c
@@ -244,7 +244,6 @@ main (int argc, char **argv)
off_t size IF_LINT ( = 0);
off_t rsize = -1;
rel_mode_t rel_mode = rm_abs;
- mode_t omode;
int c, fd = -1, oflags;
char const *fname;
@@ -385,11 +384,10 @@ main (int argc, char **argv)
}
oflags = O_WRONLY | (no_create ? 0 : O_CREAT) | O_NONBLOCK;
- omode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
while ((fname = *argv++) != NULL)
{
- if ((fd = open (fname, oflags, omode)) == -1)
+ if ((fd = open (fname, oflags, MODE_RW_UGO)) == -1)
{
/* 'truncate -s0 -c no-such-file' shouldn't gen error
'truncate -s0 no-such-dir/file' should gen ENOENT error