bank_account* create_account(char* acct_owner, double init_balance, char* acct_num) { bank_account* b = NULL; if(acct_owner != NULL && strlen(acct_owner) > 0) { if(acct_num != NULL && is_all_digits(acct_num)) { if(strlen(acct_num) == ACCT_LENGTH) { if(init_balance >= 0) { b = malloc(sizeof(bank_account)); b -> owner = create_copy(acct_owner); b -> balance = init_balance; b -> num = create_copy(acct_num); } else { printf("The account balance is less than 0. Please try again with a balance of zero or greater.\n"); exit(0); } } else { printf("Please be sure the account number is 13 digits in length and try again.\n"); exit(0); } } else { printf("Please be sure your account is valid and that the account number contains only digits and try again.\n"); exit(0); } } else { printf("Please be sure the account is valid and that there is an owner's name associated with it and try again.\n"); exit(0); } return b; }
static enum swupd_code clean_staged_manifests(const char *path, bool dry_run, bool all) { DIR *dir; dir = opendir(path); if (!dir) { return SWUPD_COULDNT_LIST_DIR; } /* NOTE: Currently Manifest files have their timestamp from generation * preserved. */ /* When --all is not used, keep the Manifests used by the current OS version. This * ensures that a regular 'clean' won't make 'search' redownload files. */ char *mom_contents = NULL; if (!all) { int current_version = get_current_version(path_prefix); if (current_version < 0) { warn("Unable to determine current OS version\n"); } else { mom_contents = read_mom_contents(current_version); } } int ret = SWUPD_OK; while (true) { /* Reset errno to properly identify the end of stream. */ errno = 0; struct dirent *entry; entry = readdir(dir); if (!entry) { if (errno) { ret = SWUPD_COULDNT_LIST_DIR; } break; } const char *name = entry->d_name; if (!strcmp(name, ".") || !strcmp(name, "..")) { continue; } if (!is_all_digits(name)) { continue; } char *version_dir; string_or_die(&version_dir, "%s/%s", state_dir, name); /* This is not precise: it may keep Manifest files that we don't use, and * also will keep the previous version. If that extra precision is * required we should parse the manifest. */ if (mom_contents && strstr(mom_contents, name)) { /* Remove all hash-hint manifest files. */ ret = remove_if(version_dir, dry_run, is_hashed_manifest); } else { /* Remove all manifest files, including hash-hints */ ret = remove_if(version_dir, dry_run, is_manifest); } /* Remove empty dirs if possible. */ (void)rmdir(version_dir); free_string(&version_dir); if (ret != 0) { break; } } free(mom_contents); closedir(dir); return ret; }