FILE *gBank_File;
// === CODE ===
+static int Bank_int_WriteEntry(int ID)
+{
+ if( ID < 0 || ID >= giBank_NumUsers ) {
+ return -1;
+ }
+
+ // Commit to file
+ fseek(gBank_File, ID*sizeof(gaBank_Users[0]), SEEK_SET);
+ fwrite(&gaBank_Users[ID], sizeof(gaBank_Users[0]), 1, gBank_File);
+
+ return 0;
+}
+
int Bank_GetUserByName(const char *Username)
{
int i, uid;
gaBank_Users[ID].Flags &= ~Mask;
gaBank_Users[ID].Flags |= Value;
+
+ Bank_int_WriteEntry(ID);
return 0;
}
// Update
gaBank_Users[ID].Balance += Delta;
- // Commit
- fseek(gBank_File, ID*sizeof(gaBank_Users[0]), SEEK_SET);
- fwrite(&gaBank_Users[ID], sizeof(gaBank_Users[0]), 1, gBank_File);
-
- return 0;
-}
-
-int Bank_SetUserBalance(int ID, int Value)
-{
- // Sanity
- if( ID < 0 || ID >= giBank_NumUsers )
- return -1;
-
- // Update
- gaBank_Users[ID].Balance = Value;
-
- // Commit
- fseek(gBank_File, ID*sizeof(gaBank_Users[0]), SEEK_SET);
- fwrite(&gaBank_Users[ID], sizeof(gaBank_Users[0]), 1, gBank_File);
+ Bank_int_WriteEntry(ID);
return 0;
}
else if( strcmp(Username, "root") == 0 ) {
gaBank_Users[giBank_NumUsers].Flags = USER_FLAG_WHEEL|USER_FLAG_COKE;
}
-
- // Commit to file
- fseek(gBank_File, giBank_NumUsers*sizeof(gaBank_Users[0]), SEEK_SET);
- fwrite(&gaBank_Users[giBank_NumUsers], sizeof(gaBank_Users[0]), 1, gBank_File);
// Increment count
giBank_NumUsers ++;
+
+ Bank_int_WriteEntry(giBank_NumUsers - 1);
return 0;
}