Hi pals, I was trying to reload the database as is shown in the online
documentation, but it doesnt works. The function cl_statchkdir(&dbstat) always
return 0, I belive I'm doing something wrong, please review my code and send
comments.


Thanks in advance.

Geffrey


#include <stdio.h>
#include <clamav.h>
#include <string.h>

int main()
{
        int ret, no = 0;
        struct cl_node *root = NULL;

        if((ret = cl_loaddbdir(cl_retdbdir(), &root, &no))) {
                printf("cl_loaddbdir: %s\n", cl_perror(ret));
                return 2;
        }

        if((ret = cl_build(root))) {
                printf("Database initialization error: %s\n", 
cl_strerror(ret));;
                cl_free(root);
                return 2;
        }

        printf("ClamAV version %s with %d virus signatures loaded\n",
cl_retver(), no);
       /* waiting for freshclam for DB update */
       getchar();
      
        struct cl_stat dbstat;
        memset(&dbstat, 0, sizeof(struct cl_stat));
        cl_statinidir(cl_retdbdir(), &dbstat);

        /* always return 0, never reload the DB*/
        if(cl_statchkdir(&dbstat) == 1) {
                cl_free(root);
                root = NULL;
                no = 0;
               if((ret = cl_loaddbdir(cl_retdbdir(), &root, &no))) {
                        printf("cl_loaddbdir: %s\n", cl_perror(ret));
                        return 2;
                }

                if((ret = cl_build(root))) {
                        printf("Database initialization error: %s\n",
cl_strerror(ret));;
                        cl_free(root);
                        return 2;
                }

                cl_statfree(&dbstat);
                cl_statinidir(cl_retdbdir(), &dbstat);
        }

        printf("ClamAV version %s with %d virus signatures loaded\n",
cl_retver(), no);

        cl_free(root);

        return 0;
}

_______________________________________________
http://lurker.clamav.net/list/clamav-devel.html

Reply via email to