mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-07 02:42:48 +03:00
Add sqlite3_quota_ferror() and sqlite3_quota_file_available() interfaces to
test_quota.c. Change sqlite3_quota_fwrite() to use a const input buffer. FossilOrigin-Name: 61669c95859e187618fb2fb4249306a947ae8d26
This commit is contained in:
@@ -1042,7 +1042,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 +1052,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 +1091,7 @@ size_t sqlite3_quota_fwrite(
|
||||
pFile->iSize = iNewEnd;
|
||||
quotaLeave();
|
||||
}
|
||||
return rc;
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1160,6 +1160,13 @@ long sqlite3_quota_ftell(quota_FILE *p){
|
||||
return ftell(p->f);
|
||||
}
|
||||
|
||||
/*
|
||||
** 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.
|
||||
*/
|
||||
@@ -1236,6 +1243,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.
|
||||
@@ -1895,6 +1921,53 @@ static int test_quota_glob(
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** 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
|
||||
@@ -1924,6 +1997,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;
|
||||
|
||||
|
Reference in New Issue
Block a user