Bugfix: don't try to read/write/append to file if it was not possible to open it. Bugfix: CFS file descriptors that are 0 are OK.
This commit is contained in:
parent
7e4bab3cc8
commit
adbf6c47ab
|
@ -28,7 +28,7 @@
|
|||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* $Id: shell-file.c,v 1.3 2008/05/24 08:31:56 oliverschmidt Exp $
|
||||
* $Id: shell-file.c,v 1.4 2008/07/02 14:06:46 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -75,7 +75,7 @@ PROCESS_THREAD(shell_ls_process, ev, data)
|
|||
char buf[32];
|
||||
PROCESS_BEGIN();
|
||||
|
||||
if(cfs_opendir(&dir, ".") != 0) {
|
||||
if(cfs_opendir(&dir, "/") != 0) {
|
||||
shell_output_str(&ls_command, "Cannot open directory", "");
|
||||
} else {
|
||||
totsize = 0;
|
||||
|
@ -101,11 +101,10 @@ PROCESS_THREAD(shell_append_process, ev, data)
|
|||
|
||||
fd = cfs_open(data, CFS_WRITE | CFS_APPEND);
|
||||
|
||||
if(fd <= 0) {
|
||||
if(fd < 0) {
|
||||
shell_output_str(&append_command,
|
||||
"Could not open file for writing: ", data);
|
||||
}
|
||||
|
||||
"append: could not open file for writing: ", data);
|
||||
} else {
|
||||
while(1) {
|
||||
struct shell_input *input;
|
||||
PROCESS_WAIT_EVENT_UNTIL(ev == shell_event_input);
|
||||
|
@ -123,6 +122,7 @@ PROCESS_THREAD(shell_append_process, ev, data)
|
|||
input->data1, input->len1,
|
||||
input->data2, input->len2);
|
||||
}
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
|
@ -137,11 +137,10 @@ PROCESS_THREAD(shell_write_process, ev, data)
|
|||
|
||||
fd = cfs_open(data, CFS_WRITE);
|
||||
|
||||
if(fd <= 0) {
|
||||
if(fd < 0) {
|
||||
shell_output_str(&write_command,
|
||||
"Could not open file for writing: ", data);
|
||||
}
|
||||
|
||||
"write: could not open file for writing: ", data);
|
||||
} else {
|
||||
while(1) {
|
||||
struct shell_input *input;
|
||||
PROCESS_WAIT_EVENT_UNTIL(ev == shell_event_input);
|
||||
|
@ -159,6 +158,7 @@ PROCESS_THREAD(shell_write_process, ev, data)
|
|||
input->data1, input->len1,
|
||||
input->data2, input->len2);
|
||||
}
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
|
@ -171,11 +171,10 @@ PROCESS_THREAD(shell_read_process, ev, data)
|
|||
|
||||
fd = cfs_open(data, CFS_READ);
|
||||
|
||||
if(fd <= 0) {
|
||||
shell_output_str(&write_command,
|
||||
"Could not open file for reading: ", data);
|
||||
}
|
||||
|
||||
if(fd < 0) {
|
||||
shell_output_str(&read_command,
|
||||
"read: could not open file for reading: ", data);
|
||||
} else {
|
||||
|
||||
while(1) {
|
||||
char buf[40];
|
||||
|
@ -203,6 +202,7 @@ PROCESS_THREAD(shell_read_process, ev, data)
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue