[mw-devel] [Git][arthur/mw][master] Fix building with clang

Andrew Price welshbyte at sucs.org
Thu Jul 27 01:00:15 BST 2017


Andrew Price pushed to branch master at Justin Mitchell / mw


Commits:
e00db6ac by Andrew Price at 2017-07-27T00:47:55+01:00
Fix building with clang

- - - - -


3 changed files:

- src/client/main.c
- src/str_util.h
- src/utils/mwnci.c


Changes:

=====================================
src/client/main.c
=====================================
--- a/src/client/main.c
+++ b/src/client/main.c
@@ -631,17 +631,15 @@ int main(int argc, char **argv)
 	}
 
 	{
-		struct sockaddr sa;
+		struct sockaddr_in sa;
 		socklen_t ss;
 
 		ss=sizeof(sa);
 		/* can we log a hostname ? */
-		if (getpeername(fileno(stdin), &sa , &ss))
+		if (getpeername(fileno(stdin), (struct sockaddr *)&sa, &ss))
 			mwlog("LOGIN");
 		else
-		{
-			mwlog("LOGIN from %s", inet_ntoa(((struct sockaddr_in *)&sa)->sin_addr) );
-		}
+			mwlog("LOGIN from %s", inet_ntoa(sa.sin_addr));
 	}
 
 	time_t when = user->record.lastlogout;


=====================================
src/str_util.h
=====================================
--- a/src/str_util.h
+++ b/src/str_util.h
@@ -1,11 +1,18 @@
 #ifndef STR_UTIL_H
 #define STR_UTIL_H
 
-/* str_util.c */
+#ifdef __clang__
+#define mw_printf_func(stridx, vastart) __attribute__((format(printf,stridx,vastart)))
+#elif defined __GNUC__
+#define mw_printf_func(stridx, vastart) __attribute__((format(gnu_printf,stridx,vastart)))
+#else
+#define mw_printf_func(stridx, vastart)
+#endif
+
 int stringcmp(const char *a, const char *b, int n);
 void strip_str(char *string);
 int get_rand(int min, int max);
-void string_add(char **str, const char *fmt, ...)  __attribute__((format(gnu_printf,2,3)));
+void string_add(char **str, const char *fmt, ...) mw_printf_func(2, 3);
 int allspace(char *in);
 void strlower(char *szString);
 void escprintf(const char *szFormat, ...);


=====================================
src/utils/mwnci.c
=====================================
--- a/src/utils/mwnci.c
+++ b/src/utils/mwnci.c
@@ -171,32 +171,31 @@ static int is_unique_user_name(int fd, const char *name, int *err)
 	return 1;
 }
 
-static int check_template(const char *optarg, size_t maxlen)
+static int check_template(const char *t, size_t maxlen)
 {
 	const char *i;
 	size_t size;
 	int count;
 
-	size = strlen(optarg);
+	size = strlen(t);
 	if (size == 0) {
 		fprintf(stderr, "Empty template\n");
 		return 1;
 	}
 	if (size > maxlen) {
-		fprintf(stderr, "Template is too long: '%s'\n", optarg);
+		fprintf(stderr, "Template is too long: '%s'\n", t);
 		return 1;
 	}
-	for (count = 0, i = optarg; *i != '\0'; i++) {
+	for (count = 0, i = t; *i != '\0'; i++) {
 		if (*i == '%') {
 			count++;
 		} else if (!isprint(*i)) {
-			fprintf(stderr, "Template '%s' contains non-printable characters\n",
-			                 optarg);
+			fprintf(stderr, "Template '%s' contains non-printable characters\n", t);
 			return 1;
 		}
 	}
 	if (count < 3) {
-		fprintf(stderr, "Template '%s' contains too few '%%' characters.\n", optarg);
+		fprintf(stderr, "Template '%s' contains too few '%%' characters.\n", t);
 		return 1;
 	}
 	return 0;



View it on GitLab: https://projects.sucs.org/arthur/mw/commit/e00db6accd676753c65fe280d0be996c41d3e981

---
View it on GitLab: https://projects.sucs.org/arthur/mw/commit/e00db6accd676753c65fe280d0be996c41d3e981
You're receiving this email because of your account on projects.sucs.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sucs.org/pipermail/mw-devel/attachments/20170727/a238cb0a/attachment-0001.html>


More information about the mw-devel mailing list