tools/adflib: build only host variant which is used by Sam440 target
[AROS.git] / workbench / network / stacks / AROSTCP / netlib / _allocufb.c
blobb81ed124a4a89a51e148e73f052a01e4707e097c
1 /* $Id$
3 * _allocufb.c - get a free ufb (SAS/C)
5 * Copyright © 1994 AmiTCP/IP Group,
6 * Network Solutions Development Inc.
7 * All rights reserved.
8 */
10 #include <ios1.h>
11 #include <stdlib.h>
12 #include <errno.h>
15 * Allocate new ufb, which is returned as return value. The corresponding fd
16 * is returned via fdp.
18 struct UFB *
19 __allocufb(int *fdp)
21 struct UFB *ufb, *last_ufb;
22 int last_fd = 0;
25 * find first free ufb
27 last_ufb = ufb = __ufbs;
28 while (ufb != NULL && ufb->ufbflg != 0) {
29 last_ufb = ufb;
30 last_fd++;
31 ufb = last_ufb->ufbnxt;
34 * Check if need to create one
36 if (ufb == NULL) {
37 if ((ufb = malloc(sizeof(*ufb))) == NULL) {
38 errno = ENOMEM;
39 return NULL;
41 ufb->ufbnxt = NULL;
42 ufb->ufbflg = 0; /* => unused ufb */
44 if (last_ufb == NULL)
45 __ufbs = ufb;
46 else
47 last_ufb->ufbnxt = ufb;
49 *fdp = __nufbs++;
51 else
52 *fdp = last_fd;
54 return ufb;