about summary refs log tree commit diff stats
path: root/src/command
diff options
context:
space:
mode:
Diffstat (limited to 'src/command')
-rw-r--r--src/command/cmd_ac.c20
-rw-r--r--src/command/cmd_defs.c16
-rw-r--r--src/command/cmd_funcs.c8
3 files changed, 22 insertions, 22 deletions
diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c
index cd684f19..f74ca847 100644
--- a/src/command/cmd_ac.c
+++ b/src/command/cmd_ac.c
@@ -36,8 +36,6 @@
 
 #include "config.h"
 
-#define _GNU_SOURCE 1
-
 #include <stdlib.h>
 #include <string.h>
 #include <assert.h>
@@ -1558,13 +1556,15 @@ cmd_ac_complete_filepath(const char* const input, char* const startstr, gboolean
 
     // expand ~ to $HOME
     if (inpcp[0] == '~' && inpcp[1] == '/') {
-        if (asprintf(&tmp, "%s/%sfoo", getenv("HOME"), inpcp + 2) == -1) {
+        tmp = g_strdup_printf("%s/%sfoo", getenv("HOME"), inpcp + 2);
+        if (!tmp) {
             free(inpcp);
             return NULL;
         }
         output_off = strlen(getenv("HOME")) + 1;
     } else {
-        if (asprintf(&tmp, "%sfoo", inpcp) == -1) {
+        tmp = g_strdup_printf("%sfoo", inpcp);
+        if (!tmp) {
             free(inpcp);
             return NULL;
         }
@@ -1596,25 +1596,29 @@ cmd_ac_complete_filepath(const char* const input, char* const startstr, gboolean
 
             char* acstring;
             if (output_off) {
-                if (asprintf(&tmp, "%s/%s", directory, dir->d_name) == -1) {
+                tmp = g_strdup_printf("%s/%s", directory, dir->d_name);
+                if(!tmp) {
                     free(directory);
                     free(foofile);
                     return NULL;
                 }
-                if (asprintf(&acstring, "~/%s", tmp + output_off) == -1) {
+                acstring = g_strdup_printf("~/%s", tmp + output_off);
+                if (!acstring) {
                     free(directory);
                     free(foofile);
                     return NULL;
                 }
                 free(tmp);
             } else if (strcmp(directory, "/") == 0) {
-                if (asprintf(&acstring, "/%s", dir->d_name) == -1) {
+                acstring = g_strdup_printf("/%s", dir->d_name);
+                if (!acstring) {
                     free(directory);
                     free(foofile);
                     return NULL;
                 }
             } else {
-                if (asprintf(&acstring, "%s/%s", directory, dir->d_name) == -1) {
+                acstring = g_strdup_printf("%s/%s", directory, dir->d_name);
+                if (!acstring) {
                     free(directory);
                     free(foofile);
                     return NULL;
diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c
index c756c169..730169ba 100644
--- a/src/command/cmd_defs.c
+++ b/src/command/cmd_defs.c
@@ -34,8 +34,6 @@
  *
  */
 
-#define _GNU_SOURCE 1
-
 #include "config.h"
 
 #include <assert.h>
@@ -2894,11 +2892,11 @@ command_mangen(void)
 
     mkdir_recursive("docs");
 
-    char* header = NULL;
     GDateTime* now = g_date_time_new_now_local();
     gchar* date = g_date_time_format(now, "%F");
-    if (asprintf(&header, ".TH man 1 \"%s\" \"" PACKAGE_VERSION "\" \"Profanity XMPP client\"\n", date) == -1) {
-        // TODO: error
+    gchar *header = g_strdup_printf(".TH man 1 \"%s\" \"" PACKAGE_VERSION "\" \"Profanity XMPP client\"\n", date);
+    if (!header) {
+        log_error("command_mangen(): could not allocate memory");
         return;
     }
     g_date_time_unref(now);
@@ -2908,9 +2906,9 @@ command_mangen(void)
     while (curr) {
         Command* pcmd = curr->data;
 
-        char* filename = NULL;
-        if (asprintf(&filename, "docs/profanity-%s.1", &pcmd->cmd[1]) == -1) {
-            // TODO: error
+        gchar* filename = g_strdup_printf("docs/profanity-%s.1", &pcmd->cmd[1]);
+        if (!filename) {
+            log_error("command_mangen(): could not allocate memory");
             return;
         }
         FILE* manpage = fopen(filename, "w");
@@ -2955,6 +2953,6 @@ command_mangen(void)
 
     printf("\nProcessed %d commands.\n\n", g_list_length(cmds));
 
-    free(header);
+    g_free(header);
     g_list_free(cmds);
 }
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c
index 115db27f..8f463a6c 100644
--- a/src/command/cmd_funcs.c
+++ b/src/command/cmd_funcs.c
@@ -35,8 +35,6 @@
  *
  */
 
-#define _GNU_SOURCE 1
-
 #include "config.h"
 
 #include <string.h>
@@ -141,10 +139,10 @@ cmd_process_input(ProfWin* window, char* inp)
         char* question_mark = strchr(command, '?');
         if (question_mark) {
             *question_mark = '\0';
-            char* fakeinp;
-            if (asprintf(&fakeinp, "/help %s", command + 1)) {
+            gchar* fakeinp = g_strdup_printf("/help %s", command + 1);
+            if (fakeinp) {
                 result = _cmd_execute(window, "/help", fakeinp);
-                free(fakeinp);
+                g_free(fakeinp);
             }
         } else {
             result = _cmd_execute(window, command, inp);