⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 os_os2.c

📁 最新的sqlite3.6.2源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
  int flags,                    /* Open mode flags */  int *pOutFlags                /* Status return flags */){  HFILE h;  ULONG ulFileAttribute = FILE_NORMAL;  ULONG ulOpenFlags = 0;  ULONG ulOpenMode = 0;  os2File *pFile = (os2File*)id;  APIRET rc = NO_ERROR;  ULONG ulAction;  char *zNameCp;  char zTmpname[CCHMAXPATH+1];    /* Buffer to hold name of temp file */  /* If the second argument to this function is NULL, generate a   ** temporary file name to use   */  if( !zName ){    int rc = getTempname(CCHMAXPATH+1, zTmpname);    if( rc!=SQLITE_OK ){      return rc;    }    zName = zTmpname;  }  memset( pFile, 0, sizeof(*pFile) );  OSTRACE2( "OPEN want %d\n", flags );  if( flags & SQLITE_OPEN_READWRITE ){    ulOpenMode |= OPEN_ACCESS_READWRITE;    OSTRACE1( "OPEN read/write\n" );  }else{    ulOpenMode |= OPEN_ACCESS_READONLY;    OSTRACE1( "OPEN read only\n" );  }  if( flags & SQLITE_OPEN_CREATE ){    ulOpenFlags |= OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_CREATE_IF_NEW;    OSTRACE1( "OPEN open new/create\n" );  }else{    ulOpenFlags |= OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_FAIL_IF_NEW;    OSTRACE1( "OPEN open existing\n" );  }  if( flags & SQLITE_OPEN_MAIN_DB ){    ulOpenMode |= OPEN_SHARE_DENYNONE;    OSTRACE1( "OPEN share read/write\n" );  }else{    ulOpenMode |= OPEN_SHARE_DENYWRITE;    OSTRACE1( "OPEN share read only\n" );  }  if( flags & SQLITE_OPEN_DELETEONCLOSE ){    char pathUtf8[CCHMAXPATH];#ifdef NDEBUG /* when debugging we want to make sure it is deleted */    ulFileAttribute = FILE_HIDDEN;#endif    os2FullPathname( pVfs, zName, CCHMAXPATH, pathUtf8 );    pFile->pathToDel = convertUtf8PathToCp( pathUtf8 );    OSTRACE1( "OPEN hidden/delete on close file attributes\n" );  }else{    pFile->pathToDel = NULL;    OSTRACE1( "OPEN normal file attribute\n" );  }  /* always open in random access mode for possibly better speed */  ulOpenMode |= OPEN_FLAGS_RANDOM;  ulOpenMode |= OPEN_FLAGS_FAIL_ON_ERROR;  ulOpenMode |= OPEN_FLAGS_NOINHERIT;  zNameCp = convertUtf8PathToCp( zName );  rc = DosOpen( (PSZ)zNameCp,                &h,                &ulAction,                0L,                ulFileAttribute,                ulOpenFlags,                ulOpenMode,                (PEAOP2)NULL );  free( zNameCp );  if( rc != NO_ERROR ){    OSTRACE7( "OPEN Invalid handle rc=%d: zName=%s, ulAction=%#lx, ulAttr=%#lx, ulFlags=%#lx, ulMode=%#lx\n",              rc, zName, ulAction, ulFileAttribute, ulOpenFlags, ulOpenMode );    if( pFile->pathToDel )      free( pFile->pathToDel );    pFile->pathToDel = NULL;    if( flags & SQLITE_OPEN_READWRITE ){      OSTRACE2( "OPEN %d Invalid handle\n", ((flags | SQLITE_OPEN_READONLY) & ~SQLITE_OPEN_READWRITE) );      return os2Open( pVfs, zName, id,                      ((flags | SQLITE_OPEN_READONLY) & ~SQLITE_OPEN_READWRITE),                      pOutFlags );    }else{      return SQLITE_CANTOPEN;    }  }  if( pOutFlags ){    *pOutFlags = flags & SQLITE_OPEN_READWRITE ? SQLITE_OPEN_READWRITE : SQLITE_OPEN_READONLY;  }  pFile->pMethod = &os2IoMethod;  pFile->h = h;  OpenCounter(+1);  OSTRACE3( "OPEN %d pOutFlags=%d\n", pFile->h, pOutFlags );  return SQLITE_OK;}/*** Delete the named file.*/static int os2Delete(  sqlite3_vfs *pVfs,                     /* Not used on os2 */  const char *zFilename,                 /* Name of file to delete */  int syncDir                            /* Not used on os2 */){  APIRET rc = NO_ERROR;  char *zFilenameCp = convertUtf8PathToCp( zFilename );  SimulateIOError( return SQLITE_IOERR_DELETE );  rc = DosDelete( (PSZ)zFilenameCp );  free( zFilenameCp );  OSTRACE2( "DELETE \"%s\"\n", zFilename );  return rc == NO_ERROR ? SQLITE_OK : SQLITE_IOERR;}/*** Check the existance and status of a file.*/static int os2Access(  sqlite3_vfs *pVfs,        /* Not used on os2 */  const char *zFilename,    /* Name of file to check */  int flags,                /* Type of test to make on this file */  int *pOut                 /* Write results here */){  FILESTATUS3 fsts3ConfigInfo;  APIRET rc = NO_ERROR;  char *zFilenameCp = convertUtf8PathToCp( zFilename );  memset( &fsts3ConfigInfo, 0, sizeof(fsts3ConfigInfo) );  rc = DosQueryPathInfo( (PSZ)zFilenameCp, FIL_STANDARD,                         &fsts3ConfigInfo, sizeof(FILESTATUS3) );  free( zFilenameCp );  OSTRACE4( "ACCESS fsts3ConfigInfo.attrFile=%d flags=%d rc=%d\n",            fsts3ConfigInfo.attrFile, flags, rc );  switch( flags ){    case SQLITE_ACCESS_READ:    case SQLITE_ACCESS_EXISTS:      rc = (rc == NO_ERROR);      OSTRACE3( "ACCESS %s access of read and exists  rc=%d\n", zFilename, rc );      break;    case SQLITE_ACCESS_READWRITE:      rc = (rc == NO_ERROR) && ( (fsts3ConfigInfo.attrFile & FILE_READONLY) == 0 );      OSTRACE3( "ACCESS %s access of read/write  rc=%d\n", zFilename, rc );      break;    default:      assert( !"Invalid flags argument" );  }  *pOut = rc;  return SQLITE_OK;}#ifndef SQLITE_OMIT_LOAD_EXTENSION/*** Interfaces for opening a shared library, finding entry points** within the shared library, and closing the shared library.*//*** Interfaces for opening a shared library, finding entry points** within the shared library, and closing the shared library.*/static void *os2DlOpen(sqlite3_vfs *pVfs, const char *zFilename){  UCHAR loadErr[256];  HMODULE hmod;  APIRET rc;  char *zFilenameCp = convertUtf8PathToCp(zFilename);  rc = DosLoadModule((PSZ)loadErr, sizeof(loadErr), zFilenameCp, &hmod);  free(zFilenameCp);  return rc != NO_ERROR ? 0 : (void*)hmod;}/*** A no-op since the error code is returned on the DosLoadModule call.** os2Dlopen returns zero if DosLoadModule is not successful.*/static void os2DlError(sqlite3_vfs *pVfs, int nBuf, char *zBufOut){/* no-op */}static void *os2DlSym(sqlite3_vfs *pVfs, void *pHandle, const char *zSymbol){  PFN pfn;  APIRET rc;  rc = DosQueryProcAddr((HMODULE)pHandle, 0L, zSymbol, &pfn);  if( rc != NO_ERROR ){    /* if the symbol itself was not found, search again for the same     * symbol with an extra underscore, that might be needed depending     * on the calling convention */    char _zSymbol[256] = "_";    strncat(_zSymbol, zSymbol, 255);    rc = DosQueryProcAddr((HMODULE)pHandle, 0L, _zSymbol, &pfn);  }  return rc != NO_ERROR ? 0 : (void*)pfn;}static void os2DlClose(sqlite3_vfs *pVfs, void *pHandle){  DosFreeModule((HMODULE)pHandle);}#else /* if SQLITE_OMIT_LOAD_EXTENSION is defined: */  #define os2DlOpen 0  #define os2DlError 0  #define os2DlSym 0  #define os2DlClose 0#endif/*** Write up to nBuf bytes of randomness into zBuf.*/static int os2Randomness(sqlite3_vfs *pVfs, int nBuf, char *zBuf ){  ULONG sizeofULong = sizeof(ULONG);  int n = 0;  if( sizeof(DATETIME) <= nBuf - n ){    DATETIME x;    DosGetDateTime(&x);    memcpy(&zBuf[n], &x, sizeof(x));    n += sizeof(x);  }  if( sizeofULong <= nBuf - n ){    PPIB ppib;    DosGetInfoBlocks(NULL, &ppib);    memcpy(&zBuf[n], &ppib->pib_ulpid, sizeofULong);    n += sizeofULong;  }  if( sizeofULong <= nBuf - n ){    PTIB ptib;    DosGetInfoBlocks(&ptib, NULL);    memcpy(&zBuf[n], &ptib->tib_ptib2->tib2_ultid, sizeofULong);    n += sizeofULong;  }  /* if we still haven't filled the buffer yet the following will */  /* grab everything once instead of making several calls for a single item */  if( sizeofULong <= nBuf - n ){    ULONG ulSysInfo[QSV_MAX];    DosQuerySysInfo(1L, QSV_MAX, ulSysInfo, sizeofULong * QSV_MAX);    memcpy(&zBuf[n], &ulSysInfo[QSV_MS_COUNT - 1], sizeofULong);    n += sizeofULong;    if( sizeofULong <= nBuf - n ){      memcpy(&zBuf[n], &ulSysInfo[QSV_TIMER_INTERVAL - 1], sizeofULong);      n += sizeofULong;    }    if( sizeofULong <= nBuf - n ){      memcpy(&zBuf[n], &ulSysInfo[QSV_TIME_LOW - 1], sizeofULong);      n += sizeofULong;    }    if( sizeofULong <= nBuf - n ){      memcpy(&zBuf[n], &ulSysInfo[QSV_TIME_HIGH - 1], sizeofULong);      n += sizeofULong;    }    if( sizeofULong <= nBuf - n ){      memcpy(&zBuf[n], &ulSysInfo[QSV_TOTAVAILMEM - 1], sizeofULong);      n += sizeofULong;    }  }  return n;}/*** Sleep for a little while.  Return the amount of time slept.** The argument is the number of microseconds we want to sleep.** The return value is the number of microseconds of sleep actually** requested from the underlying operating system, a number which** might be greater than or equal to the argument, but not less** than the argument.*/static int os2Sleep( sqlite3_vfs *pVfs, int microsec ){  DosSleep( (microsec/1000) );  return microsec;}/*** The following variable, if set to a non-zero value, becomes the result** returned from sqlite3OsCurrentTime().  This is used for testing.*/#ifdef SQLITE_TESTint sqlite3_current_time = 0;#endif/*** Find the current time (in Universal Coordinated Time).  Write the** current time and date as a Julian Day number into *prNow and** return 0.  Return 1 if the time and date cannot be found.*/int os2CurrentTime( sqlite3_vfs *pVfs, double *prNow ){  double now;  SHORT minute; /* needs to be able to cope with negative timezone offset */  USHORT second, hour,         day, month, year;  DATETIME dt;  DosGetDateTime( &dt );  second = (USHORT)dt.seconds;  minute = (SHORT)dt.minutes + dt.timezone;  hour = (USHORT)dt.hours;  day = (USHORT)dt.day;  month = (USHORT)dt.month;  year = (USHORT)dt.year;  /* Calculations from http://www.astro.keele.ac.uk/~rno/Astronomy/hjd.html     http://www.astro.keele.ac.uk/~rno/Astronomy/hjd-0.1.c */  /* Calculate the Julian days */  now = day - 32076 +    1461*(year + 4800 + (month - 14)/12)/4 +    367*(month - 2 - (month - 14)/12*12)/12 -    3*((year + 4900 + (month - 14)/12)/100)/4;  /* Add the fractional hours, mins and seconds */  now += (hour + 12.0)/24.0;  now += minute/1440.0;  now += second/86400.0;  *prNow = now;#ifdef SQLITE_TEST  if( sqlite3_current_time ){    *prNow = sqlite3_current_time/86400.0 + 2440587.5;  }#endif  return 0;}static int os2GetLastError(sqlite3_vfs *pVfs, int nBuf, char *zBuf){  return 0;}/*** Initialize and deinitialize the operating system interface.*/int sqlite3_os_init(void){  static sqlite3_vfs os2Vfs = {    1,                 /* iVersion */    sizeof(os2File),   /* szOsFile */    CCHMAXPATH,        /* mxPathname */    0,                 /* pNext */    "os2",             /* zName */    0,                 /* pAppData */    os2Open,           /* xOpen */    os2Delete,         /* xDelete */    os2Access,         /* xAccess */    os2FullPathname,   /* xFullPathname */    os2DlOpen,         /* xDlOpen */    os2DlError,        /* xDlError */    os2DlSym,          /* xDlSym */    os2DlClose,        /* xDlClose */    os2Randomness,     /* xRandomness */    os2Sleep,          /* xSleep */    os2CurrentTime,    /* xCurrentTime */    os2GetLastError    /* xGetLastError */  };  sqlite3_vfs_register(&os2Vfs, 1);  initUconvObjects();  return SQLITE_OK;}int sqlite3_os_end(void){  freeUconvObjects();  return SQLITE_OK;}#endif /* SQLITE_OS_OS2 */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -