/ Check-in [b60508cc]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Copy the latest VFS changes into the OS/2 implementation. This is a blind edit - I have no way to compile or test OS/2. (CVS 5210)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: b60508ccbc3159e994bc988512d9dbec3932deb6
User & Date: drh 2008-06-12 12:38:10
Context
2008-06-12
12:40
Remove obsolete code from the test_osinst.c module. (CVS 5211) check-in: 699cec66 user: drh tags: trunk
12:38
Copy the latest VFS changes into the OS/2 implementation. This is a blind edit - I have no way to compile or test OS/2. (CVS 5210) check-in: b60508cc user: drh tags: trunk
05:16
Added additional testcases for julianday calculations with midnight boundary for UTC time. (CVS 5209) check-in: edd2cb00 user: shane tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/os_os2.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   ******************************************************************************
    12     12   **
    13     13   ** This file contains code that is specific to OS/2.
    14     14   **
    15         -** $Id: os_os2.c,v 1.41 2008/06/12 02:16:45 shane Exp $
           15  +** $Id: os_os2.c,v 1.42 2008/06/12 12:38:10 drh Exp $
    16     16   */
    17     17   
    18     18   #include "sqliteInt.h"
    19     19   
    20     20   #if OS_OS2
    21     21   
    22     22   /*
................................................................................
   410    410   }
   411    411   
   412    412   /*
   413    413   ** This routine checks if there is a RESERVED lock held on the specified
   414    414   ** file by this or any other process. If such a lock is held, return
   415    415   ** non-zero, otherwise zero.
   416    416   */
   417         -int os2CheckReservedLock( sqlite3_file *id ){
          417  +int os2CheckReservedLock( sqlite3_file *id, int *pOut ){
   418    418     int r = 0;
   419    419     os2File *pFile = (os2File*)id;
   420    420     assert( pFile!=0 );
   421    421     if( pFile->locktype>=RESERVED_LOCK ){
   422    422       r = 1;
   423    423       OSTRACE3( "TEST WR-LOCK %d %d (local)\n", pFile->h, r );
   424    424     }else{
................................................................................
   441    441         UnlockArea.lRange = 1L;
   442    442         rcu = DosSetFileLocks( pFile->h, &UnlockArea, &LockArea, LOCK_TIMEOUT, 0L );
   443    443         OSTRACE3( "TEST WR-LOCK %d unlock reserved byte r=%d\n", pFile->h, rcu );
   444    444       }
   445    445       r = !(rc == NO_ERROR);
   446    446       OSTRACE3( "TEST WR-LOCK %d %d (remote)\n", pFile->h, r );
   447    447     }
   448         -  return r;
          448  +  *pOut = r;
          449  +  return SQLITE_OK;
   449    450   }
   450    451   
   451    452   /*
   452    453   ** Lower the locking level on file descriptor id to locktype.  locktype
   453    454   ** must be either NO_LOCK or SHARED_LOCK.
   454    455   **
   455    456   ** If the locking level of the file descriptor is already at or below
................................................................................
   627    628   };
   628    629   
   629    630   /***************************************************************************
   630    631   ** Here ends the I/O methods that form the sqlite3_io_methods object.
   631    632   **
   632    633   ** The next block of code implements the VFS methods.
   633    634   ****************************************************************************/
          635  +
          636  +/*
          637  +** Create a temporary file name in zBuf.  zBuf must be big enough to
          638  +** hold at pVfs->mxPathname characters.
          639  +*/
          640  +static int getTempname(int nBuf, char *zBuf ){
          641  +  static const unsigned char zChars[] =
          642  +    "abcdefghijklmnopqrstuvwxyz"
          643  +    "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
          644  +    "0123456789";
          645  +  int i, j;
          646  +  char zTempPathBuf[3];
          647  +  PSZ zTempPath = (PSZ)&zTempPathBuf;
          648  +  char *zTempPathUTF;
          649  +  if( DosScanEnv( (PSZ)"TEMP", &zTempPath ) ){
          650  +    if( DosScanEnv( (PSZ)"TMP", &zTempPath ) ){
          651  +      if( DosScanEnv( (PSZ)"TMPDIR", &zTempPath ) ){
          652  +           ULONG ulDriveNum = 0, ulDriveMap = 0;
          653  +           DosQueryCurrentDisk( &ulDriveNum, &ulDriveMap );
          654  +           sprintf( (char*)zTempPath, "%c:", (char)( 'A' + ulDriveNum - 1 ) );
          655  +      }
          656  +    }
          657  +  }
          658  +  /* strip off a trailing slashes or backslashes, otherwise we would get *
          659  +   * multiple (back)slashes which causes DosOpen() to fail               */
          660  +  j = strlen(zTempPath);
          661  +  while( j > 0 && ( zTempPath[j-1] == '\\' || zTempPath[j-1] == '/' ) ){
          662  +    j--;
          663  +  }
          664  +  zTempPath[j] = '\0';
          665  +  zTempPathUTF = convertCpPathToUtf8( zTempPath );
          666  +  sqlite3_snprintf( nBuf-30, zBuf,
          667  +                    "%s\\"SQLITE_TEMP_FILE_PREFIX, zTempPathUTF );
          668  +  free( zTempPathUTF );
          669  +  j = strlen( zBuf );
          670  +  sqlite3_randomness( 20, &zBuf[j] );
          671  +  for( i = 0; i < 20; i++, j++ ){
          672  +    zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
          673  +  }
          674  +  zBuf[j] = 0;
          675  +  OSTRACE2( "TEMP FILENAME: %s\n", zBuf );
          676  +  return SQLITE_OK;
          677  +}
          678  +
   634    679   
   635    680   /*
   636    681   ** Open a file.
   637    682   */
   638    683   static int os2Open(
   639    684     sqlite3_vfs *pVfs,            /* Not used */
   640    685     const char *zName,            /* Name of the file */
................................................................................
   646    691     ULONG ulFileAttribute = 0;
   647    692     ULONG ulOpenFlags = 0;
   648    693     ULONG ulOpenMode = 0;
   649    694     os2File *pFile = (os2File*)id;
   650    695     APIRET rc = NO_ERROR;
   651    696     ULONG ulAction;
   652    697     char *zNameCp;
          698  +  char zTmpname[MAX_PATH+1];    /* Buffer to hold name of temp file */
          699  +
          700  +  /* If the second argument to this function is NULL, generate a 
          701  +  ** temporary file name to use 
          702  +  */
          703  +  if( !zName ){
          704  +    int rc = getTempname(MAX_PATH+1, zTmpname);
          705  +    if( rc!=SQLITE_OK ){
          706  +      return rc;
          707  +    }
          708  +    zName = zTmpname;
          709  +  }
          710  +
   653    711   
   654    712     memset( pFile, 0, sizeof(*pFile) );
   655    713   
   656    714     OSTRACE2( "OPEN want %d\n", flags );
   657    715   
   658    716     /*ulOpenMode = flags & SQLITE_OPEN_READWRITE ? OPEN_ACCESS_READWRITE : OPEN_ACCESS_READONLY;*/
   659    717     if( flags & SQLITE_OPEN_READWRITE ){
................................................................................
   756    814   
   757    815   /*
   758    816   ** Check the existance and status of a file.
   759    817   */
   760    818   static int os2Access(
   761    819     sqlite3_vfs *pVfs,        /* Not used on os2 */
   762    820     const char *zFilename,    /* Name of file to check */
   763         -  int flags                 /* Type of test to make on this file */
          821  +  int flags,                /* Type of test to make on this file */
          822  +  int *pOut                 /* Write results here */
   764    823   ){
   765    824     FILESTATUS3 fsts3ConfigInfo;
   766    825     APIRET rc = NO_ERROR;
   767    826   
   768    827     memset( &fsts3ConfigInfo, 0, sizeof(fsts3ConfigInfo) );
   769    828     char *zFilenameCp = convertUtf8PathToCp( zFilename );
   770    829     rc = DosQueryPathInfo( (PSZ)zFilenameCp, FIL_STANDARD,
................................................................................
   781    840       case SQLITE_ACCESS_READWRITE:
   782    841         rc = (fsts3ConfigInfo.attrFile & FILE_READONLY) == 0;
   783    842         OSTRACE3( "ACCESS %s access of read/write  rc=%d\n", zFilename, rc );
   784    843         break;
   785    844       default:
   786    845         assert( !"Invalid flags argument" );
   787    846     }
   788         -  return rc;
          847  +  *pOut = rc;
          848  +  return SQLITE_OK;
   789    849   }
   790    850   
   791    851   
   792         -/*
   793         -** Create a temporary file name in zBuf.  zBuf must be big enough to
   794         -** hold at pVfs->mxPathname characters.
   795         -*/
   796         -static int os2GetTempname( sqlite3_vfs *pVfs, int nBuf, char *zBuf ){
   797         -  static const unsigned char zChars[] =
   798         -    "abcdefghijklmnopqrstuvwxyz"
   799         -    "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
   800         -    "0123456789";
   801         -  int i, j;
   802         -  char zTempPathBuf[3];
   803         -  PSZ zTempPath = (PSZ)&zTempPathBuf;
   804         -  char *zTempPathUTF;
   805         -  if( DosScanEnv( (PSZ)"TEMP", &zTempPath ) ){
   806         -    if( DosScanEnv( (PSZ)"TMP", &zTempPath ) ){
   807         -      if( DosScanEnv( (PSZ)"TMPDIR", &zTempPath ) ){
   808         -           ULONG ulDriveNum = 0, ulDriveMap = 0;
   809         -           DosQueryCurrentDisk( &ulDriveNum, &ulDriveMap );
   810         -           sprintf( (char*)zTempPath, "%c:", (char)( 'A' + ulDriveNum - 1 ) );
   811         -      }
   812         -    }
   813         -  }
   814         -  /* strip off a trailing slashes or backslashes, otherwise we would get *
   815         -   * multiple (back)slashes which causes DosOpen() to fail               */
   816         -  j = strlen(zTempPath);
   817         -  while( j > 0 && ( zTempPath[j-1] == '\\' || zTempPath[j-1] == '/' ) ){
   818         -    j--;
   819         -  }
   820         -  zTempPath[j] = '\0';
   821         -  zTempPathUTF = convertCpPathToUtf8( zTempPath );
   822         -  sqlite3_snprintf( nBuf-30, zBuf,
   823         -                    "%s\\"SQLITE_TEMP_FILE_PREFIX, zTempPathUTF );
   824         -  free( zTempPathUTF );
   825         -  j = strlen( zBuf );
   826         -  sqlite3_randomness( 20, &zBuf[j] );
   827         -  for( i = 0; i < 20; i++, j++ ){
   828         -    zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
   829         -  }
   830         -  zBuf[j] = 0;
   831         -  OSTRACE2( "TEMP FILENAME: %s\n", zBuf );
   832         -  return SQLITE_OK;
   833         -}
   834         -
   835    852   
   836    853   /*
   837    854   ** Turn a relative pathname into a full pathname.  Write the full
   838    855   ** pathname into zFull[].  zFull[] will be at least pVfs->mxPathname
   839    856   ** bytes in size.
   840    857   */
   841    858   static int os2FullPathname(
................................................................................
  1038   1055       0,                 /* pNext */
  1039   1056       "os2",             /* zName */
  1040   1057       0,                 /* pAppData */
  1041   1058   
  1042   1059       os2Open,           /* xOpen */
  1043   1060       os2Delete,         /* xDelete */
  1044   1061       os2Access,         /* xAccess */
  1045         -    os2GetTempname,    /* xGetTempname */
  1046   1062       os2FullPathname,   /* xFullPathname */
  1047   1063       os2DlOpen,         /* xDlOpen */
  1048   1064       os2DlError,        /* xDlError */
  1049   1065       os2DlSym,          /* xDlSym */
  1050   1066       os2DlClose,        /* xDlClose */
  1051   1067       os2Randomness,     /* xRandomness */
  1052   1068       os2Sleep,          /* xSleep */
  1053   1069       os2CurrentTime     /* xCurrentTime */
         1070  +    os2GetLastError    /* xGetLastError */
  1054   1071     };
  1055   1072   
  1056   1073     return &os2Vfs;
  1057   1074   }
  1058   1075   
  1059   1076   #endif /* OS_OS2 */