source: trunk/kStuff/kHlp/Generic/kHlpGetFilename.c@ 3575

Last change on this file since 3575 was 3575, checked in by bird, 18 years ago

env, paths, page allocation.

  • Property svn:keywords set to Id
File size: 2.2 KB
Line 
1/* $Id: kHlpGetFilename.c 3575 2007-09-02 20:05:39Z bird $ */
2/** @file
3 * kHlpPath - kHlpGetFilename.
4 */
5
6/*
7 * Copyright (c) 2006-2007 knut st. osmundsen <bird-src-spam@anduin.net>
8 *
9 * This file is part of kStuff.
10 *
11 * kStuff is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 * kStuff is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with kStuff; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 *
25 */
26
27/*******************************************************************************
28* Header Files *
29*******************************************************************************/
30#include <k/kHlpPath.h>
31#include <k/kHlpString.h>
32
33
34/**
35 * Get the pointer to the filename part of the name.
36 *
37 * @returns Pointer to where the filename starts within the string pointed to by pszFilename.
38 * @returns Pointer to the terminator char if no filename.
39 * @param pszFilename The filename to parse.
40 */
41KHLP_DECL(char *) kHlpGetFilename(const char *pszFilename)
42{
43 const char *pszLast = NULL;
44 for (;;)
45 {
46 char ch = *pszFilename;
47#if K_OS == K_OS_OS2 || K_OS == K_OS_WINDOWS
48 if (ch == '/' || ch == '\\' || ch == ':')
49 {
50 while ((ch = *++pszFilename) == '/' || ch == '\\' || ch == ':')
51 /* nothing */;
52 pszLast = pszFilename;
53 }
54#else
55 if (ch == '/')
56 {
57 while ((ch = *++pszFilename) == '/')
58 /* betsuni */;
59 pszLast = pszFilename;
60 }
61#endif
62 if (!ch)
63 return (char *)(pszLast ? pszLast : pszFilename);
64 pszFilename++;
65 }
66}
67
Note: See TracBrowser for help on using the repository browser.