SQLite3 Amalgamation y C: Visor de Archivos y URLs al Azar

Iniciado por ~, 4 Abril 2016, 21:07 PM

0 Miembros y 1 Visitante están viendo este tema.

~

filesopen Espera_aleatoria_minima Espera_aleatoria_maxima Nombre_base_de_datos Numero_de_fila_de_configuracion

Aquí tengo un programa de consola que escribí, que abre automáticamente y al azar archivos locales o URLs tomadas de una base de datos SQLite3 la cual maneja por sí misma usando la librería de Amalgamación de SQLite3.

Está completamente escrita en C y funciona bajo Windows (aunque tal vez pueda funcionar bajo Wine).

Aquí está el binario compilado:
FILESOPEN.EXE

Aquí se puede ver y aprender a escribir un programa en C básico para manejar una base de datos SQLite3:
>> Grabación de Texto para el Visor Aleatorio de Archivos y URLs <<

La estructura documentada y el uso de la base de datos está contenido en dicha grabación de la escritura del código.

Se puede hacer una prueba del funcionamiento con la siguiente base de datos que contiene más de 2 millones de nombres de dominio provenientes de la lista diaria de 1 millón de sitios más importantes de Alexa:
domains_alexaranks.db

Para correr el programa, solo se necesita el siguiente comando:

filesopen 1 1 domains_alexaranks.db 1




Aquí está el código principal (compilado bajo MinGW):
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "SQLite3-Amalgamation-3.12.0/sqlite3.h"
#include "SQLite3-Amalgamation-3.12.0/sqlite3.c"
#include "SQLite3-Amalgamation-3.12.0/sqlite3ext.h"
#include <windows.h>

const char sqlite3_version[] = SQLITE_VERSION;

//Set default values for the number of table rows and for the current column
//this last one will be selected at random:
///
int SQLite3_Row_Ctr=1;
int SQLite3_Current_Row=1;

sqlite3      *SQLite3_DB_Obj;
sqlite3_stmt *SQLite3_State;
int           SQLite3_DB_Res_Handle;
char         *SQL_String;
char         *SQLite3_ErrorMsg=NULL;
char         *SQLite3_zTail_String;



//These are the default minimum and maximum number of minutes to wait
//before trying to open other file/directory entry:
///
int minwait=1;
int maxwait=1;


long minmax_rand(long min, long max)
{
return rand()%((max+1) - min) + min;
}


char *config_tablename;
char *config_datarowname;
char *config_idrowname;
char *config_fileprotocol;

static int SQLite3_Callback_config(void *NotUsed, int argc, char **argv, char **azColName)
{
config_tablename=malloc(512);
config_datarowname=malloc(512);
config_idrowname=malloc(512);
config_fileprotocol=malloc(512);

sprintf(config_tablename,"%s",argv[0]);
sprintf(config_datarowname,"%s",argv[1]);
sprintf(config_idrowname,"%s",argv[2]);
sprintf(config_fileprotocol,"%s",argv[3]);


printf("Getting database configuration...\n");
printf("tablename=%s\ndatarowname=%s\nidrowname=%s\nfileprotocol=%s\n\n", config_tablename, config_datarowname, config_idrowname, config_fileprotocol);


return 0;
}


static int SQLite3_Callback(void *NotUsed, int argc, char **argv, char **azColName)
{
int x=0;
int requiredSize=0;
int   openstrlen=0; char *cmd=NULL;
char *cmd2=NULL;
char *openstr="open";
char *openstrW;
char *explorerstr="C:\\WINDOWS\\explorer.exe";
char *explorerstrW;

int   execres=0;

openstrW=malloc(131072);
explorerstrW=malloc(131072);
cmd=malloc(131072);
cmd2=malloc(131072);

MultiByteToWideChar(
                     (UINT)CP_UTF8,
                     (DWORD)0,
                     (LPCSTR)explorerstr,
                     (int)-1,
                     (LPWSTR)explorerstrW,
                     (int)131072
                    );

MultiByteToWideChar(
                     (UINT)CP_UTF8,
                     (DWORD)0,
                     (LPCSTR)openstr,
                     (int)-1,
                     (LPWSTR)openstrW,
                     (int)131072
                    );




for(x=0; x<argc; x++)
{
  snprintf(cmd,131072,"\"%s%s\"",config_fileprotocol,argv[x]);

/*
int MultiByteToWideChar(
  _In_      UINT   CodePage,
  _In_      DWORD  dwFlags,
  _In_      LPCSTR lpMultiByteStr,
  _In_      int    cbMultiByte,
  _Out_opt_ LPWSTR lpWideCharStr,
  _In_      int    cchWideChar
);
*/
  MultiByteToWideChar(
                      (UINT)CP_UTF8,
                      (DWORD)0,
                      (LPCSTR)cmd,
                      (int)-1,
                      (LPWSTR)cmd2,
                      (int)131072
                     );

  printf("%ld: %s\n\n", SQLite3_Current_Row, cmd);

/*
HINSTANCE ShellExecute(
  _In_opt_ HWND    hwnd,
  _In_opt_ LPCTSTR lpOperation,
  _In_     LPCTSTR lpFile,
  _In_opt_ LPCTSTR lpParameters,
  _In_opt_ LPCTSTR lpDirectory,
  _In_     INT     nShowCmd
);

*/

  execres=(int)ShellExecuteW(
                (HWND)0,
                (LPCWSTR)openstrW,
                (LPCWSTR)explorerstrW,
                (LPCWSTR)cmd2,
                (LPCWSTR)NULL,
                (INT)SW_SHOWNORMAL
               );


  switch(execres)
  {
   case 0:
   printf("exec: 0");
   break;

   case ERROR_BAD_FORMAT:
    printf("exec: ERROR_BAD_FORMAT");
   break;

   case SE_ERR_ACCESSDENIED:
    printf("exec: SE_ERR_ACCESSDENIED");
   break;

   case SE_ERR_ASSOCINCOMPLETE:
    printf("exec: SE_ERR_ASSOCINCOMPLETE");
   break;

   case SE_ERR_DDEBUSY:
    printf("exec: SE_ERR_DDEBUSY");
   break;

   case SE_ERR_DDEFAIL:
    printf("exec: SE_ERR_DDEFAIL");
   break;

   case SE_ERR_DDETIMEOUT:
    printf("exec: SE_ERR_DDETIMEOUT");
   break;

   case SE_ERR_DLLNOTFOUND:
    printf("exec: SE_ERR_DLLNOTFOUND");
   break;

   case SE_ERR_FNF:
    printf("exec: SE_ERR_FNF");
   break;

   case SE_ERR_NOASSOC:
    printf("exec: SE_ERR_NOASSOC");
   break;

   case SE_ERR_OOM:
    printf("exec: SE_ERR_OOM");
   break;

   case SE_ERR_SHARE:
    printf("exec: SE_ERR_SHARE");
   break;
  }


  sleep(60*(int)minmax_rand(minwait,maxwait));
}

free(cmd);
free(cmd2);
free(openstrW);
free(explorerstrW);


return 0;
}


static int SQLite3_Callback2(void *NotUsed, int argc, char **argv, char **azColName)
{
SQLite3_Row_Ctr=atol(argv[0]);
return SQLite3_Row_Ctr;
}



void clear_state()
{
//NOTE: This is for the good practice of not leaving
//      freeing of resources or other default operations
//      at their default state but accelerate and ensure
//      the global sanity of the environment and the program
//      by specifying every operation exactly as we want it:
///
sqlite3_finalize(SQLite3_State);
sqlite3_close(SQLite3_DB_Obj);
free(SQL_String);

}






int main(int argc, char *argv[])
{
atexit(clear_state);
SQL_String=malloc(4096);



if(argc>=5)
{
  if(!(minwait=atoi(argv[1])))minwait=1;
  if(!(maxwait=atoi(argv[2])))maxwait=1;
}
  else
  {
   printf("Usage: filesopen min_minutes max_minutes SQLITE3_Database_Path Database_Config_ID\n\n");
   return -2;
  }


//Open the database and see if it was successful. If not, just exit the program:
///
  SQLite3_DB_Res_Handle=sqlite3_open(argv[3], &SQLite3_DB_Obj);

  if(SQLite3_DB_Res_Handle!=SQLITE_OK)
  {
   printf("Error opening database\n\n");
   return -1;
  }


  //Get the configuration of the database to use the proper table and field names,
  //as well as basic formatting for the data:
  ///
   snprintf(SQL_String, 4096, "SELECT tablename,datarowname,idrowname,fileprotocol FROM config WHERE configid=%s LIMIT 1", argv[4]);
   SQLite3_DB_Res_Handle=sqlite3_exec(
                                      SQLite3_DB_Obj,
                                      SQL_String,
                                      SQLite3_Callback_config,
                                      SQLite3_zTail_String,
                                      &SQLite3_ErrorMsg
                                     );







//Get all columns for the first time to count them.
//Its callback will return the count in SQLite3_Row_Ctr:
///
  snprintf(SQL_String, 4096, "SELECT COALESCE(MAX(%s)+1, 0) FROM %s", config_idrowname, config_tablename);
  SQLite3_DB_Res_Handle=sqlite3_exec(
                                     SQLite3_DB_Obj,
                                     SQL_String,
                                     SQLite3_Callback2,
                                     SQLite3_zTail_String,
                                     &SQLite3_ErrorMsg
                                    );

printf("Cycling through %ld files...\n", SQLite3_Row_Ctr);


while(1)
{
  //Go to next row (selected randomly):
  ///
   SQLite3_Current_Row=minmax_rand(1, SQLite3_Row_Ctr);


  //Get random files to open:
  ///
   snprintf(SQL_String, 4096, "SELECT %s FROM %s WHERE %s=%ld LIMIT 1", config_datarowname, config_tablename, config_idrowname, SQLite3_Current_Row);
   SQLite3_DB_Res_Handle=sqlite3_exec(
                                      SQLite3_DB_Obj,
                                      SQL_String,
                                      SQLite3_Callback,
                                      SQLite3_zTail_String,
                                      &SQLite3_ErrorMsg
                                     );


  //If there was a database error or fault, just end:
  ///
   if(SQLite3_ErrorMsg)return 0;
}


return 0;
}


Sitio web (si la siguiente imagen no aparece es porque está offline):

fary

Un byte a la izquierda.

HardForo

Bueno, lo he probado y no me ha funcionado  :-\

Código (dos) [Seleccionar]

g++ -o SQLite3-Amalgamation_example SQLite3-Amalgamation_example.c


Me genera todo este choclo de errores:

CitarIn file included from SQLite3-Amalgamation_example.c:5:0:

c:\mingw\include\sqlite3.c: In function 'void strftimeFunc(sqlite3_context*, int, sqlite3_value**)':
c:\mingw\include\sqlite3.c:17689:40: error: invalid conversion from 'void*' to 'char*' [-fpermissive]
     z = sqlite3DbMallocRawNN(db, (int)n);
                                        ^
c:\mingw\include\sqlite3.c: In function 'void* sqlite3MemMalloc(int)':
c:\mingw\include\sqlite3.c:18592:7: error: invalid conversion from 'void*' to 'sqlite3_int64* {aka long long int*}' [-
ermissive]
   p = SQLITE_MALLOC( nByte+8 );
       ^
c:\mingw\include\sqlite3.c: In function 'void* sqlite3MemRealloc(void*, int)':
c:\mingw\include\sqlite3.c:18665:7: error: invalid conversion from 'void*' to 'sqlite3_int64* {aka long long int*}' [-
ermissive]
   p = SQLITE_REALLOC(p, nByte+8 );
       ^
In file included from SQLite3-Amalgamation_example.c:5:0:
c:\mingw\include\sqlite3.c: In function 'sqlite3_mutex* winMutexAlloc(int)':
c:\mingw\include\sqlite3.c:21842:41: error: invalid conversion from 'void*' to 'sqlite3_mutex*' [-fpermissive]
       p = sqlite3MallocZero( sizeof(*p) );
                                         ^
c:\mingw\include\sqlite3.c: In function 'char* sqlite3DbStrDup(sqlite3*, const char*)':
c:\mingw\include\sqlite3.c:22757:39: error: invalid conversion from 'void*' to 'char*' [-fpermissive]
   zNew = sqlite3DbMallocRaw(db, (int)n);
                                       ^
c:\mingw\include\sqlite3.c: In function 'char* sqlite3DbStrNDup(sqlite3*, const char*, u64)':
c:\mingw\include\sqlite3.c:22770:38: error: invalid conversion from 'void*' to 'char*' [-fpermissive]
   zNew = sqlite3DbMallocRawNN(db, n+1);
                                      ^
c:\mingw\include\sqlite3.c: In function 'void sqlite3VXPrintf(StrAccum*, const char*, va_list)':
c:\mingw\include\sqlite3.c:23266:47: error: invalid conversion from 'void*' to 'char*' [-fpermissive]
           zOut = zExtra = sqlite3Malloc( nOut );
                                               ^
c:\mingw\include\sqlite3.c:23377:71: error: invalid conversion from 'void*' to 'char*' [-fpermissive]
               = sqlite3Malloc( MAX(e2,0)+(i64)precision+(i64)width+15 );
                                                                       ^
c:\mingw\include\sqlite3.c:23525:29: error: invalid conversion from 'const char*' to 'char*' [-fpermissive]
         if( isnull ) escarg = (xtype==etSQLESCAPE2 ? "NULL" : "(NULL)");
                             ^
c:\mingw\include\sqlite3.c:23533:45: error: invalid conversion from 'void*' to 'char*' [-fpermissive]
           bufpt = zExtra = sqlite3Malloc( n );
                                             ^
c:\mingw\include\sqlite3.c:23568:48: error: cannot convert 'SrcList::SrcList_item*' to 'SrcList_item*' in initializati

         struct SrcList_item *pItem = &pSrc->a[k];
                                                ^
c:\mingw\include\sqlite3.c:23571:18: error: invalid use of incomplete type 'struct SrcList_item'
         if( pItem->zDatabase ){
                  ^
In file included from SQLite3-Amalgamation_example.c:5:0:
c:\mingw\include\sqlite3.c:14473:59: error: forward declaration of 'struct SrcList_item'
SQLITE_PRIVATE int sqlite3IndexedByLookup(Parse *, struct SrcList_item *);
                                                           ^
In file included from SQLite3-Amalgamation_example.c:5:0:
c:\mingw\include\sqlite3.c:23572:49: error: invalid use of incomplete type 'struct SrcList_item'
           sqlite3StrAccumAppendAll(pAccum, pItem->zDatabase);
                                                 ^
In file included from SQLite3-Amalgamation_example.c:5:0:
c:\mingw\include\sqlite3.c:14473:59: error: forward declaration of 'struct SrcList_item'
SQLITE_PRIVATE int sqlite3IndexedByLookup(Parse *, struct SrcList_item *);
                                                           ^
In file included from SQLite3-Amalgamation_example.c:5:0:
c:\mingw\include\sqlite3.c:23575:47: error: invalid use of incomplete type 'struct SrcList_item'
         sqlite3StrAccumAppendAll(pAccum, pItem->zName);
                                               ^
In file included from SQLite3-Amalgamation_example.c:5:0:
c:\mingw\include\sqlite3.c:14473:59: error: forward declaration of 'struct SrcList_item'
SQLITE_PRIVATE int sqlite3IndexedByLookup(Parse *, struct SrcList_item *);
                                                           ^
In file included from SQLite3-Amalgamation_example.c:5:0:
c:\mingw\include\sqlite3.c: In function 'int sqlite3StrAccumEnlarge(StrAccum*, int)':
c:\mingw\include\sqlite3.c:23638:53: error: invalid conversion from 'void*' to 'char*' [-fpermissive]
       zNew = sqlite3DbRealloc(p->db, zOld, p->nAlloc);
                                                     ^
c:\mingw\include\sqlite3.c:23640:47: error: invalid conversion from 'void*' to 'char*' [-fpermissive]
       zNew = sqlite3_realloc64(zOld, p->nAlloc);
                                               ^
c:\mingw\include\sqlite3.c: In function 'char* sqlite3StrAccumFinish(StrAccum*)':
c:\mingw\include\sqlite3.c:23722:55: error: invalid conversion from 'void*' to 'char*' [-fpermissive]
       p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 );
                                                       ^
c:\mingw\include\sqlite3.c: In function 'void sqlite3_randomness(int, void*)':
c:\mingw\include\sqlite3.c:24479:25: error: invalid conversion from 'void*' to 'unsigned char*' [-fpermissive]
   unsigned char *zBuf = pBuf;
                         ^
c:\mingw\include\sqlite3.c: In function 'int sqlite3ThreadCreate(SQLiteThread**, void* (*)(void*), void*)':
c:\mingw\include\sqlite3.c:24737:31: error: invalid conversion from 'void*' to 'SQLiteThread*' [-fpermissive]
   p = sqlite3Malloc(sizeof(*p));
                               ^
c:\mingw\include\sqlite3.c: In function 'int sqlite3VdbeMemTranslate(Mem*, u8)':
c:\mingw\include\sqlite3.c:25132:42: error: invalid conversion from 'void*' to 'unsigned char*' [-fpermissive]
   zOut = sqlite3DbMallocRaw(pMem->db, len);
                                          ^
c:\mingw\include\sqlite3.c: In function 'char* sqlite3Utf16to8(sqlite3*, const void*, int, u8)':
c:\mingw\include\sqlite3.c:25299:56: error: invalid conversion from 'const void*' to 'const char*' [-fpermissive]
   sqlite3VdbeMemSetStr(&m, z, nByte, enc, SQLITE_STATIC);
                                                        ^
In file included from SQLite3-Amalgamation_example.c:5:0:
c:\mingw\include\sqlite3.c:16306:20: note: initializing argument 2 of 'int sqlite3VdbeMemSetStr(Mem*, const char*, int
u8, void (*)(void*))'
SQLITE_PRIVATE int sqlite3VdbeMemSetStr(Mem*, const char*, int, u8, void(*)(void*));
                    ^
In file included from SQLite3-Amalgamation_example.c:5:0:
c:\mingw\include\sqlite3.c: In function 'int sqlite3Utf16ByteLen(const void*, int)':
c:\mingw\include\sqlite3.c:25318:28: error: invalid conversion from 'const void*' to 'const unsigned char*' [-fpermiss
e]
   unsigned char const *z = zIn;
                            ^
c:\mingw\include\sqlite3.c: In function 'void insertElement(Hash*, _ht*, HashElem*)':
c:\mingw\include\sqlite3.c:26935:19: error: invalid use of incomplete type 'struct _ht'
     pHead = pEntry->count ? pEntry->chain : 0;
                   ^
c:\mingw\include\sqlite3.c:26930:10: error: forward declaration of 'struct _ht'
   struct _ht *pEntry,    /* The entry into which pNew is inserted */
          ^
c:\mingw\include\sqlite3.c:26935:35: error: invalid use of incomplete type 'struct _ht'
     pHead = pEntry->count ? pEntry->chain : 0;
                                   ^
c:\mingw\include\sqlite3.c:26930:10: error: forward declaration of 'struct _ht'
   struct _ht *pEntry,    /* The entry into which pNew is inserted */
          ^
c:\mingw\include\sqlite3.c:26936:11: error: invalid use of incomplete type 'struct _ht'
     pEntry->count++;
           ^
c:\mingw\include\sqlite3.c:26930:10: error: forward declaration of 'struct _ht'
   struct _ht *pEntry,    /* The entry into which pNew is inserted */
          ^
c:\mingw\include\sqlite3.c:26937:11: error: invalid use of incomplete type 'struct _ht'
     pEntry->chain = pNew;
           ^
c:\mingw\include\sqlite3.c:26930:10: error: forward declaration of 'struct _ht'
   struct _ht *pEntry,    /* The entry into which pNew is inserted */
          ^
c:\mingw\include\sqlite3.c: In function 'int rehash(Hash*, unsigned int)':
c:\mingw\include\sqlite3.c:26967:33: error: invalid application of 'sizeof' to incomplete type '_ht'
   if( new_size*sizeof(struct _ht)>SQLITE_MALLOC_SOFT_LIMIT ){
                                 ^
c:\mingw\include\sqlite3.c:26968:58: error: invalid application of 'sizeof' to incomplete type '_ht'
     new_size = SQLITE_MALLOC_SOFT_LIMIT/sizeof(struct _ht);
                                                          ^
c:\mingw\include\sqlite3.c:26982:67: error: invalid application of 'sizeof' to incomplete type '_ht'
   new_ht = (struct _ht *)sqlite3Malloc( new_size*sizeof(struct _ht) );
                                                                   ^
c:\mingw\include\sqlite3.c:26987:10: error: cannot convert '_ht*' to 'Hash::_ht*' in assignment
   pH->ht = new_ht;
          ^
c:\mingw\include\sqlite3.c:26988:70: error: invalid application of 'sizeof' to incomplete type '_ht'
   pH->htsize = new_size = sqlite3MallocSize(new_ht)/sizeof(struct _ht);
                                                                      ^
c:\mingw\include\sqlite3.c:26989:47: error: invalid application of 'sizeof' to incomplete type '_ht'
   memset(new_ht, 0, new_size*sizeof(struct _ht));
                                               ^
c:\mingw\include\sqlite3.c:26993:32: error: invalid use of incomplete type 'struct _ht'
     insertElement(pH, &new_ht[h], elem);
                                ^
c:\mingw\include\sqlite3.c:26930:10: error: forward declaration of 'struct _ht'
   struct _ht *pEntry,    /* The entry into which pNew is inserted */
          ^
c:\mingw\include\sqlite3.c: In function 'HashElem* findElementWithHash(const Hash*, const char*, unsigned int*)':
c:\mingw\include\sqlite3.c:27014:12: error: cannot convert 'Hash::_ht*' to '_ht*' in assignment
     pEntry = &pH->ht[h];
            ^
c:\mingw\include\sqlite3.c:27015:18: error: invalid use of incomplete type 'struct _ht'
     elem = pEntry->chain;
                  ^
c:\mingw\include\sqlite3.c:26930:10: error: forward declaration of 'struct _ht'
   struct _ht *pEntry,    /* The entry into which pNew is inserted */
          ^
c:\mingw\include\sqlite3.c:27016:19: error: invalid use of incomplete type 'struct _ht'
     count = pEntry->count;
                   ^
c:\mingw\include\sqlite3.c:26930:10: error: forward declaration of 'struct _ht'
   struct _ht *pEntry,    /* The entry into which pNew is inserted */
          ^
c:\mingw\include\sqlite3.c: In function 'void removeElementGivenHash(Hash*, HashElem*, unsigned int)':
c:\mingw\include\sqlite3.c:27051:12: error: cannot convert 'Hash::_ht*' to '_ht*' in assignment
     pEntry = &pH->ht[h];
            ^
c:\mingw\include\sqlite3.c:27052:15: error: invalid use of incomplete type 'struct _ht'
     if( pEntry->chain==elem ){
               ^
c:\mingw\include\sqlite3.c:26930:10: error: forward declaration of 'struct _ht'
   struct _ht *pEntry,    /* The entry into which pNew is inserted */
          ^
c:\mingw\include\sqlite3.c:27053:13: error: invalid use of incomplete type 'struct _ht'
       pEntry->chain = elem->next;
             ^
c:\mingw\include\sqlite3.c:26930:10: error: forward declaration of 'struct _ht'
   struct _ht *pEntry,    /* The entry into which pNew is inserted */
          ^
c:\mingw\include\sqlite3.c:27055:11: error: invalid use of incomplete type 'struct _ht'
     pEntry->count--;
           ^
c:\mingw\include\sqlite3.c:26930:10: error: forward declaration of 'struct _ht'
   struct _ht *pEntry,    /* The entry into which pNew is inserted */
          ^
c:\mingw\include\sqlite3.c: In function 'void* sqlite3HashInsert(Hash*, const char*, void*)':
c:\mingw\include\sqlite3.c:27125:54: error: cannot convert 'Hash::_ht*' to '_ht*' for argument '2' to 'void insertElem
t(Hash*, _ht*, HashElem*)'
   insertElement(pH, pH->ht ? &pH->ht[h] : 0, new_elem);
                                                      ^
c:\mingw\include\sqlite3.c: In function 'WCHAR* winUtf8ToUnicode(const char*)':
c:\mingw\include\sqlite3.c:36937:69: error: invalid conversion from 'void*' to 'LPWSTR {aka wchar_t*}' [-fpermissive]
   zWideFilename = sqlite3MallocZero( nChar*sizeof(zWideFilename[0]) );
                                                                     ^
c:\mingw\include\sqlite3.c: In function 'char* winUnicodeToUtf8(LPCWSTR)':
c:\mingw\include\sqlite3.c:36962:40: error: invalid conversion from 'void*' to 'char*' [-fpermissive]
   zFilename = sqlite3MallocZero( nByte );
                                        ^
c:\mingw\include\sqlite3.c: In function 'WCHAR* winMbcsToUnicode(const char*)':
c:\mingw\include\sqlite3.c:36992:69: error: invalid conversion from 'void*' to 'LPWSTR {aka wchar_t*}' [-fpermissive]
   zMbcsFilename = sqlite3MallocZero( nByte*sizeof(zMbcsFilename[0]) );
                                                                     ^
c:\mingw\include\sqlite3.c: In function 'char* winUnicodeToMbcs(LPCWSTR)':
c:\mingw\include\sqlite3.c:37021:40: error: invalid conversion from 'void*' to 'char*' [-fpermissive]
   zFilename = sqlite3MallocZero( nByte );
                                        ^
c:\mingw\include\sqlite3.c: In function 'int winOpenSharedMemory(winFile*)':
c:\mingw\include\sqlite3.c:38920:37: error: invalid conversion from 'void*' to 'winShm*' [-fpermissive]
   p = sqlite3MallocZero( sizeof(*p) );
                                     ^
c:\mingw\include\sqlite3.c:38923:60: error: invalid conversion from 'void*' to 'winShmNode*' [-fpermissive]
   pNew = sqlite3MallocZero( sizeof(*pShmNode) + nName + 17 );
                                                            ^
c:\mingw\include\sqlite3.c: In function 'int winShmMap(sqlite3_file*, int, int, int, volatile void**)':
c:\mingw\include\sqlite3.c:39255:54: error: invalid use of incomplete type 'struct winShmMap(sqlite3_file*, int, int,
t, volatile void**)::ShmRegion'
         pShmNode->aRegion, (iRegion+1)*sizeof(apNew[0])
                                                      ^
c:\mingw\include\sqlite3.c:39220:12: error: forward declaration of 'struct winShmMap(sqlite3_file*, int, int, int, vol
ile void**)::ShmRegion'
     struct ShmRegion *apNew;           /* New aRegion[] array */
            ^
c:\mingw\include\sqlite3.c:39255:55: error: invalid application of 'sizeof' to incomplete type 'winShmMap(sqlite3_file
int, int, int, volatile void**)::ShmRegion'
         pShmNode->aRegion, (iRegion+1)*sizeof(apNew[0])
                                                       ^
c:\mingw\include\sqlite3.c:39261:23: error: cannot convert 'winShmMap(sqlite3_file*, int, int, int, volatile void**)::
mRegion*' to 'winShmNode::ShmRegion*' in assignment
     pShmNode->aRegion = apNew;
                       ^
c:\mingw\include\sqlite3.c: In function 'int winGetTempname(sqlite3_vfs*, char**)':
c:\mingw\include\sqlite3.c:39685:34: error: invalid conversion from 'void*' to 'char*' [-fpermissive]
   zBuf = sqlite3MallocZero( nBuf );
                                  ^
c:\mingw\include\sqlite3.c:39794:62: error: invalid conversion from 'void*' to 'LPWSTR {aka wchar_t*}' [-fpermissive]
     LPWSTR zWidePath = sqlite3MallocZero( nMax*sizeof(WCHAR) );
                                                              ^
c:\mingw\include\sqlite3.c:39822:47: error: invalid conversion from 'void*' to 'char*' [-fpermissive]
     char *zMbcsPath = sqlite3MallocZero( nMax );
                                               ^
c:\mingw\include\sqlite3.c: In function 'int winDelete(sqlite3_vfs*, const char*, int)':
c:\mingw\include\sqlite3.c:40254:45: error: invalid conversion from 'void*' to 'LPCWSTR {aka const wchar_t*}' [-fpermi
ive]
       attr = osGetFileAttributesW(zConverted);
                                             ^
c:\mingw\include\sqlite3.c:40270:36: error: invalid conversion from 'void*' to 'LPCWSTR {aka const wchar_t*}' [-fpermi
ive]
       if ( osDeleteFileW(zConverted) ){
                                    ^
c:\mingw\include\sqlite3.c:40283:45: error: invalid conversion from 'void*' to 'LPCSTR {aka const char*}' [-fpermissiv

       attr = osGetFileAttributesA(zConverted);
                                             ^
c:\mingw\include\sqlite3.c:40298:36: error: invalid conversion from 'void*' to 'LPCSTR {aka const char*}' [-fpermissiv

       if ( osDeleteFileA(zConverted) ){
                                    ^
c:\mingw\include\sqlite3.c: In function 'int winFullPathname(sqlite3_vfs*, const char*, int, char*)':
c:\mingw\include\sqlite3.c:40573:55: error: invalid conversion from 'void*' to 'LPWSTR {aka wchar_t*}' [-fpermissive]
     zTemp = sqlite3MallocZero( nByte*sizeof(zTemp[0]) );
                                                       ^
c:\mingw\include\sqlite3.c:40599:55: error: invalid conversion from 'void*' to 'char*' [-fpermissive]
     zTemp = sqlite3MallocZero( nByte*sizeof(zTemp[0]) );
                                                       ^
c:\mingw\include\sqlite3.c: In function 'void (* winDlSym(sqlite3_vfs*, void*, const char*))()':
c:\mingw\include\sqlite3.c:40679:44: error: invalid conversion from 'HANDLE {aka void*}' to 'HMODULE {aka HINSTANCE__*
[-fpermissive]
   proc = osGetProcAddressA((HANDLE)pH, zSym);
                                            ^
c:\mingw\include\sqlite3.c: In function 'void winDlClose(sqlite3_vfs*, void*)':
c:\mingw\include\sqlite3.c:40686:32: error: invalid conversion from 'HANDLE {aka void*}' to 'HMODULE {aka HINSTANCE__*
[-fpermissive]
   osFreeLibrary((HANDLE)pHandle);
                                ^
c:\mingw\include\sqlite3.c: In function 'Bitvec* sqlite3BitvecCreate(u32)':
c:\mingw\include\sqlite3.c:41105:37: error: invalid conversion from 'void*' to 'Bitvec*' [-fpermissive]
   p = sqlite3MallocZero( sizeof(*p) );
                                     ^
In file included from SQLite3-Amalgamation_example.c:5:0:
c:\mingw\include\sqlite3.c: In function 'int sqlite3BitvecSet(Bitvec*, u32)':
c:\mingw\include\sqlite3.c:41200:21: error: invalid conversion from 'void*' to 'u32* {aka unsigned int*}' [-fpermissiv

     u32 *aiValues = sqlite3StackAllocRaw(0, sizeof(p->u.aHash));
                     ^
In file included from SQLite3-Amalgamation_example.c:5:0:
c:\mingw\include\sqlite3.c: In function 'void sqlite3BitvecClear(Bitvec*, u32, void*)':
c:\mingw\include\sqlite3.c:41243:21: error: invalid conversion from 'void*' to 'u32* {aka unsigned int*}' [-fpermissiv

     u32 *aiValues = pBuf;
                     ^
c:\mingw\include\sqlite3.c: In function 'int sqlite3BitvecBuiltinTest(int, int*)':
c:\mingw\include\sqlite3.c:41334:40: error: invalid conversion from 'void*' to 'unsigned char*' [-fpermissive]
   pV = sqlite3MallocZero( (sz+7)/8 + 1 );
                                        ^
c:\mingw\include\sqlite3.c: In function 'int pcache1InitBulk(PCache1*)':
c:\mingw\include\sqlite3.c:42379:9: error: invalid conversion from 'void*' to 'char*' [-fpermissive]
   zBulk = pCache->pBulk = sqlite3Malloc( szBulk );
         ^
c:\mingw\include\sqlite3.c: In function 'RowSet* sqlite3RowSetInit(sqlite3*, void*, unsigned int)':
c:\mingw\include\sqlite3.c:43475:5: error: invalid conversion from 'void*' to 'RowSet*' [-fpermissive]
   p = pSpace;
     ^
c:\mingw\include\sqlite3.c: In function 'RowSetEntry* rowSetEntryAlloc(RowSet*)':
c:\mingw\include\sqlite3.c:43519:53: error: invalid conversion from 'void*' to 'RowSetChunk*' [-fpermissive]
     pNew = sqlite3DbMallocRawNN(p->db, sizeof(*pNew));
                                                     ^
c:\mingw\include\sqlite3.c: In function 'int pager_delmaster(Pager*, const char*)':
c:\mingw\include\sqlite3.c:46467:65: error: invalid conversion from 'void*' to 'char*' [-fpermissive]
   zMasterJournal = sqlite3Malloc(nMasterJournal + nMasterPtr + 1);
                                                                 ^
c:\mingw\include\sqlite3.c: In function 'int readDbPage(PgHdr*, u32)':
c:\mingw\include\sqlite3.c:46908:68: error: invalid conversion from 'void*' to 'u8* {aka unsigned char*}' [-fpermissiv

     rc = sqlite3WalReadFrame(pPager->pWal, iFrame, pgsz, pPg->pData);
                                                                    ^
c:\mingw\include\sqlite3.c:43946:20: note: initializing argument 4 of 'int sqlite3WalReadFrame(Wal*, u32, int, u8*)'
SQLITE_PRIVATE int sqlite3WalReadFrame(Wal *, u32, int, u8 *);

Aun asi no puedo:

Código (dos) [Seleccionar]
g++ -Wall -Werror -pedantic -std=c++11 -pthread -o SQLite3-Amalgamati
on_example SQLite3-Amalgamation_example.c -Wall -Werror -pedantic -std=c++11 -pthread

HardForo:  foro de Hardware y programación

Se buscan Mods y colaboradores *

MAFUS

Esto es porque lo quieres compilar con C++. C, no se queja tanto por la igualdad en tipos de datos, C++ es muy estricto en eso.
malloc, calloc, realloc devuelven void*. C al ver esto se fija en el tipo de dato del lvalue y si puede hacer la conversión, la hace; en cámbio C++ no hace ese paso y entiende que el programador, al no hacer el cast explícito, se ha equivocado.
int *p = malloc (sizeof (int));
Funciona en C pero en C++ necesita
int *p = (int*) malloc (sizeof(int));

HardForo

#4
@MAFUS:  me sirvió mucho la explicación  ;-)

Me la pasaba haciendo castings y supuestamente estaba jugando en C y ahora SI pude compilar sin errores el archivo, muchas gracias, me has salvado otra vez!

HardForo:  foro de Hardware y programación

Se buscan Mods y colaboradores *