summaryrefslogtreecommitdiff
path: root/trans/null.c
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>1999-12-03 20:47:58 +0000
committerRoland McGrath <roland@gnu.org>1999-12-03 20:47:58 +0000
commitf6b9e57fdef3d89c11c36aec94173d6f565839fa (patch)
tree8b63192cdea403e5b11da9d142b33dc85be2860f /trans/null.c
parent71864184ef2e98c8b75e546e92252e2b71662749 (diff)
1999-12-03 Roland McGrath <roland@baalperazim.frob.com>
* null.c: Support --full/-f option to be /dev/full (ENOSPC writes). (write_error_code): New variable. (options, argp): New static const variables. (parse_opt): New function. (main): Move local ARGP out to static. (trivfs_S_io_write): Return write_error_code instead of zero.
Diffstat (limited to 'trans/null.c')
-rw-r--r--trans/null.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/trans/null.c b/trans/null.c
index 2729a639..ecec5c94 100644
--- a/trans/null.c
+++ b/trans/null.c
@@ -34,13 +34,37 @@
const char *argp_program_version = STANDARD_HURD_VERSION (null);
+/* Error code to return for write attempts.
+ If zero, they succeed in writing to the bitbucket. */
+static error_t write_error_code;
+
+static const struct argp_option options[] =
+{
+ {"full", 'f', 0, 0, "Cause writes to fail as if to a full disk"},
+ {0}
+};
+
+static error_t
+parse_opt (int opt, char *arg, struct argp_state *state)
+{
+ switch (opt)
+ {
+ case 'f':
+ write_error_code = ENOSPC;
+ return 0;
+ }
+ return ARGP_ERR_UNKNOWN;
+}
+
+static const struct argp argp =
+{ options, parse_opt, 0, "Endless sink and null source" };
+
int
main (int argc, char **argv)
{
error_t err;
mach_port_t bootstrap;
struct trivfs_control *fsys;
- const struct argp argp = { 0, 0, 0, "Endless sink and null source" };
argp_parse (&argp, argc, argv, 0, 0, 0);
@@ -197,7 +221,7 @@ trivfs_S_io_write (struct trivfs_protid *cred,
else if (!(cred->po->openmodes & O_WRITE))
return EBADF;
*amt = datalen;
- return 0;
+ return write_error_code;
}
/* Truncate file. */