Module Name:    othersrc
Committed By:   lukem
Date:           Sat Sep 23 02:56:09 UTC 2023

Modified Files:
        othersrc/libexec/tnftpd: tnftpd.h
        othersrc/libexec/tnftpd/libnetbsd: sl_init.c

Log Message:
sync lib/libc/gen/stringlist.c 1.13

Functional changes since upstream 1.8:
- 1.11: Add sl_delete. Change sl_find() to use const char * argument.
- 1.10: Don't update the size of allocated storage until realloc successes.

Note: not updating to upstream 1.15 because that was a refactor to
use reallocarr() which I'm deferring for now.

Comment out other unneeded upstream code to minimise differences.

Update sl_find() and sl_delete() declarations in tnftpd.h
per include/stringlist.h rev 1.6.


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 othersrc/libexec/tnftpd/tnftpd.h
cvs rdiff -u -r1.3 -r1.4 othersrc/libexec/tnftpd/libnetbsd/sl_init.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: othersrc/libexec/tnftpd/tnftpd.h
diff -u othersrc/libexec/tnftpd/tnftpd.h:1.37 othersrc/libexec/tnftpd/tnftpd.h:1.38
--- othersrc/libexec/tnftpd/tnftpd.h:1.37	Tue Jan 29 13:06:14 2019
+++ othersrc/libexec/tnftpd/tnftpd.h	Sat Sep 23 02:56:08 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: tnftpd.h,v 1.37 2019/01/29 13:06:14 lukem Exp $ */
+/* $NetBSD: tnftpd.h,v 1.38 2023/09/23 02:56:08 lukem Exp $ */
 
 #define	FTPD_VERSION	PACKAGE_STRING
 
@@ -224,10 +224,11 @@ typedef struct _stringlist {
 	size_t	  sl_cur;
 } StringList;
 
-StringList *sl_init(void);
-int	 sl_add(StringList *, char *);
-void	 sl_free(StringList *, int);
-char	*sl_find(StringList *, char *);
+StringList 	*sl_init(void);
+int		 sl_add(StringList *, char *);
+void		 sl_free(StringList *, int);
+char 		*sl_find(StringList *, const char *);
+int		 sl_delete(StringList *, const char *, int);
 
 #if !defined(NO_INTERNAL_LS)
 

Index: othersrc/libexec/tnftpd/libnetbsd/sl_init.c
diff -u othersrc/libexec/tnftpd/libnetbsd/sl_init.c:1.3 othersrc/libexec/tnftpd/libnetbsd/sl_init.c:1.4
--- othersrc/libexec/tnftpd/libnetbsd/sl_init.c:1.3	Sun Sep 21 16:35:25 2008
+++ othersrc/libexec/tnftpd/libnetbsd/sl_init.c	Sat Sep 23 02:56:08 2023
@@ -1,5 +1,7 @@
-/* $NetBSD: sl_init.c,v 1.3 2008/09/21 16:35:25 lukem Exp $ */
-/* from	NetBSD: stringlist.c,v 1.8 1999/11/28 03:44:09 lukem Exp */
+/* $NetBSD: sl_init.c,v 1.4 2023/09/23 02:56:08 lukem Exp $ */
+
+/* from:	NetBSD: stringlist.c,v 1.13 2008/04/28 20:22:59 martin Exp */
+/* upstream:	lib/libc/gen/stringlist.c */
 
 /*-
  * Copyright (c) 1994, 1999 The NetBSD Foundation, Inc.
@@ -32,6 +34,30 @@
 
 #include "tnftpd.h"
 
+#if 0
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: sl_init.c,v 1.4 2023/09/23 02:56:08 lukem Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#include "namespace.h"
+
+#include <assert.h>
+#include <err.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stringlist.h>
+
+#ifdef __weak_alias
+__weak_alias(sl_add,_sl_add)
+__weak_alias(sl_find,_sl_find)
+__weak_alias(sl_free,_sl_free)
+__weak_alias(sl_init,_sl_init)
+__weak_alias(sl_delete,_sl_delete)
+#endif
+#endif
+
 #define _SL_CHUNKSIZE	20
 
 /*
@@ -44,7 +70,7 @@ sl_init(void)
 
 	sl = malloc(sizeof(StringList));
 	if (sl == NULL)
-		return (NULL);
+		return NULL;
 
 	sl->sl_cur = 0;
 	sl->sl_max = _SL_CHUNKSIZE;
@@ -53,7 +79,7 @@ sl_init(void)
 		free(sl);
 		sl = NULL;
 	}
-	return (sl);
+	return sl;
 }
 
 
@@ -63,17 +89,21 @@ sl_init(void)
 int
 sl_add(StringList *sl, char *name)
 {
+
+	_DIAGASSERT(sl != NULL);
+
 	if (sl->sl_cur == sl->sl_max - 1) {
 		char	**new;
 
-		sl->sl_max += _SL_CHUNKSIZE;
-		new = (char **)realloc(sl->sl_str, sl->sl_max * sizeof(char *));
+		new = realloc(sl->sl_str,
+		    (sl->sl_max + _SL_CHUNKSIZE) * sizeof(char *));
 		if (new == NULL)
-			return (-1);
+			return -1;
+		sl->sl_max += _SL_CHUNKSIZE;
 		sl->sl_str = new;
 	}
 	sl->sl_str[sl->sl_cur++] = name;
-	return (0);
+	return 0;
 }
 
 
@@ -101,13 +131,33 @@ sl_free(StringList *sl, int all)
  * sl_find(): Find a name in the string list
  */
 char *
-sl_find(StringList *sl, char *name)
+sl_find(StringList *sl, const char *name)
 {
 	size_t i;
 
+	_DIAGASSERT(sl != NULL);
+
 	for (i = 0; i < sl->sl_cur; i++)
 		if (strcmp(sl->sl_str[i], name) == 0)
 			return sl->sl_str[i];
 
-	return (NULL);
+	return NULL;
 }
+
+int
+sl_delete(StringList *sl, const char *name, int all)
+{
+	size_t i, j;
+
+	for (i = 0; i < sl->sl_cur; i++)
+		if (strcmp(sl->sl_str[i], name) == 0) {
+			if (all)
+				free(sl->sl_str[i]);
+			for (j = i + 1; j < sl->sl_cur; j++)
+				sl->sl_str[j - 1] = sl->sl_str[j];
+			sl->sl_str[--sl->sl_cur] = NULL;
+			return 0;
+		}
+	return -1;
+}
+

Reply via email to