static int local_ptsname_r(int fd, char* buf, size_t maxlen) { char* ptr; size_t n; // FIXME lock! if ((ptr = ptrname(fd)) == NULL) { DEBUGF("ptsname failed : %s", strerror(errno)); return -1; } if ((n=strlen(ptr)) >= maxlen) { errno = ERANGE; return -1; } memcpy(buf, ptr, n); buf[n] = '\0'; return 0; }
void VfsCreateDeleteOnCloseFileOomTest() { sqlite3_vfs* vfs = sqlite3_vfs_find(NULL); TEST(vfs != NULL); sqlite3_file* osFile = (sqlite3_file*)User::Alloc(vfs->szOsFile); TEST(osFile != NULL); TheTest.Printf(_L("Iteration: ")); TInt failingAllocNum = 0; TInt err = SQLITE_IOERR_NOMEM; while(err == SQLITE_IOERR_NOMEM) { ++failingAllocNum; TheTest.Printf(_L("%d "), failingAllocNum); OomPreStep(failingAllocNum); int outFlags = 0; err = sqlite3OsOpen(vfs, KTestFile4Z, osFile, SQLITE_OPEN_CREATE | SQLITE_OPEN_DELETEONCLOSE, &outFlags); if(err == SQLITE_OK) { err = sqlite3OsClose(osFile); } OomPostStep(); if(err != SQLITE_OK) { TEST2(err, SQLITE_IOERR_NOMEM); } //Whether the iteration has failed or succeeded, the file should not exist. TPtrC8 ptrname((const TUint8*)KTestFile4Z); TBuf<50> fname; fname.Copy(ptrname); TInt err2 = TheFs.Delete(fname); TEST2(err2, KErrNotFound); } TEST2(err, SQLITE_OK); TheTest.Printf(_L("\r\n=== TVfs::Open(<delete on close file>) OOM test succeeded at allcoation %d\r\n"), failingAllocNum); User::Free(osFile); }