2 Copyright © 2013 Alastair Stuart
4 This program is open source software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
21 #define VERSION "0.01"
23 int main(int argc
, char* argv
[])
26 fprintf(stderr
, "%s: missing operand\n"
27 "Run '%s --help' for usage.\n",
34 for (arg
= 1; arg
< argc
; arg
++)
36 if (strcmp(argv
[arg
], "--help") == 0) {
37 printf("Usage: %s [group] [file ...]\n", argv
[0]);
39 } else if (strcmp(argv
[arg
], "--version") == 0) {
40 printf("chgrp (mutos) v"VERSION
"\n");
47 struct group
*group
= getgrnam(argv
[arg
]);
50 fprintf(stderr
, "%s: invalid group: '%s'\n", argv
[0], argv
[arg
]);
54 arg
++; // go to next arg
57 fprintf(stderr
, "%s: No file specified\n", argv
[0]);
61 for ( ; arg
< argc
; arg
++)
63 int rc
= chown(argv
[arg
], -1, group
->gr_gid
);
65 fprintf(stderr
, "%s: %s: %s\n", argv
[0], strerror(errno
), argv
[arg
]);