Subversion Repositories HelenOS

Rev

Rev 3886 | Rev 4192 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3886 Rev 3912
Line 1... Line 1...
1
/*
1
/*
2
 * Copyright (c) 2008 Lukas Mejdrech
2
 * Copyright (c) 2009 Lukas Mejdrech
3
 * All rights reserved.
3
 * All rights reserved.
4
 *
4
 *
5
 * Redistribution and use in source and binary forms, with or without
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
6
 * modification, are permitted provided that the following conditions
7
 * are met:
7
 * are met:
Line 29... Line 29...
29
/** @addtogroup net
29
/** @addtogroup net
30
 *  @{
30
 *  @{
31
 */
31
 */
32
 
32
 
33
/** @file
33
/** @file
34
 *  A character string to integer map implementation file.
34
 *  Character string to integer map implementation.
-
 
35
 *  @see char_map.h
35
 */
36
 */
36
 
37
 
37
#include <errno.h>
38
#include <errno.h>
38
#include <malloc.h>
39
#include <malloc.h>
39
#include <unistd.h>
40
#include <unistd.h>
40
#include <string.h>
41
#include <string.h>
41
 
42
 
42
#include "char_map.h"
43
#include "char_map.h"
43
 
44
 
44
/** An&nbsp;internal magic value for a&nbsp;consistency check.
45
/** Internal magic value for a&nbsp;consistency check.
45
 */
46
 */
46
#define CHAR_MAP_MAGIC_VALUE    0x12345611
47
#define CHAR_MAP_MAGIC_VALUE    0x12345611
47
 
48
 
48
/** Adds the value with the key to the map.
49
/** Adds the value with the key to the map.
49
 *  Creates new nodes to map the key.
50
 *  Creates new nodes to map the key.
50
 *  @param map The character string to integer map. Input/output parameter.
51
 *  @param map The character string to integer map. Input/output parameter.
51
 *  @param identifier The key zero ('\0') terminated character string. The key character string is processed until the first terminating zero ('\0') character after the given length is found. Input parameter.
52
 *  @param identifier The key zero ('\\0') terminated character string. The key character string is processed until the first terminating zero ('\\0') character after the given length is found. Input parameter.
52
 *  @param length The key character string length. The parameter may be zero (0) which means that the string is processed until the terminating zero ('\0') character is found. Input parameter.
53
 *  @param length The key character string length. The parameter may be zero (0) which means that the string is processed until the terminating zero ('\\0') character is found. Input parameter.
53
 *  @param value The integral value to be stored for the key character string. Input parameter.
54
 *  @param value The integral value to be stored for the key character string. Input parameter.
54
 *  @returns EOK on success.
55
 *  @returns EOK on success.
55
 *  @returns ENOMEM if there is no memory left.
56
 *  @returns ENOMEM if there is not enough memory left.
56
 *  @returns EEXIST if the key character string is already used.
57
 *  @returns EEXIST if the key character string is already used.
57
 */
58
 */
58
int char_map_add_item( char_map_ref map, const char * identifier, size_t length, const int value );
59
int char_map_add_item( char_map_ref map, const char * identifier, size_t length, const int value );
59
 
60
 
60
/** Returns the node assigned to the key from the map.
61
/** Returns the node assigned to the key from the map.
61
 *  @param map The character string to integer map. Input parameter.
62
 *  @param map The character string to integer map. Input parameter.
62
 *  @param identifier The key zero ('\0') terminated character string. The key character string is processed until the first terminating zero ('\0') character after the given length is found. Input parameter.
63
 *  @param identifier The key zero ('\\0') terminated character string. The key character string is processed until the first terminating zero ('\\0') character after the given length is found. Input parameter.
63
 *  @param length The key character string length. The parameter may be zero (0) which means that the string is processed until the terminating zero ('\0') character is found. Input parameter.
64
 *  @param length The key character string length. The parameter may be zero (0) which means that the string is processed until the terminating zero ('\\0') character is found. Input parameter.
64
 *  @returns The node holding the integral value assigned to the key character string.
65
 *  @returns The node holding the integral value assigned to the key character string.
65
 *  @returns NULL if the key is not assigned a&nbsp;node.
66
 *  @returns NULL if the key is not assigned a&nbsp;node.
66
 */
67
 */
67
char_map_ref    char_map_find_node( const char_map_ref map, const char * identifier, const size_t length );
68
char_map_ref    char_map_find_node( const char_map_ref map, const char * identifier, const size_t length );
68
 
69