1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2002-2005 Roman Zippel <zippel@linux-m68k.org>
4 * Copyright (C) 2002-2005 Sam Ravnborg <sam@ravnborg.org>
12 #include <hashtable.h>
16 /* hash table of all parsed Kconfig files */
17 static HASHTABLE_DEFINE(file_hashtable
, 1U << 11);
20 struct hlist_node node
;
24 /* file already present in list? If not add it */
25 const char *file_lookup(const char *name
)
29 int hash
= hash_str(name
);
31 hash_for_each_possible(file_hashtable
, file
, node
, hash
)
32 if (!strcmp(name
, file
->name
))
36 file
= xmalloc(sizeof(*file
) + len
+ 1);
37 memset(file
, 0, sizeof(*file
));
38 memcpy(file
->name
, name
, len
);
39 file
->name
[len
] = '\0';
41 hash_add(file_hashtable
, &file
->node
, hash
);
43 str_printf(&autoconf_cmd
, "\t%s \\\n", name
);
48 /* Allocate initial growable string */
49 struct gstr
str_new(void)
52 gs
.s
= xmalloc(sizeof(char) * 64);
59 /* Free storage for growable string */
60 void str_free(struct gstr
*gs
)
67 /* Append to growable string */
68 void str_append(struct gstr
*gs
, const char *s
)
72 l
= strlen(gs
->s
) + strlen(s
) + 1;
74 gs
->s
= xrealloc(gs
->s
, l
);
81 /* Append printf formatted string to growable string */
82 void str_printf(struct gstr
*gs
, const char *fmt
, ...)
85 char s
[10000]; /* big enough... */
87 vsnprintf(s
, sizeof(s
), fmt
, ap
);
92 /* Retrieve value of growable string */
93 char *str_get(const struct gstr
*gs
)