--- rpl/src/gestion_fichiers.c 2010/03/06 18:29:06 1.6 +++ rpl/src/gestion_fichiers.c 2011/06/20 17:54:15 1.26 @@ -1,7 +1,7 @@ /* ================================================================================ - RPL/2 (R) version 4.0.12 - Copyright (C) 1989-2010 Dr. BERTRAND Joël + RPL/2 (R) version 4.1.0.prerelease.1 + Copyright (C) 1989-2011 Dr. BERTRAND Joël This file is part of RPL/2. @@ -20,7 +20,7 @@ */ -#include "rpl.conv.h" +#include "rpl-conv.h" /* @@ -77,7 +77,7 @@ creation_nom_fichier(struct_processus *s do { - sprintf(tampon, "RPL2-%lu-%lu-%lu", (unsigned long) getpid(), + sprintf(tampon, "RPL-%lu-%lu-%lu", (unsigned long) getpid(), (unsigned long) pthread_self(), ordre); if (chemin == NULL) @@ -229,7 +229,7 @@ recherche_chemin_fichiers_temporaires(st if ((nom_candidat = creation_nom_fichier(s_etat_processus, candidat)) == NULL) { - return NULL; + return(NULL); } if ((fichier = fopen(nom_candidat, "w+")) != NULL) @@ -245,7 +245,7 @@ recherche_chemin_fichiers_temporaires(st } else { - return NULL; + return(NULL); } } else @@ -259,7 +259,7 @@ recherche_chemin_fichiers_temporaires(st if ((nom_candidat = creation_nom_fichier(s_etat_processus, chemins[i])) == NULL) { - return NULL; + return(NULL); } if ((fichier = fopen(nom_candidat, "w+")) != NULL) @@ -275,7 +275,7 @@ recherche_chemin_fichiers_temporaires(st } else { - return NULL; + return(NULL); } } else @@ -391,16 +391,18 @@ caracteristiques_fichier(struct_processu static logical1 initialisation_controle(struct_processus *s_etat_processus, sqlite3 *sqlite, - logical1 fichier_indexe) + integer8 position_clef, logical1 fichier_indexe) { const char commande1[] = - "create table control(id integer primary key asc, lock text)"; + "create table control(id integer primary key asc, key integer)"; const char commande2[] = - "insert into control (id, lock) values (2, '0')"; + "insert into control (id, key) values (1, %lld)"; const char *queue; sqlite3_stmt *ppStmt; + unsigned char *commande; + if (sqlite3_prepare_v2(sqlite, commande1, strlen(commande1), &ppStmt, &queue) != SQLITE_OK) { @@ -422,24 +424,35 @@ initialisation_controle(struct_processus if (fichier_indexe == d_vrai) { - if (sqlite3_prepare_v2(sqlite, commande2, strlen(commande2), &ppStmt, + if (alsprintf(&commande, commande2, position_clef) < 0) + { + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; + return(d_erreur); + } + + if (sqlite3_prepare_v2(sqlite, commande, strlen(commande), &ppStmt, &queue) != SQLITE_OK) { + free(commande); (*s_etat_processus).erreur_systeme = d_es_erreur_fichier; return(d_erreur); } if (sqlite3_step(ppStmt) != SQLITE_DONE) { + free(commande); (*s_etat_processus).erreur_systeme = d_es_erreur_fichier; return(d_erreur); } if (sqlite3_finalize(ppStmt) != SQLITE_OK) { + free(commande); (*s_etat_processus).erreur_systeme = d_es_erreur_fichier; return(d_erreur); } + + free(commande); } return(d_absence_erreur); @@ -447,16 +460,16 @@ initialisation_controle(struct_processus logical1 initialisation_fichier_acces_indexe(struct_processus *s_etat_processus, - sqlite3 *sqlite, logical1 binaire) + sqlite3 *sqlite, integer8 position_clef, logical1 binaire) { const char commande1[] = "create table data(id integer primary key asc, key_id integer, " - "lock text)"; + "data text, sequence integer)"; const char commande10[] = "create table key(id integer primary key asc, key text)"; const char commande2[] = "create table data(id integer primary key asc, key_id integer, " - "lock blob)"; + "data blob, sequence integer)"; const char commande20[] = "create table key(id integer primary key asc, key blob)"; const char commande3[] = @@ -467,7 +480,7 @@ initialisation_fichier_acces_indexe(stru sqlite3_stmt *ppStmt; - if (initialisation_controle(s_etat_processus, sqlite, d_vrai) + if (initialisation_controle(s_etat_processus, sqlite, position_clef, d_vrai) != d_absence_erreur) { return(d_erreur); @@ -600,16 +613,16 @@ initialisation_fichier_acces_direct(stru sqlite3 *sqlite, logical1 binaire) { const char commande1[] = - "create table data(id integer primary key asc, lock text)"; + "create table data(id integer primary key asc, data text)"; const char commande2[] = - "create table data(id integer primary key asc, lock blob)"; + "create table data(id integer primary key asc, data blob)"; const char commande3[] = "create index data_idx on data(id)"; const char *queue; sqlite3_stmt *ppStmt; - if (initialisation_controle(s_etat_processus, sqlite, d_faux) + if (initialisation_controle(s_etat_processus, sqlite, (integer8) 0, d_faux) != d_absence_erreur) { return(d_erreur); @@ -680,97 +693,4 @@ initialisation_fichier_acces_direct(stru return(d_absence_erreur); } -unsigned char * -verrouillage_fichier_sqlite(struct_processus *s_etat_processus, - sqlite3 *sqlite, unsigned char *operation) -{ - const char commande1[] = - "select lock from control where id = 1"; - const char commande2[] = - "update control set lock = '%s'"; - const char *queue; - - const unsigned char *resultat; - - sqlite3_stmt *ppStmt; - - unsigned char *verrou; - - resultat = NULL; - - if (operation == NULL) - { - // Lecture du verrou - - if (sqlite3_prepare_v2(sqlite, commande1, strlen(commande1), &ppStmt, - &queue) != SQLITE_OK) - { - (*s_etat_processus).erreur_systeme = d_es_erreur_fichier; - return(NULL); - } - - if (sqlite3_step(ppStmt) != SQLITE_ROW) - { - (*s_etat_processus).erreur_systeme = d_es_erreur_fichier; - return(NULL); - } - - if (sqlite3_column_type(ppStmt, 0) != SQLITE_TEXT) - { - (*s_etat_processus).erreur_systeme = d_es_erreur_fichier; - return(NULL); - } - - resultat = sqlite3_column_text(ppStmt, 0); - - if ((verrou = malloc((strlen(resultat) + 1) * sizeof(unsigned char))) - == NULL) - { - return(NULL); - } - - strcpy(verrou, resultat); - - if (sqlite3_finalize(ppStmt) != SQLITE_OK) - { - (*s_etat_processus).erreur_systeme = d_es_erreur_fichier; - return(NULL); - } - } - else - { - // Positionnement d'un verrou - - if (alsprintf(&verrou, commande2, operation) < 0) - { - (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; - return(NULL); - } - - if (sqlite3_prepare_v2(sqlite, verrou, strlen(verrou), &ppStmt, - &queue) != SQLITE_OK) - { - (*s_etat_processus).erreur_systeme = d_es_erreur_fichier; - return(NULL); - } - - if (sqlite3_step(ppStmt) != SQLITE_DONE) - { - (*s_etat_processus).erreur_systeme = d_es_erreur_fichier; - return(NULL); - } - - if (sqlite3_finalize(ppStmt) != SQLITE_OK) - { - (*s_etat_processus).erreur_systeme = d_es_erreur_fichier; - return(NULL); - } - - free(verrou); - verrou = NULL; - } - - return(verrou); -} - // vim: ts=4