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

4.104.114.84.95
Last change on this file since d6b1d73 was d6b1d73, checked in by Joel Sherrill <joel.sherrill@…>, on 01/22/01 at 14:05:14

2001-01-22 Ralf Corsepius <corsepiu@…>

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