/* * This procedure restores the last state of the lists (lwps, processes, * users and project) from the file defined by 'file'. * param file - the file name to be used * return 0, or -1 on error and store the error message in * the global buffer 'errmsg'. */ int list_restore(char *file) { int storefd; int listt, elemn, listn; int64_t timestamp; time_t tv; int version; int ret = -1; if ((storefd = open(file, O_RDONLY)) == -1) return (ret); log_msg("reading persistence file: %s\n", file); /* * the next do {..} while (false); statement is a replacement * of goto; */ do { if (open_prot(storefd, "r") == -1) break; if (skip_line() == -1) break; if ((version = r_value(LTDB_VERSION_KEY)) == -1) break; if (version != LTDB_VERSION) { (void) fprintf(stderr, "wrong version %d of db file %s\n", version, file); break; } if ((timestamp = r_value(LTDB_TIMESTAMP)) == -1) break; /* check the file decay time is expired */ (void) time(&tv); if ((tv - timestamp) > LTDB_DECAYTIME) break; if ((listn = r_lshead()) == -1) break; while (listn-- > 0) { if ((elemn = r_lhead(&listt)) == -1) break; if (list_read(listt, elemn) != 0) { break; } } ret = 0; } while (ret); if (ret == 0) { struct stat stat_buf; (void) fstat(storefd, &stat_buf); log_msg("read: %ld bytes\n", stat_buf.st_size); } /* close_prot(); */ (void) close(storefd); (void) unlink(file); return (ret); }
int main() { /* Creates a vector<Order> from user input, writes to a file, creates another vector from that file, sorts by name, and writes another file Creates a list<Order> from user input, writes to a third file, creates another list from the second file, sorts by address, and writes to fourth file Creates another vector<Order> from the fourth file, merges the two vectors, then writes to a fifth file */ cout << "Making Vector" << endl; vect_write(make_vector(10), "file1.txt"); vector<Order> v1 = vect_read("file1.txt"); sort(v1.begin(), v1.end(), cmp_name); vect_write(v1, "file2.txt"); cout << "Making List" << endl; list_write(make_list(10), "file3.txt"); list<Order> l = list_read("file3.txt"); l.sort(cmp_add); list_write(l, "file4.txt"); vector<Order> v2 = vect_read("file4.txt"); sort(v2.begin(), v2.end(), cmp_name); vector<Order> v3(20); merge(v1.begin(), v1.end(), v2.begin(), v2.end(), v3.begin(), cmp_name); vect_write(v3, "file5.txt"); }
void select_method (char **argv) { int x = 1; if (x==1) matrix_read(argv[3], atoi(argv[2])); else if(!x) list_read(argv[3]); else exit(1); }
int ipv4_black_list_read(const char *file_name) { int rv; FUN("ipv4_black_list_read"); rv = list_read(file_name, &black_list, &black_list_items, &black_list_alloc); return rv; }