OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems-20020807/] [cpukit/] [libfs/] [src/] [imfs/] [imfs_gtkn.c] - Blame information for rev 1026

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1026 ivang
/*
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
 *  imfs_gtkn.c,v 1.8 2002/04/08 18:28:59 joel Exp
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
 
27
IMFS_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
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.