MCPcopy Create free account
hub / github.com/NetHack/NetHack / new_oname

Function new_oname

util/sfctool.c:1195–1212  ·  view source on GitHub ↗

allocate space for an object's name; removes old name if there is one */

Source from the content-addressed store, hash-verified

1193
1194/* allocate space for an object's name; removes old name if there is one */
1195void
1196new_oname(struct obj *obj,
1197 int lth) /* desired length (caller handles adding 1
1198 for terminator) */
1199{
1200 if (lth) {
1201 /* allocate oextra if necessary; otherwise get rid of old name */
1202 if (!obj->oextra)
1203 obj->oextra = newoextra();
1204 else
1205 free_oname(obj); /* already has oextra, might also have name */
1206 ONAME(obj) = (char *) alloc((unsigned) lth);
1207 } else {
1208 /* zero length: the new name is empty; get rid of the old name */
1209 if (has_oname(obj))
1210 free_oname(obj);
1211 }
1212}
1213
1214/* release an object's name; retains oextra even if all fields are now null */
1215void

Callers

nothing calls this directly

Calls 3

newoextraFunction · 0.70
free_onameFunction · 0.70
allocFunction · 0.50

Tested by

no test coverage detected