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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [lib/] [libc/] [imfs_gtkn.c] - Blame information for rev 507

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

Line No. Rev Author Line
1 30 unneback
/*
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: imfs_gtkn.c,v 1.2 2001-09-27 12:01:15 chris Exp $
15
 */
16
 
17
#include <stdlib.h>
18
#include "imfs.h"
19
#include "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
}

powered by: WebSVN 2.1.0

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