static void Nova_DumpSlots(void) { #define MAX_KEY_FILE_SIZE 16384 /* usually around 4000, cannot grow much */ char filename[CF_BUFSIZE]; int i; snprintf(filename, CF_BUFSIZE - 1, "%s%cts_key", GetStateDir(), FILE_SEPARATOR); char file_contents_new[MAX_KEY_FILE_SIZE] = {0}; for (i = 0; i < CF_OBSERVABLES; i++) { char line[CF_MAXVARSIZE]; if (NovaHasSlot(i)) { snprintf(line, sizeof(line), "%d,%s,%s,%s,%.3lf,%.3lf,%d\n", i, NULLStringToEmpty((char*)NovaGetSlotName(i)), NULLStringToEmpty((char*)NovaGetSlotDescription(i)), NULLStringToEmpty((char*)NovaGetSlotUnits(i)), NovaGetSlotExpectedMinimum(i), NovaGetSlotExpectedMaximum(i), NovaIsSlotConsolidable(i) ? 1 : 0); } else { snprintf(line, sizeof(line), "%d,spare,unused\n", i); } strlcat(file_contents_new, line, sizeof(file_contents_new)); } bool contents_changed = true; Writer *w = FileRead(filename, MAX_KEY_FILE_SIZE, NULL); if (w) { if(strcmp(StringWriterData(w), file_contents_new) == 0) { contents_changed = false; } WriterClose(w); } if(contents_changed) { Log(LOG_LEVEL_VERBOSE, "Updating %s with new slot information", filename); if(!FileWriteOver(filename, file_contents_new)) { Log(LOG_LEVEL_ERR, "Nova_DumpSlots: Could not write file '%s'. (FileWriteOver: %s)", filename, GetErrorStr()); } } chmod(filename, 0600); }
int VarRefCompare(const VarRef *a, const VarRef *b) { int ret = strcmp(a->lval, b->lval); if (ret != 0) { return ret; } ret = strcmp(NULLStringToEmpty(a->scope), NULLStringToEmpty(b->scope)); if (ret != 0) { return ret; } const char *a_ns = a->ns ? a->ns : "default"; const char *b_ns = b->ns ? b->ns : "default"; ret = strcmp(a_ns, b_ns); if (ret != 0) { return ret; } ret = a->num_indices - b->num_indices; if (ret != 0) { return ret; } for (size_t i = 0; i < a->num_indices; i++) { ret = strcmp(a->indices[i], b->indices[i]); if (ret != 0) { return ret; } } return 0; }