void addenv(var *v) { char envname[Maxenvname]; word *w; int f; io *fd; if(v->changed){ v->changed = 0; snprint(envname, sizeof envname, "/env/%s", v->name); if((f = Creat(envname))<0) pfmt(err, "rc: can't open %s: %r\n", envname); else{ for(w = v->val;w;w = w->next) write(f, w->word, strlen(w->word)+1L); close(f); } } if(v->fnchanged){ v->fnchanged = 0; snprint(envname, sizeof envname, "/env/fn#%s", v->name); if((f = Creat(envname))<0) pfmt(err, "rc: can't open %s: %r\n", envname); else{ if(v->fn){ fd = openfd(f); pfmt(fd, "fn %q %s\n", v->name, v->fn[v->pc-1].s); closeio(fd); } close(f); } } }
int rwp (int argc, char *argv[]) { u64 key; char *file; int rc; FN; if (argc == 1) { file = "testfile"; } else { file = argv[1]; } rc = Creat(file); if (rc) { printf("Creat of %s failed %d\n", file, rc); return rc; } rc = Open(file, &key); if (rc) { printf("Open of %s failed %d\n", file, rc); return rc; } fill_file(key, 1000); Seek(key, 0); check_file(key, 1000); rc = Close(key); if (rc) { printf("Close of %llx failed %d\n", key, rc); return rc; } return 0; }
void show_dispose(DIR*dir_ptr,char*dirname,int flag) { int u=false; if(flag%U==0) u=true; DIR* dir_ptr2; dir_ptr2=opendir(dirname); if(flag%T==0 || flag % B ==0) { Node *head; head=Creat(dir_ptr2,dirname,u); if (flag % T ==0) { head=InsertSort(head); } if(flag % B == 0) { head=Reverse(head); } show_sort(head,flag); } else show(dir_ptr2,dirname,flag); closedir(dir_ptr2); }
void Xwrite(void) { char *file; int f; switch(count(runq->argv->words)){ default: Xerror1("> requires singleton\n"); return; case 0: Xerror1("> requires file\n"); return; case 1: break; } file = runq->argv->words->word; if((f = Creat(file))<0){ pfmt(err, "%s: ", file); Xerror("can't open"); return; } pushredir(ROPEN, f, runq->code[runq->pc].i); runq->pc++; poplist(); }
struct Node * InitLink() { int choose; struct Node * head; system("clear"); printf("\n\n\n\n"); printf(" **************** 1.建立新成绩单 ****************\n\n\r"); printf(" **************** 2.进入系统 ****************\n\n\n\n\n"); printf(" **************** 请输入选项: ****************"); printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); scanf("%d", &choose); if(choose == 1) { printf("录入学生信息,请输入数据(学号-成绩)\n"); head = Creat(); printf("录入成功,数据为:\n"); Print(head); return head; } if(choose == 2) { return 0; } return 0; // }
int main() { int PID; int TYPE; printf("start!\n"); PID=(Creat(0).PID); printf("%d\n",PID); TYPE=(Creat(0).PID); printf("%d\n",TYPE); getchar(); return 0; }
struct Node * creatNewList() { struct Node * head; printf("录入学生信息,请输入数据(学号-成绩)\n"); head = Creat(); printf("录入成功,数据为:\n"); Print(head); return head; }
int main(int argc, char *argv[]) { AdjMatrix *G; G = init(G); Creat(G); show(G); show_result(G); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { struct people * p; p = Creat(); printf("\n%d,%d\n",p->id,p->age); while (p->next != NULL){ p=p->next; printf("%d,%d\n",p->id,p->age); } return 0; }
void test35b() { subtest = 2; /* MaxPath and MaxName checkup. */ Creat(MaxName); MaxPath[strlen(MaxPath) - 2] = '/'; MaxPath[strlen(MaxPath) - 1] = 'a'; /* make ././.../a */ Creat(MaxPath); if (utime(MaxName, NULL) != 0) e(1); if (utime(MaxPath, NULL) != 0) e(2); /* The owner doesn't need write permisson to set times. */ Creat("foo"); if (chmod("foo", 0) != 0) e(3); if (utime("foo", NULL) != 0) e(4); if (chmod("foo", 0777) != 0) e(5); if (utime("foo", NULL) != 0) e(6); System("rm -rf ../DIR_35/*"); }
/* retrieve the mode option and perform the creat() call. returns the file descriptor or a negative value. */ static int _xioopen_creat(const char *path, int rw, struct opt *opts) { mode_t mode = 0666; int fd; retropt_modet(opts, OPT_PERM, &mode); if ((fd = Creat(path, mode)) < 0) { Error3("creat(\"%s\", 0%03o): %s", path, mode, strerror(errno)); return STAT_RETRYLATER; } return fd; }
int main(void) { int n; NODE *pHead = Init(); NODE *pHead2 = Init(); NODE *tar = pHead2; // scanf("%d", &n); Creat(pHead, 5); tar = ListNode(pHead, 0); if(tar != NULL) printf("%d\n", tar->data); else printf("有误!\n"); }
int crp (int argc, char *argv[]) { int i; int rc; FN; for (i = 1; i < argc; i++) { rc = Creat(argv[i]); if (rc) { printf("Couldn't ls %s %d\n", argv[i], rc); return rc; } } return 0; }
int main(int argc, char *argv[]) { AdjList *p; p = (AdjList *)malloc(sizeof(AdjList)); p = Creat(p); show(p); DFS(p, 1); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { AdjList *p; p = (AdjList *)malloc(sizeof(AdjList)); p = Creat(p); ///创建邻接表 show(p); ///展示 show_result(p); ///展示最终结果 return EXIT_SUCCESS; }
int main() { int i,x; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d",&a[i]); } scanf("%d",&x); Creat(p); Search(p,x); if(flag==2) printf("%d",t); else printf("-1"); return 0; }
int main(void) { AdjList g; int i; Creat(&g); for(i=1;i<=g.vexnum;i++) { ArcNode *p= g.vertex[i].head; printf("%c\t",g.vertex[i].vexdata); while(p!=NULL) { printf("%d\t%d\t",p->adjvex,p->weight); p=p->next; } printf("\n"); } TraverseG(g); return 0; }
int main(int argc, char *argv[]) { AdjList *p; AdjMatrix *G; p = (AdjList *)malloc(sizeof(AdjList)); p = Creat(p); show(p); G = init (G); G = trans(G, p); show_two(G); // show_result(p); short_path(G); return EXIT_SUCCESS; }
int main(void) { AdjMatrix *G; int i,j; Creat(G); printf("\n"); for(i=1;i<=G->vexnum;i++) { //printf("%2d:\t",G->vex[i]); for(j=1;j<=G->vexnum;j++) { //这里应该要if判断应该是不等于正无穷,还有输出应该是%d,not &d if(G->arcs[i][j]!=INFINITY) printf("%d\t",G->arcs[i][j]); } printf("\n"); } for(i=1;i<=G->vexnum;i++) printf("%d ",G->vex[i]); printf("\n"); return 0; }
BOOL ScenarioDataMgr::Read(CStdioFile &file) { BOOL bRet = TRUE; CString strTemp; strTemp.Empty(); file.ReadString(strTemp); m_NumofScenarios.InitRow(strTemp); int nNum = ScenarioNum(); ScenarioInfo *pInfo = NULL; for(int i=0;i<nNum;i++) { pInfo = Creat(); file.ReadString(strTemp); pInfo->Info(strTemp); } file.ReadString(strTemp); m_StartScenario.InitRow(strTemp); POSITION pos = m_InfoList.GetHeadPosition(); while(pos) { pInfo = m_InfoList.GetNext(pos); file.ReadString(strTemp); pInfo->OutPut(strTemp); } ReadInfo(file); if ( !isImpFile ) { file.ReadString( strTemp ) ; m_OutputScenarioOrder.InitRow( strTemp ) ; file.ReadString( strTemp ) ; m_OutputScenarioColor.InitRow( strTemp ) ; file.ReadString( strTemp ) ; m_OutputNameFormat.InitRow( strTemp ) ; file.ReadString( strTemp ) ; m_OutputDisplayCurrent.InitRow( strTemp ) ; } return TRUE; }
//------------------------------------------------------------------------- // assign a new module to CTS database //------------------------------------------------------------------------- int Assign() { char line[MODULE_ENTRY+1]; int dbFileSize, fd, i, nullMask, numOfEntries, rc; int status = SUCCESS; // assume the best static DESCRIPTOR( phy_name_p, "PHY_NAME" ); static DYNAMIC_DESCRIPTOR( phy_name ); static DESCRIPTOR( log_name_p, "LOG_NAME" ); static DYNAMIC_DESCRIPTOR( log_name ); static DESCRIPTOR( comment_p, "COMMENT" ); static DYNAMIC_DESCRIPTOR( comment ); // get user input cli_get_value( &phy_name_p, &phy_name ); str_upcase( &phy_name, &phy_name ); cli_get_value( &log_name_p, &log_name ); str_upcase( &log_name, &log_name ); str_free1_dx(&comment); // per twf -- clear out comment field cli_get_value( &comment_p, &comment ); // check to see if db file exists if( check_for_file(CTS_DB_FILE) != SUCCESS ) { // does not exist, yet // try to creat (sic) it if( (fd = Creat(CTS_DB_FILE, 0666)) == ERROR ) { status = FAILURE; // FILE_ERROR; [2001.07.12] goto Assign_Exit; // we're done :< } else close(fd); } // check to see if db file is memory mapped if( CTSdbFileIsMapped == FALSE ) { // is not, so try if( map_data_file(CTS_DB) != SUCCESS ) { // we're dead in the water status = FAILURE; // MAP_ERROR; [2001.07.12] goto Assign_Exit; } } // get current db file count if( (numOfEntries = get_file_count(CTS_DB)) < 0 ) { status = FAILURE; // FILE_ERROR; [2001.07.12] goto Assign_Exit; } if( numOfEntries ) { // 1 or more if( lookup_entry(CTS_DB, log_name.pointer) >= 0 ) { // duplicate ! if( MSGLVL(IMPORTANT) ) fprintf( stderr, "duplicate module name '%s' -- not allowed\n", log_name.pointer ); status = FAILURE; // DUPLICATE; [2001.07.12] goto Assign_Exit; } } // get db file size if( (dbFileSize = get_db_file_size(CTS_DB_FILE)) == ERROR ) { status = FAILURE; // FILE_ERROR; [2001.07.12] goto Assign_Exit; } dbFileSize /= MODULE_ENTRY; // .. current maximum number of possible module entries // do we need to expand db file? if( (dbFileSize == 0) || (numOfEntries == dbFileSize) ) { // ... yes if( expand_db(CTS_DB, numOfEntries) != SUCCESS ) { // expand ... status = FAILURE; // EXPAND_ERROR; [2001.07.12] // ... failure goto Assign_Exit; } } // else OK // create a temporary string sprintf( line, "%-32s %-10s %-40s\n", log_name.pointer, // these were entered by the user phy_name.pointer, comment.pointer ? comment.pointer : "" ); // check comment field for null string, ie "(null)" nullMask = (1 << strlen(nullStr)) - 1; // set all mask bits for( i = COMMENT_INDEX; i < COMMENT_INDEX + strlen(nullStr); ++i ) if( line[i] == nullStr[i - COMMENT_INDEX] ) nullMask &= ~(1 << (i - COMMENT_INDEX)); // clear a bit in mask if( nullMask == 0 ) // all mask bit have been reset, ie matched for( i = COMMENT_INDEX; i < COMMENT_INDEX + strlen(nullStr); ++i ) line[i] = ' '; // make it spaces // add it ... if( add_entry(CTS_DB, line) != SUCCESS ) { status = FAILURE; // ASSIGN_ERROR; [2001.07.12] goto Assign_Exit; } #if NEED_WARM_N_FUZZY // write to a buffer file for a warm fuzzy ... if( (fd = Creat("buffer.db", 0666)) == ERROR ) { if( MSGLVL(ALWAYS) ) perror("creat()"); status = FAILURE; // FILE_ERROR; [2001.07.12] goto Assign_Exit; } rc = write(fd, line, sizeof(line)); close(fd); if( rc != sizeof(line) ) { if( MSGLVL(ALWAYS) ) perror("write()"); status = FAILURE; // FILE_ERROR; [2001.07.12] } #endif Assign_Exit: // we're done, so out'a here! if( MSGLVL(DETAILS) ) { printf("Assign(): "); ShowStatus(status); } return status; }
TVerdict CTestSyscalls::doTestStepL() { int err; if(TestStepName() == KCreat) { INFO_PRINTF1(_L("Creat():")); err = Creat(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kopen1) { INFO_PRINTF1(_L("open1():")); err = open1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kopen2) { INFO_PRINTF1(_L("open2():")); err = open2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kopen3) { INFO_PRINTF1(_L("open3():")); err = open3(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kopen4) { INFO_PRINTF1(_L("open4():")); err = open4(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kopen5) { INFO_PRINTF1(_L("open5():")); err = open5(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kopen6) { INFO_PRINTF1(_L("open6():")); err = open6(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KOpenTruncate1) { INFO_PRINTF1(_L("OpenTruncate1:")); err = OpenTruncate1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KOpenTruncate2) { INFO_PRINTF1(_L("OpenTruncate2:")); err = OpenTruncate2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kopen7) { INFO_PRINTF1(_L("open7():")); err = open7(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KOpenInAppendMode) { INFO_PRINTF1(_L("OpenInAppendMode():")); err = OpenInAppendMode(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kwrite1) { INFO_PRINTF1(_L("write1():")); err = write1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kwrite2) { INFO_PRINTF1(_L("write2():")); err = write2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kwrite3) { INFO_PRINTF1(_L("write3():")); err = write3(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kwrite5) { INFO_PRINTF1(_L("write5():")); err = write5(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kread1) { INFO_PRINTF1(_L("read1():")); err = read1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kread2) { INFO_PRINTF1(_L("read2():")); err = read2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kread3) { INFO_PRINTF1(_L("read3():")); err = read3(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kread4) { INFO_PRINTF1(_L("read4():")); err = read4(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KOpendir) { INFO_PRINTF1(_L("Opendir():")); err = Opendir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KClosedir) { INFO_PRINTF1(_L("Closedir():")); err = Closedir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KReaddir) { INFO_PRINTF1(_L("Readdir():")); err = Readdir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KLseek) { INFO_PRINTF1(_L("Lseek():")); err = Lseek(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KLseek1) { INFO_PRINTF1(_L("Lseek1():")); err = Lseek1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KAccess) { INFO_PRINTF1(_L("Access():")); err = Access(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KAccess1) { INFO_PRINTF1(_L("Access1():")); err = Access1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KDup) { INFO_PRINTF1(_L("Dup():")); err = Dup(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KDup2) { INFO_PRINTF1(_L("Dup2():")); err = Dup2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRename) { INFO_PRINTF1(_L("Rename():")); err = Rename(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRename1) { INFO_PRINTF1(_L("Rename1():")); err = Rename1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KChmod) { INFO_PRINTF1(_L("Chmod():")); err = Chmod(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KChmod1) { INFO_PRINTF1(_L("Chmod1():")); err = Chmod1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KChmod_dir) { INFO_PRINTF1(_L("Chmod_dir():")); err = Chmod_dir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KFChmod) { INFO_PRINTF1(_L("FChmod():")); err = FChmod(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KFChmod_dir) { INFO_PRINTF1(_L("FChmod_dir():")); err = FChmod_dir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KExit) { INFO_PRINTF1(_L("Exit():")); err = Exit(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KClose) { INFO_PRINTF1(_L("Close():")); err = Close(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KMkdir) { INFO_PRINTF1(_L("Mkdir():")); err = Mkdir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KMk_dir) { INFO_PRINTF1(_L("Mk_dir():")); err = Mk_dir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRmdir) { INFO_PRINTF1(_L("Rmdir():")); err = Rmdir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRm_dir) { INFO_PRINTF1(_L("Rm_dir():")); err = Rm_dir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRmdir1) { INFO_PRINTF1(_L("Rmdir1():")); err = Rmdir1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRmdir_Chdir) { INFO_PRINTF1(_L("Rmdir_Chdir():")); err = Rmdir_Chdir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KFsync) { INFO_PRINTF1(_L("Fsync():")); err = Fsync(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KUtimes) { INFO_PRINTF1(_L("Utimes():")); err = Utimes(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KUtime) { INFO_PRINTF1(_L("Utime():")); err = Utime(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KChdir) { INFO_PRINTF1(_L("Chdir():")); err = Chdir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KFcntl) { INFO_PRINTF1(_L("Fcntl():")); err = Fcntl(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KIoctl) { INFO_PRINTF1(_L("Ioctl():")); err = Ioctl(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KFstat) { INFO_PRINTF1(_L("Fstat():")); err = Fstat(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KStat) { INFO_PRINTF1(_L("Stat():")); err = Stat(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KStat1) { INFO_PRINTF1(_L("Stat1():")); err = Stat1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KStat2) { INFO_PRINTF1(_L("Stat2():")); err = Stat2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KStat3) { INFO_PRINTF1(_L("Stat3():")); err = Stat3(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KGetpid) { INFO_PRINTF1(_L("Getpid():")); err = Getpid(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KClock) { INFO_PRINTF1(_L("Clock():")); err = Clock(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KTime) { INFO_PRINTF1(_L("Time():")); err = Time(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KWaitPid) { INFO_PRINTF1(_L("WaitPid():")); err = WaitPid(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KReadV) { INFO_PRINTF1(_L("ReadV():")); err = ReadV(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KWriteV) { INFO_PRINTF1(_L("WriteV():")); err = WriteV(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KSleep) { INFO_PRINTF1(_L("Sleep():")); err = Sleep(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KSeekDir) { INFO_PRINTF1(_L("SeekDir():")); err = SeekDir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRewindDir) { INFO_PRINTF1(_L("RewindDir():")); err = RewindDir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KTelldir) { INFO_PRINTF1(_L("Telldir():")); err = Telldir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KTestClock) { INFO_PRINTF1(_L("TestClock():")); err = TestClock(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KCreat2) { INFO_PRINTF1(_L("Creat2():")); err = Creat2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kopen8) { INFO_PRINTF1(_L("open8():")); err = open8(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KTestStat) { INFO_PRINTF1(_L("KTestStat():")); err = TestStat(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KLseekttytest1) { INFO_PRINTF1(_L("Lseekttytest1():")); err = Lseekttytest1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KLseekttytest2) { INFO_PRINTF1(_L("Lseekttytest2():")); err = Lseekttytest2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KWaitPidtest) { INFO_PRINTF1(_L("WaitPidtest():")); err = WaitPidtest(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KWaittest) { INFO_PRINTF1(_L("Waittest():")); err = Waittest(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KOpen_FileDes_Test) { INFO_PRINTF1(_L("Open_FileDes_Test():")); err = Open_FileDes_Test(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kopenuid) { INFO_PRINTF1(_L("openuid():")); err = openuid(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KMkdir1) { INFO_PRINTF1(_L("Mkdir1():")); err = Mkdir1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KMkdir2) { INFO_PRINTF1(_L("Mkdir2():")); err = Mkdir2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRename2) { INFO_PRINTF1(_L("Rename2():")); err = Rename2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Ktestfsync) { INFO_PRINTF1(_L("testfsync():")); err = testfsync(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Ktestrename) { INFO_PRINTF1(_L("testrename():")); err = testrename(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Ktestopenvalidate) { INFO_PRINTF1(_L("testopenvalidate():")); err = testopenvalidate(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Ksync_safe) { INFO_PRINTF1(_L("sync_safe():")); err = sync_safe(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KFstat1) { INFO_PRINTF1(_L("Fstat1():")); err = Fstat1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KUtimes1) { INFO_PRINTF1(_L("Utimes1():")); err = Utimes1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KMkdir_test1) { INFO_PRINTF1(_L("Mkdir_test1():")); err = Mkdir_test1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KChmod_test) { INFO_PRINTF1(_L("Chmod_test():")); err = Chmod_test(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KChdir1) { INFO_PRINTF1(_L("Chdir1():")); err = Chdir1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRmdir2) { INFO_PRINTF1(_L("Rmdir2():")); err = Rmdir2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRename_test) { INFO_PRINTF1(_L("Rename_test():")); err = Rename_test(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRename3) { INFO_PRINTF1(_L("Rename3():")); err = Rename3(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KCreat1) { INFO_PRINTF1(_L("Creat1():")); err = Creat1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KReadV1) { INFO_PRINTF1(_L("ReadV1():")); err = ReadV1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KUtimes2) { INFO_PRINTF1(_L("Utimes2():")); err = Utimes2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KStat_test) { INFO_PRINTF1(_L("Stat_test():")); err = Stat_test(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KMkdir_test2) { INFO_PRINTF1(_L("Mkdir_test2():")); err = Mkdir_test2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KChmod2) { INFO_PRINTF1(_L("Chmod2():")); err = Chmod2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KChdir2) { INFO_PRINTF1(_L("Chdir2():")); err = Chdir2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRename4) { INFO_PRINTF1(_L("Rename4():")); err = Rename4(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRename5) { INFO_PRINTF1(_L("Rename5():")); err = Rename5(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRmdir3) { INFO_PRINTF1(_L("Rmdir3():")); err = Rmdir3(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kread5) { INFO_PRINTF1(_L("read5():")); err = read5(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } return TestStepResult(); }
void test25b() { /* Test normal operation. */ #define BUF_SIZE 1024 int fd1, fd2, fd3, fd4, fd5; char buf[BUF_SIZE]; struct stat st1, st2, st3; time_t time1, time2; int stat_loc; subtest = 2; System("rm -rf ../DIR_25/*"); System("echo Hello > he"); /* make test files */ System("echo Hello > ha"); /* size 6 bytes */ System("echo Hello > hi"); System("echo Hello > ho"); /* Check path resolution. Check if lowest fds are returned */ if ((fd1 = open("he", O_RDONLY)) != 3) e(1); if (read(fd1, buf, BUF_SIZE) != 6) e(2); if ((fd2 = open("./ha", O_RDONLY)) != 4) e(3); if ((fd3 = open("../DIR_25/he", O_RDWR)) != 5) e(4); if ((fd4 = open("ho", O_WRONLY)) != 6) e(5); if (close(fd4) != 0) e(6); if (close(fd1) != 0) e(7); if ((fd1 = open("./././ho", O_RDWR)) != 3) e(8); if ((fd4 = open("../DIR_25/he", O_RDONLY)) != 6) e(9); if (close(fd2) != 0) e(10); if (close(fd3) != 0) e(11); if ((fd2 = open("ha", O_RDONLY)) != 4) e(12); if ((fd3 = open("/etc/passwd", O_RDONLY)) != 5) e(13); if (close(fd4) != 0) e(14); /* close all */ if (close(fd1) != 0) e(15); if (close(fd3) != 0) e(16); /* Check if processes share fd2, and if they have independent new fds */ System("rm -rf /tmp/sema.25"); switch (fork()) { case -1: printf("Can't fork\n"); break; case 0: if ((fd1 = open("he", O_WRONLY)) != 3) e(17); if ((fd3 = open("../././DIR_25/ha", O_WRONLY)) != 5) e(18); if ((fd4 = open("../DIR_25/hi", O_WRONLY)) != 6) e(19); if ((fd5 = open("ho", O_WRONLY)) != 7) e(20); system("while test ! -f /tmp/sema.25; do sleep 1; done"); /* parent */ if (read(fd2, buf, BUF_SIZE) != 3) e(21); /* gets Hel */ if (strncmp(buf, "lo\n", 3) != 0) e(22); /* we get lo */ if (close(fd1) != 0) e(23); if (close(fd2) != 0) e(24); if (close(fd3) != 0) e(25); if (close(fd4) != 0) e(26); if (close(fd5) != 0) e(27); exit(0); default: if ((fd1 = open("ha", O_RDONLY)) != 3) e(28); if ((fd3 = open("./he", O_RDONLY)) != 5) e(29); if ((fd4 = open("../DIR_25/hi", O_RDWR)) != 6) e(30); if ((fd5 = open("ho", O_WRONLY)) != 7) e(31); if (close(fd1) != 0) e(32); if (read(fd2, buf, 3) != 3) e(33); /* get Hel */ Creat("/tmp/sema.25"); if (strncmp(buf, "Hel", 3) != 0) e(34); if (close(fd2) != 0) e(35); if (close(fd3) != 0) e(36); if (close(fd4) != 0) e(37); if (close(fd5) != 0) e(38); if (wait(&stat_loc) == -1) e(39); if (stat_loc != 0) e(40); } System("rm -f /tmp/sema.25"); /* Check if the file status information is updated correctly */ Stat("hi", &st1); /* get info */ Stat("ha", &st2); /* of files */ time(&time1); while (time1 >= time((time_t *)0)) ; /* wait a sec */ if ((fd1 = open("hi", O_RDONLY)) != 3) e(41); /* open files */ if ((fd2 = open("ha", O_WRONLY)) != 4) e(42); if (read(fd1, buf, 1) != 1) e(43); /* read one */ if (close(fd1) != 0) e(44); /* close one */ Stat("hi", &st3); /* get info */ if (st1.st_uid != st3.st_uid) e(45); if (st1.st_gid != st3.st_gid) e(46); /* should be same */ if (st1.st_mode != st3.st_mode) e(47); if (st1.st_size != st3.st_size) e(48); if (st1.st_nlink != st3.st_nlink) e(49); if (st1.st_mtime != st3.st_mtime) e(50); if (st1.st_ctime != st3.st_ctime) e(51); #ifndef V1_FILESYSTEM if (st1.st_atime >= st3.st_atime) e(52); /* except for atime. */ #endif if (write(fd2, "Howdy\n", 6) != 6) e(53); /* Update c & mtime. */ if ((fd1 = open("ha", O_RDWR)) != 3) e(54); if (read(fd1, buf, 6) != 6) e(55); /* Update atime. */ if (strncmp(buf, "Howdy\n", 6) != 0) e(56); if (close(fd1) != 0) e(57); Stat("ha", &st3); if (st2.st_uid != st3.st_uid) e(58); if (st2.st_gid != st3.st_gid) e(59); /* should be same */ if (st2.st_mode != st3.st_mode) e(60); if (st2.st_nlink != st3.st_nlink) e(61); if (st2.st_ctime >= st3.st_ctime) e(62); #ifndef V1_FILESYSTEM if (st2.st_atime >= st3.st_atime) e(63); #endif if (st2.st_mtime >= st3.st_mtime) e(64); if (st2.st_size != st3.st_size) e(65); if (close(fd2) != 0) e(66); /* Let's see if RDONLY files are read only. */ if ((fd1 = open("hi", O_RDONLY)) != 3) e(67); if (write(fd1, " again", 7) != -1) e(68); /* we can't write */ if (errno != EBADF) e(69); /* a read only fd */ if (read(fd1, buf, 7) != 6) e(70); /* but we can read */ if (close(fd1) != 0) e(71); /* Let's see if WRONLY files are write only. */ if ((fd1 = open("hi", O_WRONLY)) != 3) e(72); if (read(fd1, buf, 7) != -1) e(73); /* we can't read */ if (errno != EBADF) e(74); /* a write only fd */ if (write(fd1, "hELLO", 6) != 6) e(75); /* but we can write */ if (close(fd1) != 0) e(76); /* Let's see if files are closable only once. */ if (close(fd1) != -1) e(77); if (errno != EBADF) e(78); /* Let's see how calling close() with bad fds is handled. */ if (close(10) != -1) e(79); if (errno != EBADF) e(80); if (close(111) != -1) e(81); if (errno != EBADF) e(82); if (close(-432) != -1) e(83); if (errno != EBADF) e(84); /* Let's see if RDWR files are read & write able. */ if ((fd1 = open("hi", O_RDWR)) != 3) e(85); if (read(fd1, buf, 6) != 6) e(86); /* we can read */ if (strncmp(buf, "hELLO", 6) != 0) e(87); /* and we can write */ if (write(fd1, "Hello", 6) != 6) e(88); /* a read write fd */ if (close(fd1) != 0) e(89); /* Check if APPENDed files are realy appended */ if ((fd1 = open("hi", O_RDWR | O_APPEND)) != 3) e(90); /* open hi */ /* An open should set the file offset to 0. */ if (lseek(fd1, (off_t) 0, SEEK_CUR) != 0) e(91); /* Writing 0 bytes should not have an effect. */ if (write(fd1, "", 0) != 0) e(92); if (lseek(fd1, (off_t) 0, SEEK_CUR) != 0) e(93); /* the end? */ /* A seek befor a wirte should not matter with O_APPEND. */ Stat("hi", &st1); if (lseek(fd1, (off_t) - 3, SEEK_END) != st1.st_size - 3) e(94); /* By writing 1 byte, we force the offset to the end of the file */ if (write(fd1, "1", 1) != 1) e(95); Stat("hi", &st1); if (lseek(fd1, (off_t) 0, SEEK_CUR) != st1.st_size) e(96); if (write(fd1, "2", 1) != 1) e(97); Stat("hi", &st1); if (lseek(fd1, (off_t) 0, SEEK_CUR) != st1.st_size) e(98); if (write(fd1, "3", 1) != 1) e(99); Stat("hi", &st1); if (lseek(fd1, (off_t) 0, SEEK_CUR) != st1.st_size) e(100); if (lseek(fd1, (off_t) - 2, SEEK_CUR) <= 0) e(101); if (write(fd1, "4", 1) != 1) e(102); /* Since the mode was O_APPEND, the offset should be reset to EOF */ Stat("hi", &st1); if (lseek(fd1, (off_t) 0, SEEK_CUR) != st1.st_size) e(103); if (lseek(fd1, (off_t) - 4, SEEK_CUR) != st1.st_size - 4) e(104); if (read(fd1, buf, BUF_SIZE) != 4) e(105); if (strncmp(buf, "1234", 4) != 0) e(106); if (close(fd1) != 0) e(107); /* Check the effect of O_CREAT */ Stat("ho", &st1); fd1 = open("ho", O_RDWR | O_CREAT, 0000); if (fd1 != 3) e(108); Stat("ho", &st2); if (memcmp(&st1, &st2, sizeof(struct stat)) != 0) e(109); if (read(fd1, buf, 6) != 6) e(110); if (strncmp(buf, "Hello\n", 6) != 0) e(111); if (write(fd1, "@", 1) != 1) e(112); if (close(fd1) != 0) e(113); (void) umask(0000); fd1 = open("ho", O_RDWR | O_CREAT | O_EXCL, 0777); if (fd1 != -1) e(114); /* ho exists */ System("rm -rf new"); time(&time1); while (time1 >= time((time_t *)0)) ; fd1 = open("new", O_RDWR | O_CREAT, 0716); if (fd1 != 3) e(115); /* new file */ Stat("new", &st1); time(&time2); while (time2 >= time((time_t *)0)) ; time(&time2); if (st1.st_uid != geteuid()) e(116); /* try this as superuser. */ if (st1.st_gid != getegid()) e(117); if ((st1.st_mode & 0777) != 0716) e(118); if (st1.st_nlink != 1) e(119); if (st1.st_mtime <= time1) e(120); if (st1.st_mtime >= time2) e(121); #ifndef V1_FILESYSTEM if (st1.st_atime != st1.st_mtime) e(122); #endif if (st1.st_ctime != st1.st_mtime) e(123); if (st1.st_size != 0) e(124); if (write(fd1, "I'm new in town", 16) != 16) e(125); if (lseek(fd1, (off_t) - 5, SEEK_CUR) != 11) e(126); if (read(fd1, buf, 5) != 5) e(127); if (strncmp(buf, "town", 5) != 0) e(128); if (close(fd1) != 0) e(129); /* Let's test the O_TRUNC flag on this new file. */ time(&time1); while (time1 >= time((time_t *)0)); if ((fd1 = open("new", O_RDWR | O_TRUNC)) != 3) e(130); Stat("new", &st1); time(&time2); while (time2 >= time((time_t *)0)); time(&time2); if ((st1.st_mode & 0777) != 0716) e(131); if (st1.st_size != (size_t) 0) e(132); /* TRUNCed ? */ if (st1.st_mtime <= time1) e(133); if (st1.st_mtime >= time2) e(134); if (st1.st_ctime != st1.st_mtime) e(135); if (close(fd1) != 0) e(136); /* Test if file permission bits and the file ownership are unchanged. */ /* So we will see if `O_CREAT' has no effect if the file exists. */ if (superuser) { System("echo > bar; chmod 077 bar"); /* Make bar 077 */ System("chown daemon bar"); System("chgrp daemon bar"); /* Daemon's bar */ fd1 = open("bar", O_RDWR | O_CREAT | O_TRUNC, 0777); /* knock knock */ if (fd1 == -1) e(137); if (write(fd1, "foo", 3) != 3) e(138); /* rewrite bar */ if (close(fd1) != 0) e(139); Stat("bar", &st1); if (st1.st_uid != 1) e(140); /* bar is still */ if (st1.st_gid != 1) e(141); /* owned by daemon */ if ((st1.st_mode & 0777) != 077) e(142); /* mode still is 077 */ if (st1.st_size != (size_t) 3) e(143); /* 3 bytes long */ /* We do the whole thing again, but with O_WRONLY */ fd1 = open("bar", O_WRONLY | O_CREAT | O_TRUNC, 0777); if (fd1 == -1) e(144); if (write(fd1, "foobar", 6) != 6) e(145); /* rewrite bar */ if (close(fd1) != 0) e(146); Stat("bar", &st1); if (st1.st_uid != 1) e(147); /* bar is still */ if (st1.st_gid != 1) e(148); /* owned by daemon */ if ((st1.st_mode & 0777) != 077) e(149); /* mode still is 077 */ if (st1.st_size != (size_t) 6) e(150); /* 6 bytes long */ } }
void test25c() { /* Test normal operation Part two. */ int fd1, fd2; char buf[BUF_SIZE]; struct stat st; int stat_loc; static int iteration=0; subtest = 3; iteration++; System("rm -rf ../DIR_25/*"); /* Fifo file test here. */ if (mkfifo("fifo", 0777) != 0) e(1); switch (fork()) { case -1: printf("Can't fork\n"); break; case 0: alarm(20); /* Give child 20 seconds to live. */ if ((fd1 = open("fifo", O_RDONLY)) != 3) e(2); if (read(fd1, buf, BUF_SIZE) != 23) e(3); if (strncmp(buf, "1 2 3 testing testing\n", 23) != 0) e(4); if (close(fd1) != 0) e(5); exit(0); default: if ((fd1 = open("fifo", O_WRONLY)) != 3) e(6); if (write(fd1, "1 2 3 testing testing\n", 23) != 23) e(7); if (close(fd1) != 0) e(8); if (wait(&stat_loc) == -1) e(9); if (stat_loc != 0) e(10); /* The alarm went off? */ } /* Try opening for writing with O_NONBLOCK. */ fd1 = open("fifo", O_WRONLY | O_NONBLOCK); if (fd1 != -1) e(11); if (errno != ENXIO) e(12); close(fd1); /* Try opening for writing with O_NONBLOCK and O_CREAT. */ fd1 = open("fifo", O_WRONLY | O_CREAT | O_NONBLOCK, 0777); if (fd1 != -1) e(13); if (errno != ENXIO) e(14); close(fd1); /* Both the NONBLOCK and the EXCLusive give raise to error. */ fd1 = open("fifo", O_WRONLY | O_CREAT | O_EXCL | O_NONBLOCK, 0777); if (fd1 != -1) e(15); if (errno != EEXIST && errno != ENXIO) e(16); close(fd1); /* Just in case. */ /* Try opening for reading with O_NONBLOCK. */ fd1 = open("fifo", O_RDONLY | O_NONBLOCK); if (fd1 != 3) e(17); if (close(fd1) != 0) e(18); /* Nopt runs out of memory. ;-< We just cut out some valid code */ /* FIFO's should always append. (They have no file position.) */ switch (fork()) { case -1: printf("Can't fork\n"); break; case 0: alarm(20); /* Give child 20 seconds to live. */ if ((fd1 = open("fifo", O_WRONLY)) != 3) e(19); if ((fd2 = open("fifo", O_WRONLY)) != 4) e(20); if (write(fd1, "I did see Elvis.\n", 18) != 18) e(21); if (write(fd2, "I DID.\n", 8) != 8) e(22); if (close(fd2) != 0) e(23); if (close(fd1) != 0) e(24); exit(0); default: if ((fd1 = open("fifo", O_RDONLY)) != 3) e(25); if (read(fd1, buf, 18) != 18) e(26); if (strncmp(buf, "I did see Elvis.\n", 18) != 0) e(27); if (read(fd1, buf, BUF_SIZE) != 8) e(28); if (strncmp(buf, "I DID.\n", 8) != 0) e(29); if (close(fd1) != 0) e(30); if (wait(&stat_loc) == -1) e(31); if (stat_loc != 0) e(32); /* The alarm went off? */ } /* O_TRUNC should have no effect on FIFO files. */ switch (fork()) { case -1: printf("Can't fork\n"); break; case 0: alarm(20); /* Give child 20 seconds to live. */ if ((fd1 = open("fifo", O_WRONLY)) != 3) e(33); if (write(fd1, "I did see Elvis.\n", 18) != 18) e(34); if ((fd2 = open("fifo", O_WRONLY | O_TRUNC)) != 4) e(35); if (write(fd2, "I DID.\n", 8) != 8) e(36); if (close(fd2) != 0) e(37); if (close(fd1) != 0) e(38); exit(0); default: if ((fd1 = open("fifo", O_RDONLY)) != 3) e(39); if (read(fd1, buf, 18) != 18) e(40); if (strncmp(buf, "I did see Elvis.\n", 18) != 0) e(41); if (read(fd1, buf, BUF_SIZE) != 8) e(42); if (strncmp(buf, "I DID.\n", 8) != 0) e(43); if (close(fd1) != 0) e(44); if (wait(&stat_loc) == -1) e(45); if (stat_loc != 0) e(46); /* The alarm went off? */ } /* Closing the last fd should flush all data to the bitbucket. */ System("rm -rf /tmp/sema.25"); switch (fork()) { case -1: printf("Can't fork\n"); break; case 0: alarm(20); /* Give child 20 seconds to live. */ if ((fd1 = open("fifo", O_WRONLY)) != 3) e(47); if (write(fd1, "I did see Elvis.\n", 18) != 18) e(48); Creat("/tmp/sema.25"); sleep(2); /* give parent a chance to open */ /* this was sleep(1), but that's too short: child also sleeps(1) */ if (close(fd1) != 0) e(49); exit(0); default: if ((fd1 = open("fifo", O_RDONLY)) != 3) e(50); /* Make `sure' write has closed. */ while (stat("/tmp/sema.25", &st) != 0) sleep(1); if (close(fd1) != 0) e(51); if ((fd1 = open("fifo", O_RDONLY | O_NONBLOCK)) != 3) e(52); if (read(fd1, buf, BUF_SIZE) != 18) e(53); if (close(fd1) != 0) e(54); if (wait(&stat_loc) == -1) e(55); if (stat_loc != 0) e(56); /* The alarm went off? */ } /* Let's try one too many. */ System("rm -rf /tmp/sema.25"); switch (fork()) { case -1: printf("Can't fork\n"); break; case 0: alarm(20); /* Give child 20 seconds to live. */ if ((fd1 = open("fifo", O_WRONLY)) != 3) e(57); if (write(fd1, "I did see Elvis.\n", 18) != 18) e(58); /* Keep open till third reader is opened. */ while (stat("/tmp/sema.25", &st) != 0) sleep(1); if (close(fd1) != 0) e(59); exit(0); default: if ((fd1 = open("fifo", O_RDONLY)) != 3) e(60); if (read(fd1, buf, 2) != 2) e(61); if (strncmp(buf, "I ", 2) != 0) e(62); if (close(fd1) != 0) e(63); if ((fd1 = open("fifo", O_RDONLY)) != 3) e(64); if (read(fd1, buf, 4) != 4) e(65); if (strncmp(buf, "did ", 4) != 0) e(66); if ((fd2 = open("fifo", O_RDONLY)) != 4) e(67); /* Signal third reader is open. */ Creat("/tmp/sema.25"); if (read(fd2, buf, BUF_SIZE) != 12) e(68); if (strncmp(buf, "see Elvis.\n", 12) != 0) e(69); if (close(fd2) != 0) e(70); if (close(fd1) != 0) e(71); if (wait(&stat_loc) == -1) e(72); if (stat_loc != 0) e(73); /* The alarm went off? */ } System("rm -rf fifo /tmp/sema.25"); /* O_TRUNC should have no effect on directroys. */ System("mkdir dir; touch dir/f1 dir/f2 dir/f3"); if ((fd1 = open("dir", O_WRONLY | O_TRUNC)) != -1) e(74); if (errno != EISDIR) e(75); close(fd1); /* Opening a directory for reading should be possible. */ if ((fd1 = open("dir", O_RDONLY)) != 3) e(76); if (close(fd1) != 0) e(77); if (unlink("dir/f1") != 0) e(78); /* Should still be there. */ if (unlink("dir/f2") != 0) e(79); if (unlink("dir/f3") != 0) e(80); if (rmdir("dir") != 0) e(81); if (!superuser) { /* Test if O_CREAT is not usable to open files with the wrong mode */ (void) umask(0200); /* nono has no */ System("touch nono"); /* write bit */ (void) umask(0000); fd1 = open("nono", O_RDWR | O_CREAT, 0777); /* try to open */ if (fd1 != -1) e(82); if (errno != EACCES) e(83); /* but no access */ } }
//------------------------------------------------------------------------- // Add a crate to the crate db //------------------------------------------------------------------------- int AddCrate() { char line[CRATE_ENTRY + 1]; int dbFileSize, fd, numOfEntries; int status = SUCCESS; // assume the best static DESCRIPTOR( phy_name_p, "PHY_NAME" ); static DYNAMIC_DESCRIPTOR( phy_name ); // get user input str_free1_dx(&phy_name); // per twf -- clear out field cli_get_value( &phy_name_p, &phy_name ); str_upcase( &phy_name, &phy_name ); // [2002.01.08] if( CRATEdbFileIsMapped == FALSE ) { // ... no if( check_for_file(CRATE_DB_FILE) != SUCCESS ) { // ... no if( (fd = Creat(CRATE_DB_FILE, 0666)) == ERROR ) { // no status = FAILURE; goto AddCrate_Exit; } else close(fd); // yes } if( map_data_file(CRATE_DB) != SUCCESS ) { // failure :( status = MAP_ERROR; goto AddCrate_Exit; } // else OK :) } // get current db file count if( (numOfEntries = get_file_count(CRATE_DB)) == FILE_ERROR ) { status = FAILURE; // FILE_ERROR; [2001.07.12] goto AddCrate_Exit; } if( numOfEntries ) { // 1 or more char pname[7]; sprintf(pname,"%.6s",phy_name.pointer); if( lookup_entry(CRATE_DB, pname) >= 0 ) { // duplicate ! if( MSGLVL(IMPORTANT) ) fprintf( stderr, "duplicate crate name '%.6s' -- not allowed\n", phy_name.pointer ); status = FAILURE; // DUPLICATE; [2001.07.12] goto AddCrate_Exit; } } // get db file size if( (dbFileSize = get_db_file_size(CRATE_DB_FILE)) == ERROR ) { status = FAILURE; // FILE_ERROR; [2001.07.12] goto AddCrate_Exit; } dbFileSize /= CRATE_ENTRY; // .. current maximum number of possible crate entries // do we need to expand db file? if( (dbFileSize == 0) || (numOfEntries == dbFileSize) ) { // ... yes if( (status = expand_db(CRATE_DB, numOfEntries)) != SUCCESS ) { // expand status = FAILURE; // EXPAND_ERROR; [2001.07.12] // failure goto AddCrate_Exit; } } // else OK // make an entry line, with online and enhanced set as undefined sprintf( line, "%-.6s:...:.:.:.\n", phy_name.pointer ); // add it ... if( (status = add_entry(CRATE_DB, line)) != SUCCESS ) { status = FAILURE; // ASSIGN_ERROR; [2001.07.12] goto AddCrate_Exit; } AddCrate_Exit: if( MSGLVL(DETAILS) ) { printf("AddCrate(): "); ShowStatus(status); } if( status == SUCCESS ) // if everything is OK ... Autoconfig(); // ... map crate to /dev/sg# //ShowCrate(); return status; }
int main() { Graph m; Creat(m); return 0; }
void test32c() { /* Test behavior under error contitions. */ struct stat st1; int stat_loc; subtest = 3; System("rm -rf ../DIR_32/*"); /* Test if we have access. */ system("chmod 777 noacc nowrite > /dev/null 2>/dev/null"); system("rm -rf noacc nowrite"); System("mkdir noacc nowrite"); System("> noacc/file"); System("> nowrite/file"); System("> file"); System("chmod 677 noacc"); System("chmod 577 nowrite"); if (!superuser) { if (rename("noacc/file", "nono") != -1) e(1); if (errno != EACCES) e(2); if (rename("nowrite/file", "nono") != -1) e(3); if (errno != EACCES) e(4); if (rename("file", "noacc/file") != -1) e(5); if (errno != EACCES) e(6); if (rename("file", "nowrite/file") != -1) e(7); if (errno != EACCES) e(8); } if (superuser) { /* Super user heeft access. */ if (rename("noacc/file", "noacc/yes") != 0) e(9); if (rename("nowrite/file", "nowrite/yes") != 0) e(10); if (rename("file", "yes") != 0) e(11); if (rename("noacc/yes", "noacc/file") != 0) e(12); if (rename("nowrite/yes", "nowrite/file") != 0) e(13); if (rename("yes", "file") != 0) e(14); } System("chmod 777 noacc nowrite"); /* If rmdir() doesn't remove a directory, rename() shouldn't eighter. */ System("mkdir newdir olddir"); System("rm -rf /tmp/sema.11[ab]"); switch (fork()) { case -1: printf("Can't fork\n"); break; case 0: alarm(20); switch (fork()) { case -1: printf("Can't fork\n"); break; case 0: /* Child A. */ alarm(20); if (chdir("newdir") != 0) e(15); Creat("/tmp/sema.11a"); while (stat("/tmp/sema.11a", &st1) == 0) sleep(1); exit(0); default: wait(&stat_loc); if (stat_loc != 0) e(16); /* Alarm? */ } /* Child B. */ if (chdir("olddir") != 0) e(17); Creat("/tmp/sema.11b"); while (stat("/tmp/sema.11b", &st1) == 0) sleep(1); exit(0); default: /* Wait for child A. It will keep ``newdir'' bussy. */ while (stat("/tmp/sema.11a", &st1) == -1) sleep(1); if (rmdir("newdir") == -1) { if (rename("olddir", "newdir") != -1) e(18); if (errno != EBUSY) e(19); } (void) unlink("/tmp/sema.11a"); /* Wait for child B. It will keep ``olddir'' bussy. */ while (stat("/tmp/sema.11b", &st1) == -1) sleep(1); if (rmdir("olddir") == -1) { if (rename("olddir", "newdir") != -1) e(20); if (errno != EBUSY) e(21); } (void) unlink("/tmp/sema.11b"); wait(&stat_loc); if (stat_loc != 0) e(22); /* Alarm? */ } }
void test35c() { gid_t gid, gid2; uid_t uid, uid2; struct utimbuf ub; int fd, does_truncate, stat_loc; subtest = 3; /* Access problems. */ Mkdir("bar"); Creat("bar/tryme"); if (superuser) { Chmod("bar", 0000); /* No search permisson at all. */ if (utime("bar/tryme", NULL) != 0) e(1); } if (!superuser) { Chmod("bar", 0677); /* No search permisson. */ if (utime("bar/tryme", NULL) != -1) e(2); if (errno != EACCES) e(3); } Chmod("bar", 0777); if (I_can_chown) { switch (fork()) { case -1: printf("Can't fork\n"); break; case 0: alarm(20); /* Get two differend non root uids. */ if (superuser) { getids(&uid, &gid); if (uid == 0) getids(&uid, &gid); if (uid == 0) e(4); } if (!superuser) { uid = geteuid(); gid = getegid(); } getids(&uid2, &gid); if (uid == uid2) getids(&uid2, &gid2); if (uid == uid2) e(5); /* Creat a number of files for root, user and user2. */ Creat("rootfile"); /* Owned by root. */ Chmod("rootfile", 0600); Chown("rootfile", 0, 0); Creat("user2file"); /* Owned by user 2, writeable. */ Chmod("user2file", 0020); Chown("user2file", uid2, gid); Creat("user2private"); /* Owned by user 2, privately. */ Chmod("user2private", 0600); Chown("user2private", uid2, gid); if (superuser) { setgid(gid); setuid(uid); } /* We now are user ``uid'' from group ``gid''. */ ub.actime = (time_t) 12345L; ub.modtime = (time_t) 12345L; if (utime("rootfile", NULL) != -1) e(6); if (errno != EACCES) e(7); if (utime("rootfile", &ub) != -1) e(8); if (errno != EPERM) e(9); if (utime("user2file", NULL) != 0) e(10); if (utime("user2file", &ub) != -1) e(11); if (errno != EPERM) e(12); if (utime("user2private", NULL) != -1) e(13); if (errno != EACCES) e(14); if (utime("user2private", &ub) != -1) e(15); if (errno != EPERM) e(16); exit(errct ? 1 : 0); default: wait(&stat_loc); if (stat_loc != 0) e(17); /* Alarm? */ } } /* Test names that are too long. */ does_truncate = does_fs_truncate(); fd = creat(NameTooLong, 0777); if (does_truncate) { if (utime(NameTooLong, NULL) != 0) e(18); } else { if (utime(NameTooLong, NULL) != -1) e(19); if (errno != ENAMETOOLONG) e(20); } (void) close(fd); /* Make PathTooLong contain ././.../a */ PathTooLong[strlen(PathTooLong) - 2] = '/'; PathTooLong[strlen(PathTooLong) - 1] = 'a'; Creat("a"); if (utime(PathTooLong, NULL) != -1) e(21); if (errno != ENAMETOOLONG) e(22); /* Non existing file name. */ if (utime("nonexist", NULL) != -1) e(23); if (errno != ENOENT) e(24); /* Empty file name. */ if (utime("", NULL) != -1) e(25); if (errno != ENOENT) e(26); System("rm -rf ../DIR_35/*"); }
void test35a() { /* Test normal operation. */ struct stat st; struct utimbuf ub; time_t time1, time2; int cnt; subtest = 1; /* Creat scratch file. */ Creat("foo"); /* Set file times back two seconds. */ Stat("foo", &st); ub.actime = st.st_atime - 2; ub.modtime = st.st_mtime - 2; Time(&time1); utime("foo", &ub); Time(&time2); Stat("foo", &st); if (ub.actime != st.st_atime) e(1); if (ub.modtime != st.st_mtime) e(2); /* The status changed time sould be changed. */ #ifndef V1_FILESYSTEM if (st.st_ctime < time1) e(3); #endif if (st.st_ctime > time2) e(4); /* Add twenty seconds. */ Stat("foo", &st); ub.actime = st.st_atime + 20; ub.modtime = st.st_mtime + 20; Time(&time1); utime("foo", &ub); Time(&time2); Stat("foo", &st); if (ub.actime != st.st_atime) e(5); if (ub.modtime != st.st_mtime) e(6); if (st.st_ctime < time1) e(7); #ifndef V1_FILESYSTEM if (st.st_ctime > time2) e(8); #endif /* Try 100 times to do utime in less than one second. */ cnt = 0; do { Time(&time1); utime("foo", (struct utimbuf *) NULL); Time(&time2); } while (time1 != time2 && cnt++ < 100); if (time1 == time2) { Stat("foo", &st); Time(&time2); if (st.st_atime != time1) e(9); if (st.st_mtime != time1) e(10); } else { Stat("foo", &st); if (st.st_atime > time2) e(11); if (st.st_mtime > time2) e(12); Time(&time2); if (st.st_atime < time1) e(13); if (st.st_mtime < time1) e(14); } if (st.st_ctime < time1) e(15); if (st.st_ctime > time2) e(16); System("rm -rf ../DIR_35/*"); }
int main() { int i,j; position p; LIST L; L=new mylist; p=new mylist; printf("what do you want,1-creat,2-insert,3-deleat,4-next,5-retrieve,6-makenull,7-printf,8-locate,0-exit\n"); while(scanf("%d",&j)) { if(j==1) Creat(L); if(j==2) {printf("which position do you want to in,and what number\n"); scanf("%d %d",&p,&i); Insert(i,p); } if(j==3) { printf("which position do you want to deleat\n"); scanf("%d %d",&p,&i); Delete(p); } if(j==4) { printf("which next\n"); scanf("%d",&p); p=Next(p,L); printf("the next is %d\n",p->n); } if(j==5) { printf("which do you retrieve\n"); scanf("%d",&p); printf("the element is %d\n",Retrieve(p,L)); } if(j==6) { MakeNull(L); } if(j==7) { Prin(L); } if(j==8) { printf("which do you locate\n"); scanf("%d",&i); p=Locate(i,L); if(p) { printf("%d",p->next->n); } else printf("no find"); } if(j==0) return 0; } }