source: rtems/cpukit/libfs/src/imfs/imfs_gtkn.c @ c873f40

4.104.114.84.95
Last change on this file since c873f40 was c873f40, checked in by Joel Sherrill <joel.sherrill@…>, on Apr 8, 2002 at 6:28:59 PM

2002-04-06 Ralf Corsepius <corsepiu@…>

  • src/imfs/imfs_getchild.c: include <string.h>.
  • src/imfs/imfs_gtkn.c: Include <string.h>.
  • src/imfs/ioman.c: Include <string.h>.
  • src/imfs/linearfile.c: Include <string.h>.
  • src/imfs/memfile.c: Include <string.h>.
  • Property mode set to 100644
File size: 1.7 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#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <stdlib.h>
22#include <string.h>
23
24#include "imfs.h"
25#include <rtems/libio_.h>
26
27IMFS_token_types IMFS_get_token(
28  const char       *path,
29  char             *token,
30  int              *token_len
31)
32{
33  register int i = 0;
34  IMFS_token_types  type = IMFS_NAME;
35  register char c;
36
37  /*
38   *  Copy a name into token.  (Remember NULL is a token.)
39   */
40  c = path[i];
41  while ( (!IMFS_is_separator(c)) && (i <= IMFS_NAME_MAX) ) {
42
43     token[i] = c;
44
45     if ( i == IMFS_NAME_MAX )
46       return IMFS_INVALID_TOKEN;
47
48     if ( !IMFS_is_valid_name_char(c) )
49       type = IMFS_INVALID_TOKEN;   
50
51     c = path [++i];
52  }
53
54  /*
55   *  Copy a seperator into token.
56   */
57
58  if ( i == 0 ) {
59    token[i] = c;
60
61    if ( token[i] != '\0' ) {
62      i++;
63      type = IMFS_CURRENT_DIR;
64    } else {
65      type = IMFS_NO_MORE_PATH;
66    }
67  } else if (token[ i-1 ] != '\0') {
68    token[i] = '\0';
69  }
70
71  /*
72   *  Set token_len to the number of characters copied.
73   */
74
75  *token_len = i;
76
77  /*
78   *  If we copied something that was not a seperator see if
79   *  it was a special name.
80   */
81
82  if ( type == IMFS_NAME ) {
83    if ( strcmp( token, "..") == 0 )
84      type = IMFS_UP_DIR;
85    else if ( strcmp( token, "." ) == 0 )
86      type = IMFS_CURRENT_DIR;
87  }
88
89  return type;
90}
Note: See TracBrowser for help on using the repository browser.