ev3duder  0.3.0
EV3 Downloader/Uploader
rm.c
Go to the documentation of this file.
1 
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include <errno.h>
12 
13 #include "ev3_io.h"
14 
15 #include "defs.h"
16 #include "packets.h"
17 #include "error.h"
18 #include "funcs.h"
19 
27 int rm(const char *path)
28 {
29  int res;
30  size_t path_sz = strlen(path) + 1;
31  DELETE_FILE *rm_cmd = packet_alloc(DELETE_FILE, path_sz);
32  memcpy(rm_cmd->path, path, path_sz);
33 
34  res = ev3_write(handle, (u8 *)rm_cmd, rm_cmd->packetLen + PREFIX_SIZE);
35  if (res < 0)
36  {
37  errmsg = "Unable to write DELETE_FILE.";
38  return ERR_COMM;
39  }
40  fputs("Checking reply: \n", stderr);
41  CREATE_DIR_REPLY rmrep;
42 
43  res = ev3_read_timeout(handle, (u8 *)&rmrep, sizeof rmrep, TIMEOUT);
44  if (res <= 0)
45  {
46  errmsg = "Unable to read DELETE_FILE";
47  return ERR_COMM;
48  }
49 
50  if (rmrep.type == VM_ERROR)
51  {
52  errno = rmrep.ret;
53  fputs("Operation failed.\nlast_reply=", stderr);
54  print_bytes(&rmrep, rmrep.packetLen);
55 
56 
57  errmsg = "`DELETE_FILE` was denied.";
58  return ERR_VM;
59  }
60  errmsg = "`DELETE_FILE` was successful.";
61  return ERR_UNK;
62 
63 }
64 
EXTERN void * handle
Definition: ev3_io.h:17
delete file
Definition: packets.h:241
Definition: error.h:20
Error enumerations and decriptions.
#define print_bytes(buf, len)
Definition: defs.h:34
#define packet_alloc(type, extra)
Definition: packets.h:328
EXTERN int(* ev3_read_timeout)(void *, u8 *, size_t, int milliseconds)
Definition: ev3_io.h:14
EV3_COMMAND_FIELDS u8 path[]
Definition: packets.h:245
int rm(const char *path)
removes files and directories at path. path is always relative to /home/root/lms2012/prjs/sys/ ...
Definition: rm.c:27
#define TIMEOUT
Definition: defs.h:46
packed structs for the packets.
base packet for SYSTEM REPLIES
Definition: packets.h:72
Definition: error.h:20
uint8_t u8
Definition: defs.h:9
Definition: error.h:20
Definition: error.h:22
EXTERN const char * errmsg
global variable for last error message
Definition: error.h:25
contains declarations for ev3 commands
EXTERN int(* ev3_write)(void *, const u8 *, size_t)
Definition: ev3_io.h:13
#define PREFIX_SIZE
Definition: packets.h:54