Files
TheRock/rocm-systems/projects/rocprofiler-sdk/external/sqlite/tool/enlargedb.c
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

69 lines
1.8 KiB
C

/*
** Try to enlarge an SQLite database by appending many unused pages.
** The resulting database will fail PRAGMA integrity_check due to the
** appended unused pages, but it should work otherwise.
**
** Usage:
**
** enlargedb DATABASE N
**
** Adds N blank pages onto the end of DATABASE. N can be decimal
** or hex. The total number of pages after adding must be no greater
** than 4294967297
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, char **argv){
char *zEnd;
long long int toAppend;
long long int currentSz;
long long int newSz;
FILE *f;
size_t got;
int pgsz;
char zero = 0;
unsigned char buf[100];
if( argc!=3 ) goto usage_error;
toAppend = strtoll(argv[2], &zEnd, 0);
if( zEnd==argv[2] || zEnd[0] ) goto usage_error;
if( toAppend<1 ){
fprintf(stderr, "N must be at least 1\n");
exit(1);
}
f = fopen(argv[1], "r+b");
if( f==0 ){
fprintf(stderr, "cannot open \"%s\" for reading and writing\n", argv[1]);
exit(1);
}
got = fread(buf, 1, sizeof(buf), f);
if( got!=sizeof(buf) ) goto not_valid_db;
if( strcmp((char*)buf,"SQLite format 3")!=0 ) goto not_valid_db;
pgsz = (buf[16]<<8) + buf[17];
if( pgsz==1 ) pgsz = 65536;
if( pgsz<512 || pgsz>65536 || (pgsz&(pgsz-1))!=0 ) goto not_valid_db;
currentSz = (buf[28]<<24) + (buf[29]<<16) + (buf[30]<<8) + buf[31];
newSz = currentSz + toAppend;
if( newSz > 0xffffffff ) newSz = 0xffffffff;
buf[28] = (newSz>>24) & 0xff;
buf[29] = (newSz>>16) & 0xff;
buf[30] = (newSz>>8) & 0xff;
buf[31] = newSz & 0xff;
fseek(f, 28, SEEK_SET);
fwrite(&buf[28],4,1,f);
fseek(f, (long)(newSz*pgsz - 1), SEEK_SET);
fwrite(&zero,1,1,f);
fclose(f);
return 0;
not_valid_db:
fprintf(stderr,"not a valid database: %s\n", argv[1]);
exit(1);
usage_error:
fprintf(stderr,"Usage: %s DATABASE N\n", argv[0]);
exit(1);
}