int safety(){ int i , j; copyFromTo(AVAILABLE,WORK); int *finish = (int *) malloc(sizeof(int ) * n); while((i = find(finish, WORK, NEED )) != -1){ for(j = 0;j<m;j++){ WORK[j] += ALLOCATION[i][j]; } finish[i] = 1; printf("%d just completed\n", i); if( allFinished(finish)) break; } if(!allFinished(finish)){ printf("unsafe"); return 0; } else{ printf("safe"); return 1; } }
bool download(const char* srvPath, const char* localPath, dlCallback cb) { FILE* fout = fopen(localPath, "wb"); if (!fout) { fprintf(stderr, "Can't open %s!\n", localPath); return false; } int size; FILE* fin = fopen_web(srvPath, &size); if (!fin) { fclose(fout); fprintf(stderr, "Can't download %s!\n", srvPath); return false; } if (size == -1) { fclose(fout); fclose(fin); fprintf(stderr, "Unknown download size!\n"); return false; } copyFromTo(fout, fin, size, cb); fclose(fout); fclose(fin); return true; }