aboutsummaryrefslogtreecommitdiff
path: root/sway
diff options
context:
space:
mode:
Diffstat (limited to 'sway')
-rw-r--r--sway/commands.c4
-rw-r--r--sway/container.c2
-rw-r--r--sway/log.c4
-rw-r--r--sway/main.c2
-rw-r--r--sway/stringop.c29
-rw-r--r--sway/workspace.c1
6 files changed, 30 insertions, 12 deletions
diff --git a/sway/commands.c b/sway/commands.c
index f2ee0184..80770e87 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -5,8 +5,10 @@
#include <stdlib.h>
#include <errno.h>
#include <string.h>
+#include <strings.h>
#include <unistd.h>
#include <ctype.h>
+#include <sys/types.h>
#include "stringop.h"
#include "layout.h"
#include "focus.h"
@@ -193,7 +195,7 @@ static enum cmd_status cmd_exec_always(int argc, char **argv) {
sway_log(L_DEBUG, "Executing %s", cmd);
pid_t pid;
- if ((pid = vfork()) == 0) {
+ if ((pid = fork()) == 0) {
execv("/bin/sh", args);
_exit(-1);
} else if (pid < 0) {
diff --git a/sway/container.c b/sway/container.c
index d6bcc4c2..4c523827 100644
--- a/sway/container.c
+++ b/sway/container.c
@@ -1,7 +1,9 @@
#include <stdlib.h>
#include <stdbool.h>
#include <strings.h>
+#include <string.h>
#include "config.h"
+#include "stringop.h"
#include "container.h"
#include "workspace.h"
#include "focus.h"
diff --git a/sway/log.c b/sway/log.c
index 3859fd92..a206d971 100644
--- a/sway/log.c
+++ b/sway/log.c
@@ -80,9 +80,7 @@ void sway_log_errno(log_importance_t verbosity, char* format, ...) {
va_end(args);
fprintf(stderr, ": ");
- char error[256];
- strerror_r(errno, error, sizeof(error));
- fprintf(stderr, "%s", error);
+ fprintf(stderr, "%s", strerror(errno));
if (colored && isatty(STDERR_FILENO)) {
fprintf(stderr, "\x1B[0m");
diff --git a/sway/main.c b/sway/main.c
index e03588ea..66921184 100644
--- a/sway/main.c
+++ b/sway/main.c
@@ -3,9 +3,11 @@
#include <stdbool.h>
#include <wlc/wlc.h>
#include <sys/wait.h>
+#include <sys/types.h>
#include <signal.h>
#include <getopt.h>
#include "layout.h"
+#include "stringop.h"
#include "config.h"
#include "log.h"
#include "readline.h"
diff --git a/sway/stringop.c b/sway/stringop.c
index 90f963d6..31a036c3 100644
--- a/sway/stringop.c
+++ b/sway/stringop.c
@@ -1,5 +1,6 @@
#include <stdlib.h>
#include <stdio.h>
+#include <string.h>
#include <strings.h>
#include <ctype.h>
#include "stringop.h"
@@ -7,7 +8,7 @@
#include "string.h"
#include "list.h"
-const char *whitespace = " \f\n\r\t\v";
+const char whitespace[] = " \f\n\r\t\v";
/* Note: This returns 8 characters for trimmed_start per tab character. */
char *strip_whitespace(char *_str) {
@@ -313,13 +314,16 @@ char *join_list(list_t *list, char *separator) {
}
char *cmdsep(char **stringp, const char *delim) {
- char *head = strsep(stringp, delim);
- // But skip over trailing delims. '3 tokens here' -> '3' 'tokens here'
- if (*stringp) {
- *stringp += strspn(*stringp, delim);
- // If skiping over delims brings us to the end of string, set to NULL
- if (!**stringp) *stringp = NULL;
- }
+ // skip over leading delims
+ char *head = *stringp + strspn(*stringp, delim);
+ // Find end token
+ char *tail = *stringp += strcspn(*stringp, delim);
+ // Set stringp to begining of next token
+ *stringp += strspn(*stringp, delim);
+ // Set stringp to null if last token
+ if (!**stringp) *stringp = NULL;
+ // Nullify end of first token
+ *tail = 0;
return head;
}
@@ -358,3 +362,12 @@ char *argsep(char **stringp, const char *delim) {
found:
return start;
}
+
+char *strdup(const char *str) {
+ char *dup = malloc(strlen(str) + 1);
+ if (dup) {
+ strcpy(dup, str);
+ }
+ return dup;
+}
+
diff --git a/sway/workspace.c b/sway/workspace.c
index 658f79bc..c169c1cb 100644
--- a/sway/workspace.c
+++ b/sway/workspace.c
@@ -2,6 +2,7 @@
#include <stdbool.h>
#include <wlc/wlc.h>
#include <string.h>
+#include <strings.h>
#include "workspace.h"
#include "layout.h"
#include "list.h"