summaryrefslogtreecommitdiff
path: root/appl/cmd/chgrp.b
diff options
context:
space:
mode:
authorCharles.Forsyth <devnull@localhost>2006-12-22 17:07:39 +0000
committerCharles.Forsyth <devnull@localhost>2006-12-22 17:07:39 +0000
commit37da2899f40661e3e9631e497da8dc59b971cbd0 (patch)
treecbc6d4680e347d906f5fa7fca73214418741df72 /appl/cmd/chgrp.b
parent54bc8ff236ac10b3eaa928fd6bcfc0cdb2ba46ae (diff)
20060303a
Diffstat (limited to 'appl/cmd/chgrp.b')
-rw-r--r--appl/cmd/chgrp.b58
1 files changed, 58 insertions, 0 deletions
diff --git a/appl/cmd/chgrp.b b/appl/cmd/chgrp.b
new file mode 100644
index 00000000..ec473759
--- /dev/null
+++ b/appl/cmd/chgrp.b
@@ -0,0 +1,58 @@
+implement Chgrp;
+
+include "sys.m";
+ sys: Sys;
+
+include "draw.m";
+
+include "arg.m";
+
+Chgrp: module
+{
+ init: fn(nil: ref Draw->Context, nil: list of string);
+};
+
+usage()
+{
+ sys->fprint(sys->fildes(2), "usage: chgrp [-uo] group file ...\n");
+ raise "fail:usage";
+}
+
+init(nil: ref Draw->Context, args: list of string)
+{
+ sys = load Sys Sys->PATH;
+
+ arg := load Arg Arg->PATH;
+ if(arg == nil){
+ sys->fprint(sys->fildes(2), "chgrp: can't load %s: %r\n", Arg->PATH);
+ raise "fail:load";
+ }
+ setuser := 0;
+ arg->init(args);
+ while((o := arg->opt()) != 0)
+ case o {
+ 'o' or 'u' =>
+ setuser = 1;
+ * =>
+ usage();
+ }
+ args = arg->argv();
+ arg = nil;
+ if(args == nil)
+ usage();
+ id := hd args;
+ err := 0;
+ while((args = tl args) != nil){
+ d := sys->nulldir;
+ if(setuser)
+ d.uid = id;
+ else
+ d.gid = id;
+ if(sys->wstat(hd args, d) < 0){
+ sys->fprint(sys->fildes(2), "chgrp: can't change %s: %r\n", hd args);
+ err = 1;
+ }
+ }
+ if(err)
+ raise "fail:error";
+}