summaryrefslogtreecommitdiff
path: root/src/dd.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2000-11-25 07:20:51 +0000
committerJim Meyering <jim@meyering.net>2000-11-25 07:20:51 +0000
commit7d57b3419605e20c8b206c1f5902e54a2611ac75 (patch)
tree6aae50efea4b4c1c4ec0e04fa2d4aaff0bf834fc /src/dd.c
parentc8a0eec3f6317847d44e6cbba5fe80c2639cf25a (diff)
downloadcoreutils-7d57b3419605e20c8b206c1f5902e54a2611ac75.tar.xz
(S_TYPEISSHM): New macro.
(main): Report failed fstat. Complain only when ftruncate fails on a regular file, a directory, or a shared memory object.
Diffstat (limited to 'src/dd.c')
-rw-r--r--src/dd.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/dd.c b/src/dd.c
index 259bfa2de..01447e50a 100644
--- a/src/dd.c
+++ b/src/dd.c
@@ -48,6 +48,10 @@
# define SIGINFO SIGUSR1
#endif
+#ifndef S_TYPEISSHM
+# define S_TYPEISSHM(Mode) 0
+#endif
+
#define ROUND_UP_OFFSET(X, M) ((M) - 1 - (((X) + (M) - 1) % (M)))
#define PTR_ALIGN(Ptr, M) ((Ptr) \
+ ROUND_UP_OFFSET ((char *)(Ptr) - (char *)0, (M)))
@@ -1260,11 +1264,18 @@ main (int argc, char **argv)
o = seek_bytes;
}
- /* Attempt to use ftruncate only if STDOUT refers to a regular file.
- On Linux 2.4.0, ftruncate fails with for non-regular files. */
- if (fstat (STDOUT_FILENO, &stdout_stat) == 0
- && S_ISREG (stdout_stat.st_mode)
- && ftruncate (STDOUT_FILENO, o) < 0)
+ if (fstat (STDOUT_FILENO, &stdout_stat) != 0)
+ error (1, errno, _("cannot fstat %s"), quote (output_file));
+
+ /* Complain only when ftruncate fails on a regular file, a
+ directory, or a shared memory object, as the 2000-08
+ POSIX draft specifies ftruncate's behavior only for these
+ file types. For example, do not complain when Linux 2.4
+ ftruncate fails on /dev/fd0. */
+ if (ftruncate (STDOUT_FILENO, o) != 0
+ && (S_ISREG (stdout_stat.st_mode)
+ || S_ISDIR (stdout_stat.st_mode)
+ || S_TYPEISSHM (stdout_stat.st_mode)))
{
char buf[LONGEST_HUMAN_READABLE + 1];
if (seek_record)