#define _LARGEFILE64_SOURCE
#define _GNU_SOURCE
+#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
#include <sys/stat.h>
#include <linux/fs.h>
-#define errp(msg, args...) \
- do { \
- printf("%s: " msg ": %m\n", program_invocation_short_name, ## args); \
- exit(1); \
- } while (0)
-
static unsigned long long mbps(struct timespec *stime, struct timespec *etime, off_t len)
{
uint64_t dtime;
{
uint64_t size;
if (ioctl(fd, BLKGETSIZE64, &size))
- errp("ioctl(BLKGETSIZE64) failed");
+ err(1, "ioctl(BLKGETSIZE64) failed");
return size;
}
struct stat st;
if (fstat(fd, &st))
- errp("could not stat %i", fd);
+ err(1, "could not stat %i", fd);
if (S_ISREG(st.st_mode))
return st.st_size;
return get_blk_size(fd);
errno = EINVAL;
- errp("unknown type of file");
+ err(1, "unknown type of file");
}
static void nuke(int fd, off_t offset, off_t max_size, unsigned char pattern)
printf("Writing 0x%X to the output\n", pattern);
if (lseek(fd, offset, SEEK_SET) != offset)
- errp("lseek(%"PRIu64"u) failed", offset);
+ err(1, "lseek(%"PRIu64"u) failed", offset);
unsigned long long speed = 0;
struct timespec stime, etime, itime;
return;
}
- printf("%'llu bytes %u%% (%'llu MB/s)%20s\r", (unsigned long long)pos,
- (unsigned)((pos * 100) / max_size), speed, "");
+ printf("\r\e[2K%'llu bytes %u%% (%'llu MB/s)", (unsigned long long)pos,
+ (unsigned)((pos * 100) / max_size), speed);
if ((++fsync_pos % 32) == 0) {
speed = mbps(&stime, &etime, pos - last_pos);
case 'r':
random = true;
break;
- case 'h': usage(EX_OK);
- default: usage(EX_USAGE);
+ case 'h':
+ usage(EX_OK);
+ break;
+ default:
+ usage(EX_USAGE);
+ break;
}
}
if (argc != optind + 1)
int fd = open(file, O_WRONLY|O_CLOEXEC);
if (fd == -1)
- errp("open(%s) failed", file);
+ err(1, "open(%s) failed", file);
off_t max_size = get_size(fd);