ia64/xen-unstable

changeset 4195:f7b4c5d6eb0d

bitkeeper revision 1.1159.269.7 (4239b07dqrgbq5nyeaRv54s7lw6AsA)

Add sxpr function for installing a new type.

Signed-off-by: Mike Wray <mike.wray@hp.com>
author mjw@wray-m-3.hpl.hp.com
date Thu Mar 17 16:29:49 2005 +0000 (2005-03-17)
parents 700e62ea1297
children 504d405a48d6
files tools/libxutil/sxpr.c tools/libxutil/sxpr.h
line diff
     1.1 --- a/tools/libxutil/sxpr.c	Thu Mar 17 16:28:34 2005 +0000
     1.2 +++ b/tools/libxutil/sxpr.c	Thu Mar 17 16:29:49 2005 +0000
     1.3 @@ -82,6 +82,30 @@ static SxprType types[1024] = {
     1.4  /** Number of entries in the types array. */
     1.5  static int type_sup = sizeof(types)/sizeof(types[0]);
     1.6  
     1.7 +/** Define a type.
     1.8 + * The tydef must have a non-zero type code.
     1.9 + * It is an error if the type code is out of range or already defined.
    1.10 + *
    1.11 + * @param tydef type definition
    1.12 + * @return 0 on success, error code otherwise
    1.13 + */
    1.14 +int def_sxpr_type(SxprType *tydef){
    1.15 +    int err = 0;
    1.16 +    int ty = tydef->type;
    1.17 +    if(ty < 0 || ty >= type_sup){
    1.18 +        err = -EINVAL;
    1.19 +        goto exit;
    1.20 +    }
    1.21 +    if(types[ty].type){
    1.22 +        err = -EEXIST;
    1.23 +        goto exit;
    1.24 +    }
    1.25 +    types[ty] = *tydef;
    1.26 +  exit:
    1.27 +    return err;
    1.28 +    
    1.29 +}
    1.30 +
    1.31  /** Get the type definition for a given type code.
    1.32   *
    1.33   * @param ty type code
     2.1 --- a/tools/libxutil/sxpr.h	Thu Mar 17 16:28:34 2005 +0000
     2.2 +++ b/tools/libxutil/sxpr.h	Thu Mar 17 16:29:49 2005 +0000
     2.3 @@ -307,6 +307,7 @@ typedef struct SxprType {
     2.4  } SxprType;
     2.5  
     2.6  
     2.7 +extern int def_sxpr_type(SxprType *tydef);
     2.8  extern SxprType *get_sxpr_type(int ty);
     2.9  
    2.10  /** Free the pointer in an sxpr.