Detabbed
[AROS.git] / rom / dos / filepart.c
blob13db7eaea3ee77202778def849343db04f27c097
1 /*
2 Copyright © 1995-2008, The AROS Development Team. All rights reserved.
3 $Id$
5 Returns a pointer to the first char of the filename in the give file part.
6 */
7 #ifndef TEST
8 # include "dos_intern.h"
9 #else
10 # define AROS_LH1(t,fn,a1,bt,bn,o,lib) t fn (a1)
11 # define AROS_LHA(t,n,r) t n
12 # define AROS_LIBFUNC_INIT
13 # define AROS_LIBFUNC_EXIT
14 # include <exec/types.h>
15 # define CLIB_DOS_PROTOS_H
16 #endif
17 #include <string.h>
20 /*****************************************************************************
22 NAME */
23 #include <proto/dos.h>
25 AROS_LH1(STRPTR, FilePart,
27 /* SYNOPSIS */
28 AROS_LHA(CONST_STRPTR, path, D1),
30 /* LOCATION */
31 struct DosLibrary *, DOSBase, 145, Dos)
33 /* FUNCTION
34 Get a pointer to the last component of a path, which is normally the
35 filename.
37 INPUTS
38 path - pointer AmigaDOS path string
39 May be relative to the current directory or the current disk.
41 RESULT
42 A pointer to the first char of the filename!
44 NOTES
46 EXAMPLE
47 FilePart("xxx:yyy/zzz/qqq") returns a pointer to the first 'q'.
48 FilePart("xxx:yyy") returns a pointer to the first 'y'.
49 FilePart("yyy") returns a pointer to the first 'y'.
51 BUGS
52 None known.
54 SEE ALSO
55 PathPart(), AddPart()
57 INTERNALS
58 Goes from the last char of the pathname back until it finds a ':',
59 a '/' or until the first char reached.
61 *****************************************************************************/
63 AROS_LIBFUNC_INIT
65 if(path)
67 CONST_STRPTR i;
69 /* set i to last char of path */
71 if (!*path) /* path == "" ? */
72 return (STRPTR)path;
74 i = path + strlen (path) -1; /* set i to the \0-byte */
76 /* decrease pointer as long as there is no ':', no '/' or till
77 the first char anyway. hope this works in all situations */
78 while ((*i != ':') && (*i != '/') && (i != path))
79 i--;
81 if ((*i == ':')) i++;
82 if ((*i == '/')) i++;
84 return (STRPTR)i;
85 } /* path */
87 return NULL; /* if no path is given, return NULL pointer (shouldn't happen) */
89 AROS_LIBFUNC_EXIT
90 } /* FilePart */
92 #ifdef TEST
94 # include <stdio.h>
96 int main (int argc, char ** argv)
98 UWORD i;
99 CONST_STRPTR s, fileptr;
101 while (--argc)
103 s = *++argv;
104 fileptr = FilePart(s);
106 printf("Pfad: %s\nDatei: %s\n", s, fileptr);
110 #endif /* TEST */