diff options
author | Leah Neukirchen <leah@vuxu.org> | 2018-11-13 13:25:35 +0100 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2018-11-13 13:25:35 +0100 |
commit | 41098c38510c75ba539dd14ba23410cbe381037b (patch) | |
tree | c453507ae4a629c53470461f474493d44ca94d43 /mdirs.c | |
parent | 7ea96a6dea012cbb22878ac3961cbc703de04291 (diff) | |
download | mblaze-41098c38510c75ba539dd14ba23410cbe381037b.tar.gz mblaze-41098c38510c75ba539dd14ba23410cbe381037b.tar.xz mblaze-41098c38510c75ba539dd14ba23410cbe381037b.zip |
mdirs: reset cwd after each iteration
Else `mdirs dir1/a dir2/b` fails, as the first iteration remains in `dir1`. Found by milliardo.
Diffstat (limited to 'mdirs.c')
-rw-r--r-- | mdirs.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/mdirs.c b/mdirs.c index 9789b65..18ba9da 100644 --- a/mdirs.c +++ b/mdirs.c @@ -83,8 +83,19 @@ usage: if (argc == optind) goto usage; - for (i = 0; i < argc; i++) + char toplevel[PATH_MAX]; + if (!getcwd(toplevel, sizeof toplevel)) { + perror("mdirs: getcwd"); + exit(-1); + } + + for (i = 0; i < argc; i++) { mdirs(argv[i]); + if (chdir(toplevel) < 0) { + perror("mdirs: chdir"); + exit(-1); + } + } return 0; } |