File: mcd.c

package info (click to toggle)
mtools 3.8-1
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 1,116 kB
  • ctags: 1,306
  • sloc: ansic: 11,489; sh: 2,052; makefile: 223; sed: 8
file content (44 lines) | stat: -rw-r--r-- 831 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
 * mcd.c: Change MSDOS directories
 */

#include "sysincludes.h"
#include "msdos.h"
#include "mainloop.h"
#include "mtools.h"

void mcd(int argc, char **argv, int type)
{
	Stream_t *Dir;
	FILE *fp;
	char pathname[MAX_PATH];
	struct MainParam_t mp;

	if (argc > 2) {
		fprintf(stderr, "Mtools version %s, dated %s\n", mversion, mdate);
		fprintf(stderr, "Usage: %s: [-V] msdosdirectory\n", argv[0]);
		exit(1);
	}

	init_mp(&mp);
	if (argc == 1) {
		printf("%s\n", mp.mcwd);
		exit(0);
	}
	mp.pathname = pathname;
	Dir = open_subdir(&mp, argv[1], O_RDONLY, 1, 0);
	if(!Dir){
		fprintf(stderr,"No such directory\n");
		exit(1);
	}

	FREE(&Dir);

	if (!(fp = open_mcwd("w"))){
		fprintf(stderr,"%s: Can't open mcwd file for write\n",argv[0]);
		exit(1);
	}
	fprintf(fp, "%c:%s\n", mp.drivename, pathname);
	fclose(fp);
	exit(0);
}