2 * Copyright 2005-2007, Ingo Weinhold, bonefish@cs.tu-berlin.de.
3 * Distributed under the terms of the MIT License.
6 #include "fs_shell_command_beos.h"
13 #include "fs_shell_command.h"
16 bool gUsesFifos
= false;
20 send_external_command(const char *command
, int *result
)
22 int commandLen
= strlen(command
);
23 if (commandLen
> kMaxCommandLength
) {
24 fprintf(stderr
, "Error: Command line too long.\n");
28 char _message
[sizeof(external_command_message
) + kMaxCommandLength
];
29 external_command_message
* message
= (external_command_message
*)_message
;
30 strcpy(message
->command
, command
);
32 // find the command port
33 port_id commandPort
= find_port(kFSShellCommandPort
);
34 if (commandPort
< 0) {
35 fprintf(stderr
, "Error: Couldn't find fs_shell command port.\n");
39 // create a reply port
40 port_id replyPort
= create_port(1, "fs shell reply port");
42 fprintf(stderr
, "Error: Failed to create a reply port: %s\n",
46 message
->reply_port
= replyPort
;
48 // send the command message
51 error
= write_port(commandPort
, 0, message
,
52 sizeof(external_command_message
) + commandLen
);
53 } while (error
== B_INTERRUPTED
);
56 fprintf(stderr
, "Error: Failed to send command: %s\n", strerror(error
));
61 external_command_reply reply
;
65 bytesRead
= read_port(replyPort
, &code
, &reply
, sizeof(reply
));
66 } while (bytesRead
== B_INTERRUPTED
);
69 fprintf(stderr
, "Error: Failed to read reply from fs_shell: %s\n",
74 *result
= reply
.error
;