dos.library: Reverted 49008, mixing buffered and unbuffered reads causes wrong data...
[AROS.git] / rom / dos / splitname.c
blob438f6afc53159efb3bef0ec54fe14166e2528907
1 /*
2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Split a path into pieces
6 Lang: english
7 */
8 #ifndef TEST
9 # include "dos_intern.h"
10 #else
11 # include <proto/dos.h>
12 # undef SplitName
13 # undef AROS_LH5
14 # define AROS_LH5(t,fn,a1,a2,a3,a4,a5,bt,bn,o,lib) t fn (a1,a2,a3,a4,a5)
15 # undef AROS_LHA
16 # define AROS_LHA(t,n,r) t n
17 # undef AROS_LIBFUNC_INIT
18 # define AROS_LIBFUNC_INIT
19 # undef AROS_LIBFUNC_EXIT
20 # define AROS_LIBFUNC_EXIT
21 #endif
23 /*****************************************************************************
25 NAME */
26 #include <proto/dos.h>
28 AROS_LH5(LONG, SplitName,
30 /* SYNOPSIS */
31 AROS_LHA(CONST_STRPTR, name, D1),
32 AROS_LHA(ULONG , separator, D2),
33 AROS_LHA(STRPTR, buf, D3),
34 AROS_LHA(LONG , oldpos, D4),
35 AROS_LHA(LONG , size, D5),
37 /* LOCATION */
38 struct DosLibrary *, DOSBase, 69, Dos)
40 /* FUNCTION
41 Split a path into parts at the position of separator.
43 INPUTS
44 name - Split this path
45 separator - Split it at this separator
46 buf - Copy the current part into this buffer
47 oldpos - Begin at this place with the search for separator.
48 If you call this function for the first time, set it
49 to 0.
50 size - The size of the buffer. If the current part of the
51 path is bigger than size-1, only size-1 bytes will
52 be copied.
54 RESULT
55 The next position to continue for the next part or -1 if
56 there is no separator after name+oldpos.
58 NOTES
60 EXAMPLE
62 BUGS
64 SEE ALSO
66 INTERNALS
68 *****************************************************************************/
70 AROS_LIBFUNC_INIT
72 size --;
74 name += oldpos;
76 while (*name != separator && *name && size)
78 size --;
79 *buf++ = *name++;
80 oldpos ++;
83 *buf = 0;
85 if (*name == separator)
86 return oldpos + 1;
88 return -1;
89 AROS_LIBFUNC_EXIT
90 } /* SplitName */
92 #ifdef TEST
94 # include <stdio.h>
95 # include <dos/dos.h>
97 # include <proto/dos.h>
99 int main (int argc, char ** argv)
101 LONG pos;
102 UBYTE buffer[256];
104 if (argc < 3)
106 fprintf (stderr, "Usage: %s <path> <separator>\n", argv[0]);
107 return RETURN_ERROR;
110 pos=0;
114 pos = SplitName (argv[1], *(argv[2]), buffer, pos, sizeof(buffer));
116 printf ("pos = %3ld buffer = \"%s\"\n", pos, buffer);
118 while (pos != -1);
120 return RETURN_OK;
123 #endif /* TEST */