source: rtems/c/src/lib/libc/imfs_gtkn.c @ 6693a68

4.104.114.84.95
Last change on this file since 6693a68 was 3cf8394, checked in by Joel Sherrill <joel.sherrill@…>, on 02/24/99 at 20:58:47

Changed IMFS to use IMFS_NAME_MAX as the maximum length of a basename
rather then NAME_MAX. NAME_MAX is 255 and that lets IMFS chew up memory
too fast. Perhaps in the future, the places in IMFS that put a maximum
length name string on the stack and the jnode structure does not include
a maximu length name string can be fixed so this is not a problem.

  • Property mode set to 100644
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-1998.
8 *  On-Line Applications Research Corporation (OAR).
9 *  Copyright assigned to U.S. Government, 1994.
10 *
11 *  The license and distribution terms for this file may be
12 *  found in the file LICENSE in this distribution or at
13 *  http://www.OARcorp.com/rtems/license.html.
14 *
15 *  $Id$
16 */
17
18#include <stdlib.h>
19#include "imfs.h"
20#include "libio_.h"
21
22IMFS_token_types IMFS_get_token(
23  const char       *path,
24  char             *token,
25  int              *token_len
26)
27{
28  int               i = 0;
29  IMFS_token_types  type = IMFS_NAME;
30
31  /*
32   *  Copy a name into token.  (Remember NULL is a token.)
33   */
34
35  while ( !IMFS_is_separator( path[i] ) && (i <= IMFS_NAME_MAX) ) {
36
37     token[i] = path[i];
38
39     if (i == IMFS_NAME_MAX)
40       return IMFS_INVALID_TOKEN;
41
42     if ( !IMFS_is_valid_name_char( token[i] ) )
43       type = IMFS_INVALID_TOKEN;   
44
45     i++;
46  }
47
48  /*
49   *  Copy a seperator into token.
50   */
51
52  if ( i == 0 ) {
53    token[i] = path[i];
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.