aboutsummaryrefslogtreecommitdiff
path: root/toys/other/mountpoint.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2015-01-25 13:11:58 -0600
committerRob Landley <rob@landley.net>2015-01-25 13:11:58 -0600
commitafd712aabc1b5bb6782489e01b8228b9021232f0 (patch)
treefc0aa4bd8697fb5221013ef7c7beb271726ce900 /toys/other/mountpoint.c
parentb5e72209c79b3e181673d469c8e064ae8b409836 (diff)
downloadtoybox-afd712aabc1b5bb6782489e01b8228b9021232f0.tar.gz
Cleanup mountpoint and remove it from the pending README.
Diffstat (limited to 'toys/other/mountpoint.c')
-rw-r--r--toys/other/mountpoint.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/toys/other/mountpoint.c b/toys/other/mountpoint.c
index 266bea95..150865ca 100644
--- a/toys/other/mountpoint.c
+++ b/toys/other/mountpoint.c
@@ -19,31 +19,33 @@ config MOUNTPOINT
#define FOR_mountpoint
#include "toys.h"
+static void die(char *gripe)
+{
+ if (!(toys.optflags & FLAG_q)) printf("%s: not a %s\n", *toys.optargs, gripe);
+
+ toys.exitval++;
+ xexit();
+}
+
void mountpoint_main(void)
{
struct stat st1, st2;
char *arg = *toys.optargs;
int quiet = toys.optflags & FLAG_q;
- toys.exitval = 1;
- if (((toys.optflags & FLAG_x) ? lstat : stat)(arg, &st1))
- perror_exit("%s", arg);
+ if (lstat(arg, &st1)) perror_exit("%s", arg);
if (toys.optflags & FLAG_x) {
if (S_ISBLK(st1.st_mode)) {
if (!quiet) printf("%u:%u\n", major(st1.st_rdev), minor(st1.st_rdev));
- toys.exitval = 0;
+
return;
}
- if (!quiet) printf("%s: not a block device\n", arg);
- return;
+ die("block device");
}
- // Ignore the fact a file can be a mountpoint for --bind mounts.
- if (!S_ISDIR(st1.st_mode)) {
- if (!quiet) printf("%s: not a directory\n", arg);
- return;
- }
+ // TODO: Ignore the fact a file can be a mountpoint for --bind mounts.
+ if (!S_ISDIR(st1.st_mode)) die("directory");
arg = xmprintf("%s/..", arg);
xstat(arg, &st2);