Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid using variadic macro #250

Merged
merged 1 commit into from
Nov 14, 2023
Merged

Conversation

vszakats
Copy link
Member

@vszakats vszakats commented Nov 9, 2023

This makes it possible to compile trurl with old C89 compilers without having to pass -std=gnu99 or similar.

@vszakats vszakats force-pushed the avoid-variadic-macro branch from 1cca265 to 65a2e9a Compare November 9, 2023 21:30
This makes it possible to compile trurl with old C89 compilers without
having to pass `-std=gnu99` or similar.
@jacobmealey
Copy link
Contributor

This looks awesome and is a lot easier to read than the old VERIFY macro, the only nitpick I can think of would be combining errorf_low and warnf_low into a single function that takes the error/warning prefix as a parameter. granted those functions are only used in this part of the code so it's not a big deal.

@vszakats
Copy link
Member Author

Thanks! Is this something you have in mind?:

diff --git a/trurl.c b/trurl.c
index f1bb17e..516f1b8 100644
--- a/trurl.c
+++ b/trurl.c
@@ -137,11 +137,17 @@ static char *curl_url_strerror(CURLUcode error)
 }
 #endif
 
-static void warnf_low(char *fmt, va_list ap)
+static void message_low(const char *prefix, const char *suffix,
+                        const char *fmt, va_list ap)
 {
-  fputs(WARN_PREFIX, stderr);
+  fputs(prefix, stderr);
   vfprintf(stderr, fmt, ap);
-  fputs("\n", stderr);
+  fputs(suffix, stderr);
+}
+
+static void warnf_low(char *fmt, va_list ap)
+{
+  message_low(WARN_PREFIX, "\n", fmt, ap);
 }
 
 static void warnf(char *fmt, ...)
@@ -295,9 +301,8 @@ static void trurl_cleanup_options(struct option *o)
 
 static void errorf_low(char *fmt, va_list ap)
 {
-  fputs(ERROR_PREFIX, stderr);
-  vfprintf(stderr, fmt, ap);
-  fputs("\n" ERROR_PREFIX "Try " PROGNAME " -h for help\n", stderr);
+  message_low(ERROR_PREFIX, "\n"
+              ERROR_PREFIX "Try " PROGNAME " -h for help\n", fmt, ap);
 }
 
 static void errorf(struct option *o, int exit_code, char *fmt, ...)

@vszakats
Copy link
Member Author

vszakats commented Nov 14, 2023

Merging this as-is because #251 is based on it. Will revisit this in new PR. → #253

@vszakats vszakats merged commit 17b61ae into curl:master Nov 14, 2023
9 checks passed
@vszakats vszakats deleted the avoid-variadic-macro branch November 14, 2023 09:14
vszakats added a commit to vszakats/trurl that referenced this pull request Nov 14, 2023
Ref: curl#250 (comment)
Suggested-by: Jacob Mealey
Closes #xxx
vszakats added a commit that referenced this pull request Nov 14, 2023
Ref: #250 (comment)
Suggested-by: Jacob Mealey
Closes #xxx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants