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

Function nh_basename

src/files.c:198–229  ·  view source on GitHub ↗

return a file's name without its path and optionally trailing 'type' */

Source from the content-addressed store, hash-verified

196
197/* return a file's name without its path and optionally trailing 'type' */
198const char *
199nh_basename(const char *fname, boolean keep_suffix)
200{
201#ifndef VMS
202 static char basebuf[80];
203 const char *p;
204
205 if ((p = strrchr(fname, '/')) != 0)
206 fname = p + 1;
207#if defined(WIN32) || defined(MSDOS)
208 if ((p = strrchr(fname, '\\')) != 0)
209 fname = p + 1;
210#endif
211 if ((p = strrchr(fname, '.')) != 0 && !keep_suffix) {
212 size_t ln = (size_t) (p - fname);
213 /* note that without path, name should be reasonable length;
214 it is expected to refer to a source file name or run-time
215 configuration file name and those aren't arbitrarily long;
216 if "name" part of "name.suffix" is too long for 'basebuf[]',
217 just return that as-is without stripping off ".suffix" */
218
219 if (ln < sizeof basebuf) {
220 strncpy(basebuf, fname, ln);
221 basebuf[ln] = '\0';
222 fname = basebuf;
223 }
224 }
225#else /* VMS */
226 fname = vms_basename(fname, keep_suffix);
227#endif
228 return fname;
229}
230
231/*
232 * fname_encode()

Callers 3

ask_do_tutorialFunction · 0.85
debugcoreFunction · 0.85
status_versionFunction · 0.85

Calls 1

strrchrFunction · 0.85

Tested by

no test coverage detected