summaryrefslogtreecommitdiff
path: root/src/test_quota.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/test_quota.c')
-rw-r--r--src/test_quota.c93
1 files changed, 79 insertions, 14 deletions
diff --git a/src/test_quota.c b/src/test_quota.c
index 38dc36f..2ce46ac 100644
--- a/src/test_quota.c
+++ b/src/test_quota.c
@@ -48,7 +48,7 @@
/*
** Figure out if we are dealing with Unix, Windows, or some other
** operating system. After the following block of preprocess macros,
-** all of SQLITE_OS_UNIX, SQLITE_OS_WIN, SQLITE_OS_OS2, and SQLITE_OS_OTHER
+** all of SQLITE_OS_UNIX, SQLITE_OS_WIN, and SQLITE_OS_OTHER
** will defined to either 1 or 0. One of the four will be 1. The other
** three will be 0.
*/
@@ -58,8 +58,6 @@
# define SQLITE_OS_UNIX 0
# undef SQLITE_OS_WIN
# define SQLITE_OS_WIN 0
-# undef SQLITE_OS_OS2
-# define SQLITE_OS_OS2 0
# else
# undef SQLITE_OS_OTHER
# endif
@@ -71,20 +69,12 @@
|| defined(__MINGW32__) || defined(__BORLANDC__)
# define SQLITE_OS_WIN 1
# define SQLITE_OS_UNIX 0
-# define SQLITE_OS_OS2 0
-# elif defined(__EMX__) || defined(_OS2) || defined(OS2) \
- || defined(_OS2_) || defined(__OS2__)
-# define SQLITE_OS_WIN 0
-# define SQLITE_OS_UNIX 0
-# define SQLITE_OS_OS2 1
# else
# define SQLITE_OS_WIN 0
# define SQLITE_OS_UNIX 1
-# define SQLITE_OS_OS2 0
# endif
# else
# define SQLITE_OS_UNIX 0
-# define SQLITE_OS_OS2 0
# endif
#else
# ifndef SQLITE_OS_WIN
@@ -1042,7 +1032,7 @@ size_t sqlite3_quota_fread(
** the write if we exceed quota.
*/
size_t sqlite3_quota_fwrite(
- void *pBuf, /* Take content to write from here */
+ const void *pBuf, /* Take content to write from here */
size_t size, /* Size of each element */
size_t nmemb, /* Number of elements */
quota_FILE *p /* Write to this quota_FILE objecct */
@@ -1052,7 +1042,7 @@ size_t sqlite3_quota_fwrite(
sqlite3_int64 szNew;
quotaFile *pFile;
size_t rc;
-
+
iOfst = ftell(p->f);
iEnd = iOfst + size*nmemb;
pFile = p->pFile;
@@ -1091,7 +1081,7 @@ size_t sqlite3_quota_fwrite(
pFile->iSize = iNewEnd;
quotaLeave();
}
- return rc;
+ return rc;
}
/*
@@ -1161,6 +1151,13 @@ long sqlite3_quota_ftell(quota_FILE *p){
}
/*
+** Test the error indicator for the given file.
+*/
+int sqlite3_quota_ferror(quota_FILE *p){
+ return ferror(p->f);
+}
+
+/*
** Truncate a file to szNew bytes.
*/
int sqlite3_quota_ftruncate(quota_FILE *p, sqlite3_int64 szNew){
@@ -1236,6 +1233,25 @@ sqlite3_int64 sqlite3_quota_file_truesize(quota_FILE *p){
sqlite3_int64 sqlite3_quota_file_size(quota_FILE *p){
return p->pFile ? p->pFile->iSize : -1;
}
+
+/*
+** Determine the amount of data in bytes available for reading
+** in the given file.
+*/
+long sqlite3_quota_file_available(quota_FILE *p){
+ FILE* f = p->f;
+ long pos1, pos2;
+ int rc;
+ pos1 = ftell(f);
+ if ( pos1 < 0 ) return -1;
+ rc = fseek(f, 0, SEEK_END);
+ if ( rc != 0 ) return -1;
+ pos2 = ftell(f);
+ if ( pos2 < 0 ) return -1;
+ rc = fseek(f, pos1, SEEK_SET);
+ if ( rc != 0 ) return -1;
+ return pos2 - pos1;
+}
/*
** Remove a managed file. Update quotas accordingly.
@@ -1896,6 +1912,53 @@ static int test_quota_glob(
}
/*
+** tclcmd: sqlite3_quota_file_available HANDLE
+**
+** Return the number of bytes from the current file point to the end of
+** the file.
+*/
+static int test_quota_file_available(
+ void * clientData,
+ Tcl_Interp *interp,
+ int objc,
+ Tcl_Obj *CONST objv[]
+){
+ quota_FILE *p;
+ sqlite3_int64 x;
+ if( objc!=2 ){
+ Tcl_WrongNumArgs(interp, 1, objv, "HANDLE");
+ return TCL_ERROR;
+ }
+ p = sqlite3TestTextToPtr(Tcl_GetString(objv[1]));
+ x = sqlite3_quota_file_available(p);
+ Tcl_SetObjResult(interp, Tcl_NewWideIntObj(x));
+ return TCL_OK;
+}
+
+/*
+** tclcmd: sqlite3_quota_ferror HANDLE
+**
+** Return true if the file handle is in the error state.
+*/
+static int test_quota_ferror(
+ void * clientData,
+ Tcl_Interp *interp,
+ int objc,
+ Tcl_Obj *CONST objv[]
+){
+ quota_FILE *p;
+ int x;
+ if( objc!=2 ){
+ Tcl_WrongNumArgs(interp, 1, objv, "HANDLE");
+ return TCL_ERROR;
+ }
+ p = sqlite3TestTextToPtr(Tcl_GetString(objv[1]));
+ x = sqlite3_quota_ferror(p);
+ Tcl_SetObjResult(interp, Tcl_NewIntObj(x));
+ return TCL_OK;
+}
+
+/*
** This routine registers the custom TCL commands defined in this
** module. This should be the only procedure visible from outside
** of this module.
@@ -1924,6 +1987,8 @@ int Sqlitequota_Init(Tcl_Interp *interp){
{ "sqlite3_quota_file_mtime", test_quota_file_mtime },
{ "sqlite3_quota_remove", test_quota_remove },
{ "sqlite3_quota_glob", test_quota_glob },
+ { "sqlite3_quota_file_available",test_quota_file_available },
+ { "sqlite3_quota_ferror", test_quota_ferror },
};
int i;