source: trunk/minix/commands/ftp/local.c@ 10

Last change on this file since 10 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 1.9 KB
Line 
1/* local.c
2 *
3 * This file is part of ftp.
4 *
5 *
6 * 01/25/96 Initial Release Michael Temari, <temari@ix.netcom.com>
7 */
8
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>
16
17#include "ftp.h"
18#include "local.h"
19
20static char line2[512];
21
22_PROTOTYPE(static void dodir, (char *path, int full));
23
24int DOlpwd()
25{
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);
30
31 return(0);
32}
33
34int DOlcd()
35{
36char *path;
37int s;
38
39 path = cmdargv[1];
40
41 if(cmdargc < 2) {
42 readline("Path: ", line2, sizeof(line2));
43 path = line2;
44 }
45
46 if(chdir(path))
47 printf("Could not change local directory. %s\n", strerror(errno));
48 else
49 DOlpwd();
50
51 return(0);
52}
53
54int DOlmkdir()
55{
56char *path;
57int s;
58
59 path = cmdargv[1];
60
61 if(cmdargc < 2) {
62 readline("Directory: ", line2, sizeof(line2));
63 path = line2;
64 }
65
66 if(mkdir(path, 0777))
67 printf("Could not make directory %s. %s\n", path, strerror(errno));
68 else
69 printf("Directory created.\n");
70
71 return(0);
72}
73
74int DOlrmdir()
75{
76char *path;
77int s;
78
79 path = cmdargv[1];
80
81 if(cmdargc < 2) {
82 readline("Directory: ", line2, sizeof(line2));
83 path = line2;
84 }
85
86 if(rmdir(path))
87 printf("Could not remove directory %s. %s\n", path, strerror(errno));
88 else
89 printf("Directory removed.\n");
90
91 return(0);
92}
93
94int DOllist(void)
95{
96 dodir(".", 1);
97}
98
99int DOlnlst(void)
100{
101 dodir(".", 0);
102}
103
104int DOlshell(void)
105{
106 system("$SHELL");
107}
108
109static void dodir(path, full)
110char *path;
111int full;
112{
113char cmd[128];
114static char name[32];
115
116 tmpnam(name);
117
118 if(full)
119 sprintf(cmd, "ls -l %s > %s", path, name);
120 else
121 sprintf(cmd, "ls %s > %s", path, name);
122
123 system(cmd);
124 sprintf(cmd, "more %s", name);
125 system(cmd);
126 sprintf(cmd, "rm %s", name);
127 system(cmd);
128}
Note: See TracBrowser for help on using the repository browser.