int property_set( char *name, char *val ) { char buf[96]; int line_no = 0; int kc; char *ki[15]; int tf, f; char *t_property_file_name = "/tmp_perperty.tr"; int new_key = 1; f = uffs_open( g_property_file_name, UO_RDONLY ); if( f == -1 ){ f = uffs_open( g_property_file_name, UO_RDWR|UO_CREATE ); if( f == -1 ) return -1; } tf = uffs_open( t_property_file_name, UO_WRONLY|UO_CREATE ); if( tf == -1 ){ uffs_close( f ); return -1; } while(1){ if( uffs_read_line( f, buf, sizeof( buf ) ) < 0 ) break; kc = analysis_string_to_strings_by_decollator( buf, "=", ki, 15 ); if( kc !=2 ) continue; if( s_strcmp( ki[0], name ) == 0 ){ //int len; //strncpy( buf, &ki[1], sizeof(buf) ); if( new_key == 0 ) continue; sprintf( buf, "%s=%s\n", name, val ); new_key = 0; } else strcat( buf, "\n" ); uffs_write( tf, buf, strlen( buf ) ); } if( new_key == 1 ){ uffs_close( tf ); uffs_close( f ); f = uffs_open( g_property_file_name, UO_RDWR|UO_CREATE ); if( f == -1 ) return -1; uffs_seek( f, 0, _SEEK_END ); sprintf( buf, "%s=%s\n", name, val ); uffs_write( f, buf, strlen( buf ) ); uffs_close( f ); } else{ uffs_close( tf ); uffs_close( f ); uffs_remove( g_property_file_name ); uffs_rename( t_property_file_name, g_property_file_name ); } return 0; }
static int dfs_uffs_rename( struct dfs_filesystem* fs, const char* oldpath, const char* newpath) { int result; result = uffs_rename(oldpath, newpath); if (result < 0) return uffs_result_to_dfs(uffs_get_error()); return 0; }
/** ren|mv <old> <new> */ static int cmd_ren(int argc, char *argv[]) { const char *oldname; const char *newname; int ret; CHK_ARGC(3, 3); oldname = argv[1]; newname = argv[2]; if ((ret = uffs_rename(oldname, newname)) == 0) { MSGLN("Rename from '%s' to '%s' succ.", oldname, newname); } else { MSGLN("Rename from '%s' to '%s' fail!", oldname, newname); } return ret; }
static byte RenameCmd(const unsigned char *cmd, const CLS1_ConstStdIOType *io) { /* precondition: cmd starts with "rename" */ char to_name[UFFS_PATHSIZE]; char from_name[UFFS_PATHSIZE]; byte res = ERR_OK; size_t lenRead; if ((UTIL1_ReadEscapedName(cmd+sizeof("rename"), (unsigned char*)from_name, sizeof(from_name), &lenRead, NULL, NULL)==ERR_OK) && *(cmd+sizeof("rename")+lenRead)==' ' && (UTIL1_ReadEscapedName(cmd+sizeof("rename")+lenRead+1, (unsigned char*)to_name, sizeof(to_name), NULL, NULL, NULL)==ERR_OK)) { res = uffs_rename( from_name, to_name ); } else { CmdUsageError(cmd, (unsigned char*)"rename srcFileName dstFileName", io); res = ERR_FAILED; } return res; }