summaryrefslogtreecommitdiff
path: root/lib/libfetch/common.c
diff options
context:
space:
mode:
authorDag-Erling Smørgrav <des@FreeBSD.org>1998-12-21 19:41:50 +0000
committerDag-Erling Smørgrav <des@FreeBSD.org>1998-12-21 19:41:50 +0000
commitce71b7364c992f636a7a20bc68d99e564269fa0a (patch)
treedaeceef714ad7444829535c209d95d8dc547b1e9 /lib/libfetch/common.c
parentbfc338e0bbdd9eb35d19f0959ef02313ca5453c2 (diff)
downloadsrc-test2-ce71b7364c992f636a7a20bc68d99e564269fa0a.tar.gz
src-test2-ce71b7364c992f636a7a20bc68d99e564269fa0a.zip
Notes
Diffstat (limited to 'lib/libfetch/common.c')
-rw-r--r--lib/libfetch/common.c44
1 files changed, 43 insertions, 1 deletions
diff --git a/lib/libfetch/common.c b/lib/libfetch/common.c
index a04cb0bb5afe..e3dab8dfc28a 100644
--- a/lib/libfetch/common.c
+++ b/lib/libfetch/common.c
@@ -25,7 +25,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $Id: common.c,v 1.3 1998/12/16 10:24:52 des Exp $
+ * $Id: common.c,v 1.4 1998/12/18 14:32:48 des Exp $
*/
#include <sys/param.h>
@@ -240,3 +240,45 @@ _fetch_connect(char *host, int port, int verbose)
return sd;
}
+
+
+/*** Directory-related utility functions *************************************/
+
+int
+_fetch_add_entry(struct url_ent **p, int *size, int *len,
+ char *name, struct url_stat *stat)
+{
+ struct url_ent *tmp;
+
+ if (*p == NULL) {
+#define INITIAL_SIZE 8
+ if ((*p = malloc(INITIAL_SIZE * sizeof **p)) == NULL) {
+ errno = ENOMEM;
+ _fetch_syserr();
+ return -1;
+ }
+ *size = INITIAL_SIZE;
+ *len = 0;
+#undef INITIAL_SIZE
+ }
+
+ if (*len >= *size - 1) {
+ tmp = realloc(*p, *size * 2 * sizeof **p);
+ if (tmp == NULL) {
+ errno = ENOMEM;
+ _fetch_syserr();
+ return -1;
+ }
+ *size *= 2;
+ *p = tmp;
+ }
+
+ tmp = *p + *len;
+ snprintf(tmp->name, MAXPATHLEN, "%s", name);
+ bcopy(stat, &tmp->stat, sizeof *stat);
+
+ (*len)++;
+ (++tmp)->name[0] = 0;
+
+ return 0;
+}