vm: fix potential null deref
[minix.git] / commands / ftp101 / local.c
blobc948e1df0853a2f12b68664b7291343c857d95a0
1 /* local.c Copyright 1992-2000 by Michael Temari All Rights Reserved
3 * This file is part of ftp.
6 * 01/25/96 Initial Release Michael Temari, <Michael@TemWare.Com>
7 */
9 #include <sys/types.h>
10 #include <sys/stat.h>
11 #include <stdio.h>
12 #include <unistd.h>
13 #include <string.h>
14 #include <stdlib.h>
15 #include <errno.h>
17 #include "ftp.h"
18 #include "local.h"
20 static char line2[512];
22 static void dodir(char *path, int full);
24 int DOlpwd()
26 if(getcwd(line2, sizeof(line2)) == (char *)NULL)
27 printf("Could not determine local directory. %s\n", strerror(errno));
28 else
29 printf("Current local directory: %s\n", line2);
31 return(0);
34 int DOlcd()
36 char *path;
37 int s;
39 path = cmdargv[1];
41 if(cmdargc < 2) {
42 if(readline("Path: ", line2, sizeof(line2)) < 0)
43 return(-1);
44 path = line2;
47 if(chdir(path))
48 printf("Could not change local directory. %s\n", strerror(errno));
49 else
50 return(DOlpwd());
52 return(0);
55 int DOlmkdir()
57 char *path;
58 int s;
60 path = cmdargv[1];
62 if(cmdargc < 2) {
63 if(readline("Path: ", line2, sizeof(line2)) < 0)
64 return(-1);
65 path = line2;
68 if(mkdir(path, 0777))
69 printf("Could not make directory %s. %s\n", path, strerror(errno));
70 else
71 printf("Directory created.\n");
73 return(0);
76 int DOlrmdir()
78 char *path;
79 int s;
81 path = cmdargv[1];
83 if(cmdargc < 2) {
84 if(readline("Path: ", line2, sizeof(line2)) < 0)
85 return(-1);
86 path = line2;
89 if(rmdir(path))
90 printf("Could not remove directory %s. %s\n", path, strerror(errno));
91 else
92 printf("Directory removed.\n");
94 return(0);
97 int DOllist(void)
99 dodir(".", 1);
101 return(0);
104 int DOlnlst(void)
106 dodir(".", 0);
108 return(0);
111 int DOlshell(void)
113 (void) system("$SHELL");
115 return(0);
118 static void dodir(path, full)
119 char *path;
120 int full;
122 static char cmd[128];
123 static char name[32];
125 (void) tmpnam(name);
127 if(full)
128 sprintf(cmd, "ls -l %s > %s", path, name);
129 else
130 sprintf(cmd, "ls %s > %s", path, name);
132 (void) system(cmd);
133 sprintf(cmd, "more %s", name);
134 (void) system(cmd);
135 sprintf(cmd, "rm %s", name);
136 (void) system(cmd);