wc: Added wc
[mutos-utils.git] / chroot.c
blob0c61e04ccb3115126fc1fab0cf84f3e56e1133b5
1 /*
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.
15 #include <stdio.h>
16 #include <unistd.h>
17 #include <errno.h>
18 #include <string.h>
20 #define VERSION "0.01"
22 int main(int argc, char* argv[])
24 if (argc == 1) {
25 fprintf(stderr, "%s: missing operand\n"
26 "Run '%s --help' for usage.\n",
27 argv[0], argv[0]);
28 return 1;
31 // flag parsing
32 int arg = 0;
33 for (arg = 1; arg < argc; arg++)
35 if (strcmp(argv[arg], "--help") == 0) {
36 printf("Usage: %s [newroot]\n", argv[0]);
37 return 0;
38 } else if (strcmp(argv[arg], "--version") == 0) {
39 printf("chroot (mutos) v"VERSION"\n");
40 return 0;
41 } else {
42 break;
46 chdir(argv[arg]);
47 int rc = chroot(argv[arg]);
48 if (rc == -1) {
49 fprintf(stderr, "%s: cannot change root directory to %s: %s\n", argv[0], argv[arg], strerror(errno));
50 return 125;
53 return 0;