diff mbox series

Portability of dash to legacy systems, such as AT&T Unix PC : 08-vsnprintf

Message ID 06330e5c-4d1d-48c2-95fe-ebba32bd46e6@knaff.lu (mailing list archive)
State Under Review
Delegated to: Herbert Xu
Headers show
Series Portability of dash to legacy systems, such as AT&T Unix PC : 08-vsnprintf | expand

Commit Message

Alain Knaff Nov. 17, 2024, 9:45 a.m. UTC
Hi,

The 8th patch supplies a replacement "defintion" for vsnprintf.

As vsnprintf is rather complex to re-implement fully, a stripped down
version which does not verify available size is supplied.

Most calls to vsnprintf have predictable size needs, so this is
ok. Except one, in showvars, for which an alternative method is
supplied that doesn't rely on vsnprintf for its variable size part.

Regards,

Alain
diff mbox series

Patch

diff -X ../exclude.txt -urN dash-0.5.12+07-sys-functions/configure.ac dash-0.5.12+08-vsnprintf/configure.ac
--- dash-0.5.12+07-sys-functions/configure.ac	2024-11-10 17:29:12.073235300 +0000
+++ dash-0.5.12+08-vsnprintf/configure.ac	2024-11-10 17:29:04.521055631 +0000
@@ -94,7 +94,7 @@ 
 	       sigsetmask stpcpy strchrnul strsignal strtod strtoimax \
 	       strtoumax sysconf \
 	       vfork lstat dup2 getgroups \
-	       strstr stpncpy strcasecmp strerror strdup strtoul \
+	       strstr stpncpy strcasecmp strerror strdup strtoul vsnprintf \
 	       readdir)
 
 dnl Checks for prototypes
diff -X ../exclude.txt -urN dash-0.5.12+07-sys-functions/src/system.c dash-0.5.12+08-vsnprintf/src/system.c
--- dash-0.5.12+07-sys-functions/src/system.c	2024-11-10 16:54:50.528225292 +0000
+++ dash-0.5.12+08-vsnprintf/src/system.c	2024-11-10 16:54:50.536225482 +0000
@@ -313,6 +313,22 @@ 
 }
 #endif
 
+#ifndef HAVE_VSNPRINTF
+int vsnprintf(char *str, size_t size, const char *format, va_list ap)
+{
+	char buffer[4096];
+	int ret;
+	int n;
+	ret = vsprintf(buffer, format, ap);
+	if(ret < 0 || size == 0)
+		return ret;
+	n = (ret >= size) ? size - 1 : ret;
+	strncpy(str, buffer, n);
+	str[n]='\0';
+	return ret;
+}
+#endif
+
 #ifndef HAVE_MEMMOVE
 /* memmove.c -- copy memory.
    This snippet is in the public domain.  */
diff -X ../exclude.txt -urN dash-0.5.12+07-sys-functions/src/var.c dash-0.5.12+08-vsnprintf/src/var.c
--- dash-0.5.12+07-sys-functions/src/var.c	2024-10-20 08:37:55.818683409 +0000
+++ dash-0.5.12+08-vsnprintf/src/var.c	2024-10-21 10:44:55.909560254 +0000
@@ -392,7 +392,13 @@ 
 		if (*p)
 			q = single_quote(++p);
 
+#ifdef HAVE_VSNPRINTF
 		out1fmt("%s%s%.*s%s\n", prefix, sep, (int)(p - *ep), *ep, q);
+#else
+		out1fmt("%s%s%.*s", prefix, sep, (int)(p - *ep), *ep);
+		outstr(q, out1);
+		outcslow('\n', out1);
+#endif
 	}
 
 	return 0;