source:
rtems/cpukit/libfs/src/imfs/imfs_gtkn.c
@
c058578
Last change on this file since c058578 was c058578, checked in by Joel Sherrill <joel.sherrill@…>, on 11/01/00 at 21:02:46 | |
---|---|
|
|
File size: 1.6 KB |
Line | |
---|---|
1 | /* |
2 | * IMFS_get_token |
3 | * |
4 | * Routine to get a token (name or separator) from the path |
5 | * the length of the token is returned in token_len. |
6 | * |
7 | * COPYRIGHT (c) 1989-1999. |
8 | * On-Line Applications Research Corporation (OAR). |
9 | * |
10 | * The license and distribution terms for this file may be |
11 | * found in the file LICENSE in this distribution or at |
12 | * http://www.OARcorp.com/rtems/license.html. |
13 | * |
14 | * $Id$ |
15 | */ |
16 | |
17 | #include <stdlib.h> |
18 | #include "imfs.h" |
19 | #include <rtems/libio_.h> |
20 | |
21 | IMFS_token_types IMFS_get_token( |
22 | const char *path, |
23 | char *token, |
24 | int *token_len |
25 | ) |
26 | { |
27 | register int i = 0; |
28 | IMFS_token_types type = IMFS_NAME; |
29 | register char c; |
30 | |
31 | /* |
32 | * Copy a name into token. (Remember NULL is a token.) |
33 | */ |
34 | c = path[i]; |
35 | while ( (!IMFS_is_separator(c)) && (i <= IMFS_NAME_MAX) ) { |
36 | |
37 | token[i] = c; |
38 | |
39 | if ( i == IMFS_NAME_MAX ) |
40 | return IMFS_INVALID_TOKEN; |
41 | |
42 | if ( !IMFS_is_valid_name_char(c) ) |
43 | type = IMFS_INVALID_TOKEN; |
44 | |
45 | c = path [++i]; |
46 | } |
47 | |
48 | /* |
49 | * Copy a seperator into token. |
50 | */ |
51 | |
52 | if ( i == 0 ) { |
53 | token[i] = c; |
54 | |
55 | if ( token[i] != '\0' ) { |
56 | i++; |
57 | type = IMFS_CURRENT_DIR; |
58 | } else { |
59 | type = IMFS_NO_MORE_PATH; |
60 | } |
61 | } else if (token[ i-1 ] != '\0') { |
62 | token[i] = '\0'; |
63 | } |
64 | |
65 | /* |
66 | * Set token_len to the number of characters copied. |
67 | */ |
68 | |
69 | *token_len = i; |
70 | |
71 | /* |
72 | * If we copied something that was not a seperator see if |
73 | * it was a special name. |
74 | */ |
75 | |
76 | if ( type == IMFS_NAME ) { |
77 | if ( strcmp( token, "..") == 0 ) |
78 | type = IMFS_UP_DIR; |
79 | else if ( strcmp( token, "." ) == 0 ) |
80 | type = IMFS_CURRENT_DIR; |
81 | } |
82 | |
83 | return type; |
84 | } |
Note: See TracBrowser
for help on using the repository browser.