X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs2.git;a=blobdiff_plain;f=yaffs_nameval.c;h=a4ed2973526ba259375199b480f01d7c49298dcd;hp=e15b647196eb316994a46e83fc8bee7501c446eb;hb=eadf0b4ff9a673b3acff35430c6f9edc48c616a6;hpb=299791ad6d378fae30d50560097a7633cde3aab2 diff --git a/yaffs_nameval.c b/yaffs_nameval.c index e15b647..a4ed297 100644 --- a/yaffs_nameval.c +++ b/yaffs_nameval.c @@ -21,6 +21,8 @@ * nbytes value. * ---------- * total size stored in record size + * + * This code has not been tested with unicode yet. */ @@ -28,7 +30,7 @@ #include "yportenv.h" -static int nval_find(const char *xb, int xb_size, const char *name, +static int nval_find(const char *xb, int xb_size, const YCHAR *name, int *exist_size) { int pos=0; @@ -36,7 +38,7 @@ static int nval_find(const char *xb, int xb_size, const char *name, memcpy(&size,xb,sizeof(int)); while(size > 0 && (size < xb_size) && (pos + size < xb_size)){ - if(strncmp(xb+pos+sizeof(int),name,size) == 0){ + if(yaffs_strncmp((YCHAR *)(xb+pos+sizeof(int)),name,size) == 0){ if(exist_size) *exist_size = size; return pos; @@ -68,7 +70,7 @@ static int nval_used(const char *xb, int xb_size) return pos; } -int nval_del(char *xb, int xb_size, const char *name) +int nval_del(char *xb, int xb_size, const YCHAR *name) { int pos = nval_find(xb, xb_size, name, NULL); int size; @@ -80,13 +82,13 @@ int nval_del(char *xb, int xb_size, const char *name) memset(xb + (xb_size - size),0,size); return 0; } else - return -ENOENT; + return -ENODATA; } -int nval_set(char *xb, int xb_size, const char *name, const char *buf, int bsize, int flags) +int nval_set(char *xb, int xb_size, const YCHAR *name, const char *buf, int bsize, int flags) { int pos; - int namelen = strnlen(name,xb_size); + int namelen = yaffs_strnlen(name,xb_size); int reclen; int size_exist = 0; int space; @@ -97,7 +99,7 @@ int nval_set(char *xb, int xb_size, const char *name, const char *buf, int bsize if(flags & XATTR_CREATE && pos >= 0) return -EEXIST; if(flags & XATTR_REPLACE && pos < 0) - return -ENOENT; + return -ENODATA; start = nval_used(xb,xb_size); space = xb_size - start + size_exist; @@ -116,13 +118,13 @@ int nval_set(char *xb, int xb_size, const char *name, const char *buf, int bsize memcpy(xb + pos,&reclen,sizeof(int)); pos +=sizeof(int); - strncpy(xb + pos, name, reclen); + yaffs_strncpy((YCHAR *)(xb + pos), name, reclen); pos+= (namelen+1); memcpy(xb + pos,buf,bsize); return 0; } -int nval_get(const char *xb, int xb_size, const char *name, char *buf, int bsize) +int nval_get(const char *xb, int xb_size, const YCHAR *name, char *buf, int bsize) { int pos = nval_find(xb,xb_size,name,NULL); int size; @@ -148,7 +150,10 @@ int nval_get(const char *xb, int xb_size, const char *name, char *buf, int bsize } } - return -ENOENT; + if(pos >= 0) + return -ERANGE; + else + return -ENODATA; } int nval_list(const char *xb, int xb_size, char *buf, int bsize) @@ -163,12 +168,16 @@ int nval_list(const char *xb, int xb_size, char *buf, int bsize) while(size > sizeof(int) && size <= xb_size && (pos + size) < xb_size && !filled){ pos+= sizeof(int); size-=sizeof(int); - name_len = strnlen(xb + pos, size); + name_len = yaffs_strnlen((YCHAR *)(xb + pos), size); if(ncopied + name_len + 1 < bsize){ - memcpy(buf,xb+pos,name_len); + memcpy(buf,xb+pos,name_len * sizeof(YCHAR)); buf+= name_len; *buf = '\0'; buf++; + if(sizeof(YCHAR) > 1){ + *buf = '\0'; + buf++; + } ncopied += (name_len+1); } else filled = 1; @@ -181,31 +190,8 @@ int nval_list(const char *xb, int xb_size, char *buf, int bsize) return ncopied; } -int nval_load(char *xb, int xb_size, const char *src, int src_size) -{ - int tx_size; - int used; - - tx_size = xb_size; - if(tx_size > src_size) - tx_size = src_size; - - memcpy(xb,src,tx_size); - used = nval_used(xb, xb_size); - - if( used < xb_size) - memset(xb+ used, 0, xb_size - used); - return used; -} -int nval_save(const char *xb, int xb_size, char *dest, int dest_size) +int nval_hasvalues(const char *xb, int xb_size) { - int tx_size; - - tx_size = xb_size; - if(tx_size > dest_size) - tx_size = dest_size; - - memcpy(dest,xb,tx_size); - return tx_size; + return nval_used(xb, xb_size) > 0; }