i3-msg: use smalloc, sstrdup from libi3

This commit is contained in:
Michael Stapelberg 2011-10-02 18:11:01 +01:00
parent 501dc36b98
commit ff86852453

View File

@ -97,9 +97,7 @@ static void ipc_recv_message(int sockfd, uint32_t message_type,
errx(EXIT_FAILURE, "unexpected reply type (got %d, expected %d)", *((uint32_t*)walk), message_type); errx(EXIT_FAILURE, "unexpected reply type (got %d, expected %d)", *((uint32_t*)walk), message_type);
walk += sizeof(uint32_t); walk += sizeof(uint32_t);
*reply = malloc(*reply_length); *reply = smalloc(*reply_length);
if ((*reply) == NULL)
err(EXIT_FAILURE, "malloc() failed");
to_read = *reply_length; to_read = *reply_length;
read_bytes = 0; read_bytes = 0;
@ -135,7 +133,7 @@ int main(int argc, char *argv[]) {
if (o == 's') { if (o == 's') {
if (socket_path != NULL) if (socket_path != NULL)
free(socket_path); free(socket_path);
socket_path = strdup(optarg); socket_path = sstrdup(optarg);
} else if (o == 't') { } else if (o == 't') {
if (strcasecmp(optarg, "command") == 0) if (strcasecmp(optarg, "command") == 0)
message_type = I3_IPC_MESSAGE_TYPE_COMMAND; message_type = I3_IPC_MESSAGE_TYPE_COMMAND;
@ -169,15 +167,14 @@ int main(int argc, char *argv[]) {
/* Fall back to the default socket path */ /* Fall back to the default socket path */
if (socket_path == NULL) if (socket_path == NULL)
socket_path = strdup("/tmp/i3-ipc.sock"); socket_path = sstrdup("/tmp/i3-ipc.sock");
/* Use all arguments, separated by whitespace, as payload. /* Use all arguments, separated by whitespace, as payload.
* This way, you dont have to do i3-msg 'mark foo', you can use * This way, you dont have to do i3-msg 'mark foo', you can use
* i3-msg mark foo */ * i3-msg mark foo */
while (optind < argc) { while (optind < argc) {
if (!payload) { if (!payload) {
if (!(payload = strdup(argv[optind]))) payload = sstrdup(argv[optind]);
err(EXIT_FAILURE, "strdup(argv[optind])");
} else { } else {
char *both; char *both;
if (asprintf(&both, "%s %s", payload, argv[optind]) == -1) if (asprintf(&both, "%s %s", payload, argv[optind]) == -1)