summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLAN-TW <lantw44@gmail.com>2013-11-10 23:00:16 +0800
committerLAN-TW <lantw44@gmail.com>2013-11-10 23:00:16 +0800
commita6043e2df6477ec148d8ec7441afec8134ec1b9b (patch)
treecbcb1c156775720a7c79bdd2726fbf8557f59f26
parent2d283af61c9ed5da47d33d0b59ed2814eb9e107e (diff)
downloadcn2013-a6043e2df6477ec148d8ec7441afec8134ec1b9b.tar.gz
cn2013-a6043e2df6477ec148d8ec7441afec8134ec1b9b.tar.zst
cn2013-a6043e2df6477ec148d8ec7441afec8134ec1b9b.zip
HW1: 修正暫存資料夾可能無法產生的問題
-rw-r--r--hw1/shell.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/hw1/shell.c b/hw1/shell.c
index af8e5d5..c58548c 100644
--- a/hw1/shell.c
+++ b/hw1/shell.c
@@ -600,15 +600,16 @@ static int ras_shell_init (RasShell* shell, int argc, char* argv[]) {
}
}
- char* tmpdir = xstrcat ("/tmp/", argv[0], "-XXXXXX", NULL);
+ shell->name = strrchr (argv[0], '/');
+ shell->name = shell->name == NULL ? argv[0] : shell->name + 1;
+
+ char* tmpdir = xstrcat ("/tmp/", shell->name, "-XXXXXX", NULL);
if (mkdtemp (tmpdir) < 0) {
- fprintf (stderr, "%s: mkdtemp: %s\n", argv[0], strerror (errno));
+ fprintf (stderr, "%s: mkdtemp: %s\n", shell->name, strerror (errno));
free (tmpdir);
return -1;
}
- shell->name = strrchr (argv[0], '/');
- shell->name = shell->name == NULL ? argv[0] : shell->name + 1;
shell->count = 1;
shell->saved_list = list_create ();
shell->saved_tmpdir = tmpdir;