File: mkdir.c

package info (click to toggle)
cobex 0.2.12-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 208 kB
  • ctags: 213
  • sloc: ansic: 1,383; makefile: 116; sh: 62; perl: 50
file content (93 lines) | stat: -rw-r--r-- 2,199 bytes parent folder | download | duplicates (2)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
*
* mkdir.c - COBEX - Create a directory on device.
*
* Copyright 2006 Fredrik Srensson
*
* History:
* v0.1 - fsn - 06-07-24 - First version
* v0.2 - fsn - 06-07-29 - Code cleanup, made more robust
*
* Source:
*
*/

#include <stdio.h>
#include <ezV24/ezV24.h>
#include <signal.h>
#include <string.h>

#include "cobex_core.h"
#include "cobex_tools.h"
#include "cobex_serial.h"

void help () {
	printf ("cobex_mkdir v0.1\n\n");
	printf ("Usage: cobex_mkdir <device> <filename>\n\n");
	printf ("All arguments are compulsory and order is important.\nPathname must not end with a slash.\n");
}

// Main routine

int main (int argc, char *argv[]) {
	static char fsBrowser[]={ 0xf9, 0xec, 0x7b, 0xc4, 0x95, 0x3c, 0x11, 0xd2, 0x98, 0x4e, 0x52, 0x54, 0x00, 0xdc, 0x9e, 0x09, 0x00};
	v24_port_t *UsedPort=NULL;	
	int rc=0;

	char aBuffer[513];
	obex_packet aPacket;

	aPacket.max=512;
	aPacket.buffer=aBuffer;
	
	char *name;
	char *path;

	if (argc != 3) {
		printf ("ERR: Wrong argc : %d.\n",argc);
		help();
		return 1;
	}

	// Set up the port

	rc = ctools_commonInit( &UsedPort, &aPacket, argv[1], fsBrowser );
	if (rc != COBEX_OK) { exit (COBEX_ERR); }	

	// Do the specific things

	path = calloc( strlen(argv[2])+1, sizeof(char) );		// Allocate memory
	name = calloc( strlen(argv[2])+1, sizeof(char) );
	
	ctools_buildPath ( argv[2], path, name );	
	
	if (strlen(name) == 0) {
		fputs ("ERR: Path/filename must not end in '/'\n",stderr);
	} else {
		rc=ctools_recursePath( &aPacket, path, UsedPort, OBEX_SETPATH_DONTCREATE );	// Descend to the depest level
	
		if (cobex_response_code(&aPacket) != (OBEX_RESPONSE_OK|OBEX_FINAL_BIT) ) { 
			fprintf (stderr, "ERR: %s \n",
				cobex_respstring(cobex_response_code(&aPacket)) ) ;
			rc=COBEX_ERR;
		} else {
			rc=ctools_setPath( &aPacket, name, UsedPort, 0x00);			// Only if we descended ok.
			if (cobex_response_code(&aPacket) != (OBEX_RESPONSE_OK|OBEX_FINAL_BIT) ) {
				fprintf (stderr, "ERR: %s \n",
					cobex_respstring(cobex_response_code(&aPacket)) ) ;
				rc=COBEX_ERR;
			}
		}
	}

	// Clean up
	
	free (path);						// Deallocate memory
	free (name);
	ctools_disconnect( &aPacket, UsedPort );	
	cobex_closePort(UsedPort);

	return rc;

}