File:  [local] / rpl / src / instructions_w1.c
Revision 1.73: download - view: text, annotated - select for diffs - revision graph
Fri Mar 1 09:29:30 2013 UTC (11 years, 2 months ago) by bertrand
Branches: MAIN
CVS tags: HEAD
Correction de bugs critiques dans READ (sockets) et dans les échappements
des caractères.

    1: /*
    2: ================================================================================
    3:   RPL/2 (R) version 4.1.13
    4:   Copyright (C) 1989-2013 Dr. BERTRAND Joël
    5: 
    6:   This file is part of RPL/2.
    7: 
    8:   RPL/2 is free software; you can redistribute it and/or modify it
    9:   under the terms of the CeCILL V2 License as published by the french
   10:   CEA, CNRS and INRIA.
   11:  
   12:   RPL/2 is distributed in the hope that it will be useful, but WITHOUT
   13:   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   14:   FITNESS FOR A PARTICULAR PURPOSE.  See the CeCILL V2 License
   15:   for more details.
   16:  
   17:   You should have received a copy of the CeCILL License
   18:   along with RPL/2. If not, write to info@cecill.info.
   19: ================================================================================
   20: */
   21: 
   22: 
   23: #include "rpl-conv.h"
   24: 
   25: 
   26: /*
   27: ================================================================================
   28:   Fonction 'while'
   29: ================================================================================
   30:   Entrées :
   31: --------------------------------------------------------------------------------
   32:   Sorties :
   33: --------------------------------------------------------------------------------
   34:   Effets de bord : néant
   35: ================================================================================
   36: */
   37: 
   38: void
   39: instruction_while(struct_processus *s_etat_processus)
   40: {
   41:     (*s_etat_processus).erreur_execution = d_ex;
   42: 
   43:     if ((*s_etat_processus).affichage_arguments == 'Y')
   44:     {
   45:         printf("\n  WHILE ");
   46: 
   47:         if ((*s_etat_processus).langue == 'F')
   48:         {
   49:             printf("(structure de contrôle)\n\n");
   50:             printf("  Utilisation :\n\n");
   51:         }
   52:         else
   53:         {
   54:             printf("(control statement)\n\n");
   55:             printf("  Usage:\n\n");
   56:         }
   57: 
   58:         printf("    WHILE\n");
   59:         printf("        (clause)\n");
   60:         printf("    REPEAT\n");
   61:         printf("        (expression 1)\n");
   62:         printf("        EXIT\n");
   63:         printf("        (expression 2)\n");
   64:         printf("    END\n\n");
   65: 
   66:         printf("    WHILE\n");
   67:         printf("        (clause)\n");
   68:         printf("    REPEAT\n");
   69:         printf("        (expression)\n");
   70:         printf("    END\n");
   71: 
   72:         return;
   73:     }
   74:     else if ((*s_etat_processus).test_instruction == 'Y')
   75:     {
   76:         (*s_etat_processus).nombre_arguments = -1;
   77:         return;
   78:     }
   79: 
   80:     empilement_pile_systeme(s_etat_processus);
   81: 
   82:     if ((*s_etat_processus).erreur_systeme != d_es)
   83:     {
   84:         return;
   85:     }
   86: 
   87:     (*(*s_etat_processus).l_base_pile_systeme).type_cloture = 'W';
   88:     (*(*s_etat_processus).l_base_pile_systeme).clause = 'W';
   89: 
   90:     if ((*s_etat_processus).mode_execution_programme == 'Y')
   91:     {
   92:         (*(*s_etat_processus).l_base_pile_systeme).adresse_retour =
   93:                 (*s_etat_processus).position_courante;
   94:     }
   95:     else
   96:     {
   97:         if ((*s_etat_processus).expression_courante == NULL)
   98:         {
   99:             (*s_etat_processus).erreur_execution =
  100:                     d_ex_erreur_traitement_boucle;
  101:             return;
  102:         }
  103: 
  104:         (*(*s_etat_processus).l_base_pile_systeme).pointeur_objet_retour =
  105:                 (*s_etat_processus).expression_courante;
  106:     }
  107: 
  108:     return;
  109: }
  110: 
  111: 
  112: /*
  113: ================================================================================
  114:   Fonction 'warranty'
  115: ================================================================================
  116:   Entrées :
  117: --------------------------------------------------------------------------------
  118:   Sorties :
  119: --------------------------------------------------------------------------------
  120:   Effets de bord : néant
  121: ================================================================================
  122: */
  123: 
  124: void
  125: instruction_warranty(struct_processus *s_etat_processus)
  126: {
  127: #   include                 "garanties-conv.h"
  128: 
  129:     (*s_etat_processus).erreur_execution = d_ex;
  130: 
  131:     if ((*s_etat_processus).affichage_arguments == 'Y')
  132:     {
  133:         printf("\n  WARRANTY ");
  134: 
  135:         if ((*s_etat_processus).langue == 'F')
  136:         {
  137:             printf("(garantie)\n\n");
  138:             printf("  Aucun argument\n");
  139:         }
  140:         else
  141:         {
  142:             printf("(warranty)\n\n");
  143:             printf("  No argument\n");
  144:         }
  145: 
  146:         return;
  147:     }
  148:     else if ((*s_etat_processus).test_instruction == 'Y')
  149:     {
  150:         (*s_etat_processus).nombre_arguments = -1;
  151:         return;
  152:     }
  153: 
  154:     printf("%s\n", warranty);
  155: 
  156:     if ((*s_etat_processus).hauteur_pile_operationnelle == 0)
  157:     {
  158:         printf("\n");
  159:     }
  160: 
  161:     return;
  162: }
  163: 
  164: 
  165: /*
  166: ================================================================================
  167:   Fonction 'wait'
  168: ================================================================================
  169:   Entrées :
  170: --------------------------------------------------------------------------------
  171:   Sorties :
  172: --------------------------------------------------------------------------------
  173:   Effets de bord : néant
  174: ================================================================================
  175: */
  176: 
  177: void
  178: instruction_wait(struct_processus *s_etat_processus)
  179: {
  180:     int                         code_retour;
  181:     int                         erreur;
  182: 
  183:     real8                       attente;
  184: 
  185:     struct_objet                *s_objet;
  186: 
  187:     struct timespec             temporisation;
  188: 
  189:     (*s_etat_processus).erreur_execution = d_ex;
  190: 
  191:     if ((*s_etat_processus).affichage_arguments == 'Y')
  192:     {
  193:         printf("\n  WAIT ");
  194: 
  195:         if ((*s_etat_processus).langue == 'F')
  196:         {
  197:             printf("(attente exprimée en secondes)\n\n");
  198:         }
  199:         else
  200:         {
  201:             printf("(wait a number of seconds)\n\n");
  202:         }
  203: 
  204:         printf("    1: %s, %s\n", d_INT, d_REL);
  205: 
  206:         return;
  207:     }
  208:     else if ((*s_etat_processus).test_instruction == 'Y')
  209:     {
  210:         (*s_etat_processus).nombre_arguments = -1;
  211:         return;
  212:     }
  213: 
  214:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
  215:     {
  216:         if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
  217:         {
  218:             return;
  219:         }
  220:     }
  221: 
  222:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
  223:             &s_objet) == d_erreur)
  224:     {
  225:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
  226:         return;
  227:     }
  228:     
  229:     if (((*s_objet).type == INT) || ((*s_objet).type == REL))
  230:     {
  231:         if ((*s_objet).type == INT)
  232:         {
  233:             attente = (real8) (*((integer8 *) (*s_objet).objet));
  234:         }
  235:         else
  236:         {
  237:             attente = (*((real8 *) (*s_objet).objet));
  238:         }
  239: 
  240:         if (attente < 0)
  241:         {
  242:             liberation(s_etat_processus, s_objet);
  243: 
  244:             (*s_etat_processus).erreur_execution = d_ex_argument_invalide;
  245:             return;
  246:         }
  247: 
  248:         temporisation.tv_sec = (long) floor((double) attente);
  249:         temporisation.tv_nsec = (attente - temporisation.tv_sec) *
  250:                 (long) 1000000000;
  251: 
  252:         if ((*s_etat_processus).profilage == d_vrai)
  253:         {
  254:             profilage(s_etat_processus, "Sleep function (WAIT)");
  255: 
  256:             if ((*s_etat_processus).erreur_systeme != d_es)
  257:             {
  258:                 return;
  259:             }
  260:         }
  261: 
  262:         do
  263:         {
  264: #           ifndef SEMAPHORES_NOMMES
  265:                 if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
  266: #           else
  267:                 if (sem_post((*s_etat_processus).semaphore_fork) != 0)
  268: #           endif
  269:             {
  270:                 (*s_etat_processus).erreur_systeme = d_es_processus;
  271:                 return;
  272:             }
  273: 
  274:             code_retour = nanosleep(&temporisation, &temporisation);
  275:             erreur = errno;
  276: 
  277: #           ifndef SEMAPHORES_NOMMES
  278:                 while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
  279: #           else
  280:                 while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
  281: #           endif
  282:             {
  283:                 if (errno != EINTR)
  284:                 {
  285:                     (*s_etat_processus).erreur_systeme = d_es_processus;
  286:                     return;
  287:                 }
  288:             }
  289: 
  290:             scrutation_injection(s_etat_processus);
  291: 
  292:             if ((*s_etat_processus).nombre_interruptions_non_affectees != 0)
  293:             {
  294:                 affectation_interruptions_logicielles(s_etat_processus);
  295:             }
  296: 
  297:             if ((*s_etat_processus).nombre_interruptions_en_queue != 0)
  298:             {
  299:                 traitement_interruptions_logicielles(s_etat_processus);
  300:             }
  301:         } while(((code_retour == -1) && (erreur == EINTR))
  302:                 && ((*s_etat_processus).var_volatile_requete_arret == 0));
  303: 
  304:         if ((*s_etat_processus).profilage == d_vrai)
  305:         {
  306:             profilage(s_etat_processus, NULL);
  307:         }
  308:     }
  309:     else
  310:     {
  311:         liberation(s_etat_processus, s_objet);
  312: 
  313:         (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
  314:         return;
  315:     }
  316: 
  317:     liberation(s_etat_processus, s_objet);
  318: 
  319:     return;
  320: }
  321: 
  322: 
  323: /*
  324: ================================================================================
  325:   Fonction 'wireframe' (passe en mode d'affichage échantillonné)
  326: ================================================================================
  327:   Entrées : structure processus
  328: --------------------------------------------------------------------------------
  329:   Sorties :
  330: --------------------------------------------------------------------------------
  331:   Effets de bord : néant
  332: ================================================================================
  333: */
  334: 
  335: void
  336: instruction_wireframe(struct_processus *s_etat_processus)
  337: {
  338:     (*s_etat_processus).erreur_execution = d_ex;
  339: 
  340:     if ((*s_etat_processus).affichage_arguments == 'Y')
  341:     {
  342:         printf("\n  WIREFRAME ");
  343: 
  344:         if ((*s_etat_processus).langue == 'F')
  345:         {
  346:             printf("(graphique tridimensionnel grillagé)\n\n");
  347:             printf("  Aucun argument\n");
  348:         }
  349:         else
  350:         {
  351:             printf("(wireframe 3D graph)\n\n");
  352:             printf("  No argument\n");
  353:         }
  354: 
  355:         return;
  356:     }
  357:     else if ((*s_etat_processus).test_instruction == 'Y')
  358:     {
  359:         (*s_etat_processus).nombre_arguments = -1;
  360:         return;
  361:     }
  362: 
  363:     strcpy((*s_etat_processus).type_trace_eq, "GRILLE 3D");
  364: 
  365:     return;
  366: }
  367: 
  368: 
  369: /*
  370: ================================================================================
  371:   Fonction 'write'
  372: ================================================================================
  373:   Entrées : structure processus
  374: --------------------------------------------------------------------------------
  375:   Sorties :
  376: --------------------------------------------------------------------------------
  377:   Effets de bord : néant
  378: ================================================================================
  379: */
  380: 
  381: void
  382: instruction_write(struct_processus *s_etat_processus)
  383: {
  384:     const char                          *queue;
  385: 
  386:     int                                 adresse[16];
  387:     int                                 port;
  388:     int                                 sqlite_status;
  389: 
  390:     integer8                            clef;
  391:     integer8                            compteur;
  392:     integer8                            id;
  393:     integer8                            ordre;
  394: 
  395:     logical1                            format_degenere;
  396:     logical1                            mise_a_jour;
  397: 
  398:     long                                longueur;
  399:     long                                longueur_effective;
  400:     long                                recursivite;
  401: 
  402:     sqlite3_stmt                        *ppStmt;
  403: 
  404:     ssize_t                             ios;
  405: 
  406:     struct_descripteur_fichier          *descripteur;
  407: 
  408:     struct_liste_chainee                *l_element_courant;
  409:     struct_liste_chainee                *l_element_courant_format;
  410: 
  411:     struct_objet                        *s_format;
  412:     struct_objet                        *s_element;
  413:     struct_objet                        *s_objet_argument_1;
  414:     struct_objet                        *s_objet_argument_2;
  415:     struct_objet                        *s_objet_argument_3;
  416: 
  417:     struct sigaction                    action;
  418:     struct sigaction                    registre;
  419: 
  420:     struct sockaddr_in                  adresse_ipv4;
  421: #   ifdef IPV6
  422:     struct sockaddr_in6                 adresse_ipv6;
  423: #   endif
  424:     struct sockaddr_un                  adresse_unix;
  425: 
  426:     struct flock                        lock;
  427: 
  428:     struct timespec                     attente;
  429: 
  430:     uint32_t                            calcul_adresse;
  431: 
  432:     unsigned char                       *chaine;
  433:     unsigned char                       *chaine_utf8;
  434:     unsigned char                       *clef_utf8;
  435:     unsigned char                       *commande;
  436:     unsigned char                       *format_chaine;
  437: 
  438:     unsigned long                       i;
  439: 
  440:     (*s_etat_processus).erreur_execution = d_ex;
  441: 
  442:     if ((*s_etat_processus).affichage_arguments == 'Y')
  443:     {
  444:         printf("\n  WRITE ");
  445: 
  446:         if ((*s_etat_processus).langue == 'F')
  447:         {
  448:             printf("(écriture d'un enregistrement d'un fichier)\n\n");
  449:         }
  450:         else
  451:         {
  452:             printf("(write a record of a file)\n\n");
  453:         }
  454: 
  455:         printf("    2: %s\n", d_LST);
  456:         printf("    1: %s, %s\n\n", d_FCH, d_SCK);
  457: 
  458:         printf("    3: %s\n", d_LST);
  459:         printf("    2: %s\n", d_INT);
  460:         printf("    1: %s\n", d_FCH);
  461:         return;
  462:     }
  463:     else if ((*s_etat_processus).test_instruction == 'Y')
  464:     {
  465:         (*s_etat_processus).nombre_arguments = -1;
  466:         return;
  467:     }
  468: 
  469:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
  470:     {
  471:         if ((*s_etat_processus).l_base_pile == NULL)
  472:         {
  473:             (*s_etat_processus).erreur_execution = d_ex_manque_argument;
  474:             return;
  475:         }
  476: 
  477:         if ((*(*(*s_etat_processus).l_base_pile).donnee).type == FCH)
  478:         {
  479:             if ((*((struct_fichier *) (*(*(*s_etat_processus).l_base_pile)
  480:                     .donnee).objet)).acces == 'D')
  481:             {
  482:                 if (empilement_pile_last(s_etat_processus, 3) == d_erreur)
  483:                 {
  484:                     return;
  485:                 }
  486:             }
  487:             else
  488:             {
  489:                 if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
  490:                 {
  491:                     return;
  492:                 }
  493:             }
  494:         }
  495:         else
  496:         {
  497:             if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
  498:             {
  499:                 return;
  500:             }
  501:         }
  502:     }
  503: 
  504:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
  505:             &s_objet_argument_1) == d_erreur)
  506:     {
  507:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
  508:         return;
  509:     }
  510:     
  511:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
  512:             &s_objet_argument_2) == d_erreur)
  513:     {
  514:         liberation(s_etat_processus, s_objet_argument_1);
  515: 
  516:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
  517:         return;
  518:     }
  519:     
  520:     if ((*s_objet_argument_1).type == FCH)
  521:     {
  522:         if ((descripteur = descripteur_fichier(s_etat_processus,
  523:                 (struct_fichier *) (*s_objet_argument_1).objet)) == NULL)
  524:         {
  525:             return;
  526:         }
  527: 
  528:         /*
  529:          * Vérification des verrous
  530:          */
  531: 
  532:         lock.l_type = F_WRLCK;
  533:         lock.l_whence = SEEK_SET;
  534:         lock.l_start = 0;
  535:         lock.l_len = 0;
  536:         lock.l_pid = getpid();
  537:         recursivite = 0;
  538: 
  539:         if (fcntl(fileno((*descripteur).descripteur_c), F_GETLK, &lock)
  540:                 == -1)
  541:         {
  542:             liberation(s_etat_processus, s_objet_argument_2);
  543:             liberation(s_etat_processus, s_objet_argument_1);
  544: 
  545:             (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  546:             return;
  547:         }
  548: 
  549:         if (lock.l_type != F_UNLCK)
  550:         {
  551:             liberation(s_etat_processus, s_objet_argument_2);
  552:             liberation(s_etat_processus, s_objet_argument_1);
  553: 
  554:             (*s_etat_processus).erreur_execution =
  555:                     d_ex_fichier_verrouille;
  556:             return;
  557:         }
  558: 
  559:         /*
  560:          * Vérification de l'autorisation d'écriture
  561:          */
  562: 
  563:         if ((*((struct_fichier *) (*s_objet_argument_1).objet))
  564:                 .protection == 'R')
  565:         {
  566:             liberation(s_etat_processus, s_objet_argument_2);
  567:             liberation(s_etat_processus, s_objet_argument_1);
  568: 
  569:             (*s_etat_processus).erreur_execution = d_ex_erreur_acces_fichier;
  570:             return;
  571:         }
  572: 
  573:         if ((*((struct_fichier *) (*s_objet_argument_1).objet)).binaire == 'N')
  574:         {
  575:             /*
  576:              * Fichiers formatés
  577:              */
  578: 
  579:             if ((*((struct_fichier *) (*s_objet_argument_1).objet)).acces
  580:                     == 'S')
  581:             {
  582:                 if ((*s_objet_argument_2).type != LST)
  583:                 {
  584:                     liberation(s_etat_processus, s_objet_argument_2);
  585:                     liberation(s_etat_processus, s_objet_argument_1);
  586: 
  587:                     (*s_etat_processus).erreur_execution =
  588:                             d_ex_erreur_type_argument;
  589:                     return;
  590:                 }
  591: 
  592:                 if ((chaine = formateur_fichier(s_etat_processus,
  593:                         s_objet_argument_2, (*((struct_fichier *)
  594:                         (*s_objet_argument_1).objet)).format, 0, 0, ' ', 'F',
  595:                         &longueur_effective, &recursivite)) == NULL)
  596:                 {
  597:                     liberation(s_etat_processus, s_objet_argument_2);
  598:                     liberation(s_etat_processus, s_objet_argument_1);
  599: 
  600:                     return;
  601:                 }
  602: 
  603:                 BUG(((*descripteur).type != 'C'), uprintf("Bad filetype !\n"));
  604: 
  605:                 if (fseek((*descripteur).descripteur_c, (long) 0, SEEK_END)
  606:                         != 0)
  607:                 {
  608:                     liberation(s_etat_processus, s_objet_argument_2);
  609:                     liberation(s_etat_processus, s_objet_argument_1);
  610: 
  611:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  612:                     return;
  613:                 }
  614: 
  615:                 if ((chaine_utf8 = transliteration(s_etat_processus,
  616:                         chaine, d_locale, "UTF-8")) == NULL)
  617:                 {
  618:                     free(chaine);
  619: 
  620:                     liberation(s_etat_processus, s_objet_argument_2);
  621:                     liberation(s_etat_processus, s_objet_argument_1);
  622: 
  623:                     return;
  624:                 }
  625: 
  626:                 free(chaine);
  627: 
  628:                 if (fprintf((*descripteur).descripteur_c, "%s\n", chaine_utf8)
  629:                         < 0)
  630:                 {
  631:                     free(chaine_utf8);
  632: 
  633:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  634:                     return;
  635:                 }
  636: 
  637:                 free(chaine_utf8);
  638:             }
  639:             else if ((*((struct_fichier *) (*s_objet_argument_1).objet)).acces
  640:                     == 'D')
  641:             {
  642:                 BUG(((*descripteur).type != 'S'), uprintf("Bad filetype !\n"));
  643: 
  644:                 if ((*s_objet_argument_2).type != INT)
  645:                 {
  646:                     liberation(s_etat_processus, s_objet_argument_2);
  647:                     liberation(s_etat_processus, s_objet_argument_1);
  648: 
  649:                     (*s_etat_processus).erreur_execution =
  650:                             d_ex_erreur_type_argument;
  651:                     return;
  652:                 }
  653: 
  654:                 if (depilement(s_etat_processus, &((*s_etat_processus)
  655:                         .l_base_pile), &s_objet_argument_3) == d_erreur)
  656:                 {
  657:                     (*s_etat_processus).erreur_execution = d_ex_manque_argument;
  658:                     return;
  659:                 }
  660: 
  661:                 if ((*s_objet_argument_3).type != LST)
  662:                 {
  663:                     liberation(s_etat_processus, s_objet_argument_3);
  664:                     liberation(s_etat_processus, s_objet_argument_2);
  665:                     liberation(s_etat_processus, s_objet_argument_1);
  666: 
  667:                     (*s_etat_processus).erreur_execution =
  668:                             d_ex_erreur_type_argument;
  669:                     return;
  670:                 }
  671: 
  672:                 // Modification ou création d'un nouvel enregistrement
  673: 
  674:                 if ((chaine = formateur_fichier(s_etat_processus,
  675:                         s_objet_argument_3, (*((struct_fichier *)
  676:                         (*s_objet_argument_1).objet)).format, 0, 0, ' ',
  677:                         'F', &longueur_effective, &recursivite)) == NULL)
  678:                 {
  679:                     liberation(s_etat_processus, s_objet_argument_3);
  680:                     liberation(s_etat_processus, s_objet_argument_2);
  681:                     liberation(s_etat_processus, s_objet_argument_1);
  682: 
  683:                     return;
  684:                 }
  685: 
  686:                 if ((chaine_utf8 = transliteration(s_etat_processus,
  687:                         chaine, d_locale, "UTF-8")) == NULL)
  688:                 {
  689:                     free(chaine);
  690: 
  691:                     liberation(s_etat_processus, s_objet_argument_3);
  692:                     liberation(s_etat_processus, s_objet_argument_2);
  693:                     liberation(s_etat_processus, s_objet_argument_1);
  694: 
  695:                     return;
  696:                 }
  697: 
  698:                 free(chaine);
  699: 
  700:                 if (alsprintf(&commande, "insert or replace into data "
  701:                         "(id, data) values (%lld, '%s')", (*((integer8 *)
  702:                         (*s_objet_argument_2).objet)), chaine_utf8) < 0)
  703:                 {
  704:                     (*s_etat_processus).erreur_systeme =
  705:                             d_es_allocation_memoire;
  706:                     return;
  707:                 }
  708: 
  709:                 free(chaine_utf8);
  710: 
  711:                 if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite,
  712:                         commande, strlen(commande), &ppStmt, &queue)
  713:                         != SQLITE_OK)
  714:                 {
  715:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  716:                     return;
  717:                 }
  718: 
  719:                 if (sqlite3_step(ppStmt) != SQLITE_DONE)
  720:                 {
  721:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  722:                     return;
  723:                 }
  724: 
  725:                 if (sqlite3_finalize(ppStmt) != SQLITE_OK)
  726:                 {
  727:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  728:                     return;
  729:                 }
  730: 
  731:                 liberation(s_etat_processus, s_objet_argument_3);
  732:                 free(commande);
  733:             }
  734:             else // Fichiers indexés
  735:             {
  736:                 BUG(((*descripteur).type != 'S'), uprintf("Bad filetype !\n"));
  737: 
  738:                 if ((*s_objet_argument_2).type != LST)
  739:                 {
  740:                     liberation(s_etat_processus, s_objet_argument_2);
  741:                     liberation(s_etat_processus, s_objet_argument_1);
  742: 
  743:                     (*s_etat_processus).erreur_execution =
  744:                             d_ex_erreur_type_argument;
  745:                     return;
  746:                 }
  747: 
  748:                 // Récupération de la position de la clef
  749: 
  750:                 if (alsprintf(&commande, "select key from control "
  751:                         "where id = 1") < 0)
  752:                 {
  753:                     (*s_etat_processus).erreur_systeme =
  754:                             d_es_allocation_memoire;
  755:                     return;
  756:                 }
  757: 
  758:                 if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite,
  759:                         commande, strlen(commande), &ppStmt, &queue)
  760:                         != SQLITE_OK)
  761:                 {
  762:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  763:                     return;
  764:                 }
  765: 
  766:                 attente.tv_sec = 0;
  767:                 attente.tv_nsec = GRANULARITE_us * 1000;
  768: 
  769:                 do
  770:                 {
  771:                     sqlite_status = sqlite3_step(ppStmt);
  772: 
  773:                     if (sqlite_status == SQLITE_ROW)
  774:                     {
  775:                         break;
  776:                     }
  777:                     else if ((sqlite_status == SQLITE_BUSY) ||
  778:                             (sqlite_status == SQLITE_LOCKED))
  779:                     {
  780:                         nanosleep(&attente, NULL);
  781:                         INCR_GRANULARITE(attente.tv_nsec);
  782:                     }
  783:                     else
  784:                     {
  785:                         (*s_etat_processus).erreur_systeme =
  786:                                 d_es_erreur_fichier;
  787:                         return;
  788:                     }
  789:                 } while(sqlite_status != SQLITE_ROW);
  790: 
  791:                 if (sqlite3_column_type(ppStmt, 0) != SQLITE_INTEGER)
  792:                 {
  793:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  794:                     return;
  795:                 }
  796: 
  797:                 clef = sqlite3_column_int64(ppStmt, 0);
  798: 
  799:                 if (sqlite3_step(ppStmt) != SQLITE_DONE)
  800:                 {
  801:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  802:                     return;
  803:                 }
  804: 
  805:                 if (sqlite3_finalize(ppStmt) != SQLITE_OK)
  806:                 {
  807:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  808:                     return;
  809:                 }
  810: 
  811:                 free(commande);
  812: 
  813:                 l_element_courant = (struct_liste_chainee *)
  814:                         (*s_objet_argument_2).objet;
  815:                 l_element_courant_format = (struct_liste_chainee *)
  816:                         (*(*((struct_fichier *) (*s_objet_argument_1).objet))
  817:                         .format).objet;
  818:                 compteur = 1;
  819: 
  820:                 while((l_element_courant != NULL) &&
  821:                         (l_element_courant_format != NULL))
  822:                 {
  823:                     if (compteur == clef)
  824:                     {
  825:                         break;
  826:                     }
  827: 
  828:                     l_element_courant = (*l_element_courant).suivant;
  829:                     l_element_courant_format = (*l_element_courant_format)
  830:                             .suivant;
  831:                     compteur++;
  832:                 }
  833: 
  834:                 if ((l_element_courant == NULL) ||
  835:                         (l_element_courant_format == NULL))
  836:                 {
  837:                     (*s_etat_processus).erreur_execution =
  838:                             d_ex_clef_inexistante;
  839:                         
  840:                     liberation(s_etat_processus, s_objet_argument_2);
  841:                     liberation(s_etat_processus, s_objet_argument_1);
  842: 
  843:                     return;
  844:                 }
  845: 
  846:                 if ((s_element = allocation(s_etat_processus, LST)) == NULL)
  847:                 {
  848:                     (*s_etat_processus).erreur_systeme =
  849:                             d_es_allocation_memoire;
  850:                     return;
  851:                 }
  852: 
  853:                 if (((*s_element).objet = allocation_maillon(s_etat_processus))
  854:                         == NULL)
  855:                 {
  856:                     (*s_etat_processus).erreur_systeme =
  857:                             d_es_allocation_memoire;
  858:                     return;
  859:                 }
  860: 
  861:                 (*((struct_liste_chainee *) (*s_element).objet)).suivant = NULL;
  862: 
  863:                 if (((*((struct_liste_chainee *) (*s_element).objet))
  864:                         .donnee = copie_objet(s_etat_processus,
  865:                         (*l_element_courant).donnee, 'N')) == NULL)
  866:                 {
  867:                     (*s_etat_processus).erreur_systeme =
  868:                             d_es_allocation_memoire;
  869:                     return;
  870:                 }
  871: 
  872:                 if ((s_format = allocation(s_etat_processus, LST)) == NULL)
  873:                 {
  874:                     (*s_etat_processus).erreur_systeme =
  875:                             d_es_allocation_memoire;
  876:                     return;
  877:                 }
  878: 
  879:                 if (((*s_format).objet = allocation_maillon(s_etat_processus))
  880:                         == NULL)
  881:                 {
  882:                     (*s_etat_processus).erreur_systeme =
  883:                             d_es_allocation_memoire;
  884:                     return;
  885:                 }
  886: 
  887:                 (*((struct_liste_chainee *) (*s_format).objet)).suivant = NULL;
  888: 
  889:                 if (((*((struct_liste_chainee *) (*s_format).objet))
  890:                         .donnee = copie_objet(s_etat_processus,
  891:                         (*l_element_courant_format).donnee, 'N')) == NULL)
  892:                 {
  893:                     (*s_etat_processus).erreur_systeme =
  894:                             d_es_allocation_memoire;
  895:                     return;
  896:                 }
  897: 
  898:                 if ((chaine = formateur_fichier(s_etat_processus,
  899:                         s_element, s_format, 0, 0, ' ',
  900:                         'F', &longueur_effective, &recursivite)) == NULL)
  901:                 {
  902:                     liberation(s_etat_processus, s_element);
  903:                     liberation(s_etat_processus, s_format);
  904:                     liberation(s_etat_processus, s_objet_argument_2);
  905:                     liberation(s_etat_processus, s_objet_argument_1);
  906: 
  907:                     return;
  908:                 }
  909: 
  910:                 liberation(s_etat_processus, s_element);
  911:                 liberation(s_etat_processus, s_format);
  912: 
  913:                 if ((clef_utf8 = transliteration(s_etat_processus,
  914:                         chaine, d_locale, "UTF-8")) == NULL)
  915:                 {
  916:                     liberation(s_etat_processus, s_objet_argument_2);
  917:                     liberation(s_etat_processus, s_objet_argument_1);
  918: 
  919:                     return;
  920:                 }
  921: 
  922:                 free(chaine);
  923: 
  924:                 // Récupération de l'identifiant de la clef
  925: 
  926:                 if (alsprintf(&commande, "select id from key where key = "
  927:                         "'%s'", clef_utf8) < 0)
  928:                 {
  929:                     (*s_etat_processus).erreur_systeme =
  930:                             d_es_allocation_memoire;
  931:                     return;
  932:                 }
  933: 
  934:                 if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite,
  935:                         commande, strlen(commande), &ppStmt, &queue)
  936:                         != SQLITE_OK)
  937:                 {
  938:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  939:                     return;
  940:                 }
  941: 
  942:                 attente.tv_sec = 0;
  943:                 attente.tv_nsec = GRANULARITE_us * 1000;
  944: 
  945:                 do
  946:                 {
  947:                     switch(sqlite_status = sqlite3_step(ppStmt))
  948:                     {
  949:                         case SQLITE_ROW:
  950:                         {
  951:                             // Une clef existe.
  952: 
  953:                             mise_a_jour = d_vrai;
  954:                             break;
  955:                         }
  956: 
  957:                         case SQLITE_DONE:
  958:                         {
  959:                             // Aucune clef n'existe.
  960: 
  961:                             mise_a_jour = d_faux;
  962: 
  963:                             if (sqlite3_finalize(ppStmt) != SQLITE_OK)
  964:                             {
  965:                                 (*s_etat_processus).erreur_systeme =
  966:                                         d_es_erreur_fichier;
  967:                                 return;
  968:                             }
  969: 
  970:                             free(commande);
  971: 
  972:                             if (alsprintf(&commande, "insert into key "
  973:                                     "(key) values ('%s')", clef_utf8) < 0)
  974:                             {
  975:                                 (*s_etat_processus).erreur_systeme =
  976:                                         d_es_allocation_memoire;
  977:                                 return;
  978:                             }
  979: 
  980:                             if (sqlite3_prepare_v2((*descripteur)
  981:                                     .descripteur_sqlite,
  982:                                     commande, strlen(commande), &ppStmt, &queue)
  983:                                     != SQLITE_OK)
  984:                             {
  985:                                 (*s_etat_processus).erreur_systeme =
  986:                                         d_es_erreur_fichier;
  987:                                 return;
  988:                             }
  989: 
  990:                             if (sqlite3_step(ppStmt) != SQLITE_DONE)
  991:                             {
  992:                                 (*s_etat_processus).erreur_systeme =
  993:                                         d_es_erreur_fichier;
  994:                                 return;
  995:                             }
  996: 
  997:                             if (sqlite3_finalize(ppStmt) != SQLITE_OK)
  998:                             {
  999:                                 (*s_etat_processus).erreur_systeme =
 1000:                                         d_es_erreur_fichier;
 1001:                                 return;
 1002:                             }
 1003: 
 1004:                             free(commande);
 1005: 
 1006:                             if (alsprintf(&commande, "select id from key "
 1007:                                     "where key = '%s'", clef_utf8) < 0)
 1008:                             {
 1009:                                 (*s_etat_processus).erreur_systeme =
 1010:                                         d_es_allocation_memoire;
 1011:                                 return;
 1012:                             }
 1013: 
 1014:                             if (sqlite3_prepare_v2((*descripteur)
 1015:                                     .descripteur_sqlite,
 1016:                                     commande, strlen(commande), &ppStmt, &queue)
 1017:                                     != SQLITE_OK)
 1018:                             {
 1019:                                 (*s_etat_processus).erreur_systeme =
 1020:                                         d_es_erreur_fichier;
 1021:                                 return;
 1022:                             }
 1023: 
 1024:                             break;
 1025:                         }
 1026: 
 1027:                         case SQLITE_BUSY:
 1028:                         case SQLITE_LOCKED:
 1029:                         {
 1030:                             nanosleep(&attente, NULL);
 1031:                             INCR_GRANULARITE(attente.tv_nsec);
 1032:                             break;
 1033:                         }
 1034: 
 1035:                         default:
 1036:                         {
 1037:                             (*s_etat_processus).erreur_systeme =
 1038:                                     d_es_erreur_fichier;
 1039:                             return;
 1040:                         }
 1041:                     }
 1042:                 } while(sqlite_status != SQLITE_ROW);
 1043: 
 1044:                 if (sqlite3_column_type(ppStmt, 0) != SQLITE_INTEGER)
 1045:                 {
 1046:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
 1047:                     return;
 1048:                 }
 1049: 
 1050:                 id = sqlite3_column_int64(ppStmt, 0);
 1051: 
 1052:                 if (sqlite3_step(ppStmt) != SQLITE_DONE)
 1053:                 {
 1054:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
 1055:                     return;
 1056:                 }
 1057: 
 1058:                 if (sqlite3_finalize(ppStmt) != SQLITE_OK)
 1059:                 {
 1060:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
 1061:                     return;
 1062:                 }
 1063: 
 1064:                 free(commande);
 1065: 
 1066:                 // Modification de la clef
 1067: 
 1068:                 if (mise_a_jour == d_vrai)
 1069:                 {
 1070:                     if (alsprintf(&commande, "update key set key = '%s' where "
 1071:                             "id = %lld", clef_utf8, id) < 0)
 1072:                     {
 1073:                         (*s_etat_processus).erreur_systeme =
 1074:                                 d_es_allocation_memoire;
 1075:                         return;
 1076:                     }
 1077: 
 1078:                     if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite,
 1079:                             commande, strlen(commande), &ppStmt, &queue)
 1080:                             != SQLITE_OK)
 1081:                     {
 1082:                         (*s_etat_processus).erreur_systeme =
 1083:                                 d_es_erreur_fichier;
 1084:                         return;
 1085:                     }
 1086: 
 1087:                     if (sqlite3_step(ppStmt) != SQLITE_DONE)
 1088:                     {
 1089:                         (*s_etat_processus).erreur_systeme =
 1090:                                 d_es_erreur_fichier;
 1091:                         return;
 1092:                     }
 1093: 
 1094:                     if (sqlite3_finalize(ppStmt) != SQLITE_OK)
 1095:                     {
 1096:                         (*s_etat_processus).erreur_systeme =
 1097:                                 d_es_erreur_fichier;
 1098:                         return;
 1099:                     }
 1100: 
 1101:                     free(commande);
 1102:                 }
 1103: 
 1104:                 // Effacement de l'enregistrement existant
 1105: 
 1106:                 if (alsprintf(&commande, "delete from data where "
 1107:                         "key_id = %lld", id) < 0)
 1108:                 {
 1109:                     (*s_etat_processus).erreur_systeme =
 1110:                             d_es_allocation_memoire;
 1111:                     return;
 1112:                 }
 1113: 
 1114:                 if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite,
 1115:                         commande, strlen(commande), &ppStmt, &queue)
 1116:                         != SQLITE_OK)
 1117:                 {
 1118:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
 1119:                     return;
 1120:                 }
 1121: 
 1122:                 if (sqlite3_step(ppStmt) != SQLITE_DONE)
 1123:                 {
 1124:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
 1125:                     return;
 1126:                 }
 1127: 
 1128:                 if (sqlite3_finalize(ppStmt) != SQLITE_OK)
 1129:                 {
 1130:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
 1131:                     return;
 1132:                 }
 1133: 
 1134:                 free(commande);
 1135: 
 1136:                 // Modification ou création d'un nouvel enregistrement
 1137: 
 1138:                 l_element_courant = (struct_liste_chainee *)
 1139:                         (*s_objet_argument_2).objet;
 1140:                 l_element_courant_format = (struct_liste_chainee *)
 1141:                         (*(*((struct_fichier *) (*s_objet_argument_1).objet))
 1142:                         .format).objet;
 1143:                 compteur = 1;
 1144:                 ordre = 1;
 1145: 
 1146:                 while((l_element_courant != NULL) &&
 1147:                         (l_element_courant_format != NULL))
 1148:                 {
 1149:                     if (compteur == clef)
 1150:                     {
 1151:                         l_element_courant = (*l_element_courant).suivant;
 1152:                         l_element_courant_format = (*l_element_courant_format)
 1153:                                 .suivant;
 1154:                         compteur++;
 1155:                         continue;
 1156:                     }
 1157: 
 1158:                     if ((s_element = allocation(s_etat_processus, LST)) == NULL)
 1159:                     {
 1160:                         (*s_etat_processus).erreur_systeme =
 1161:                                 d_es_allocation_memoire;
 1162:                         return;
 1163:                     }
 1164: 
 1165:                     if (((*s_element).objet =
 1166:                             allocation_maillon(s_etat_processus)) == NULL)
 1167:                     {
 1168:                         (*s_etat_processus).erreur_systeme =
 1169:                                 d_es_allocation_memoire;
 1170:                         return;
 1171:                     }
 1172: 
 1173:                     (*((struct_liste_chainee *) (*s_element).objet)).suivant
 1174:                             = NULL;
 1175: 
 1176:                     if ((s_format = allocation(s_etat_processus, LST)) == NULL)
 1177:                     {
 1178:                         (*s_etat_processus).erreur_systeme =
 1179:                                 d_es_allocation_memoire;
 1180:                         return;
 1181:                     }
 1182: 
 1183:                     if (((*s_format).objet =
 1184:                             allocation_maillon(s_etat_processus)) == NULL)
 1185:                     {
 1186:                         (*s_etat_processus).erreur_systeme =
 1187:                                 d_es_allocation_memoire;
 1188:                         return;
 1189:                     }
 1190: 
 1191:                     (*((struct_liste_chainee *) (*s_format).objet)).suivant
 1192:                             = NULL;
 1193: 
 1194:                     if (((*((struct_liste_chainee *) (*s_element).objet))
 1195:                             .donnee = copie_objet(s_etat_processus,
 1196:                             (*l_element_courant).donnee, 'N')) == NULL)
 1197:                     {
 1198:                         (*s_etat_processus).erreur_systeme =
 1199:                                 d_es_allocation_memoire;
 1200:                         return;
 1201:                     }
 1202: 
 1203:                     if (((*((struct_liste_chainee *) (*s_format).objet))
 1204:                             .donnee = copie_objet(s_etat_processus,
 1205:                             (*l_element_courant_format).donnee, 'N')) == NULL)
 1206:                     {
 1207:                         (*s_etat_processus).erreur_systeme =
 1208:                                 d_es_allocation_memoire;
 1209:                         return;
 1210:                     }
 1211: 
 1212:                     if ((chaine = formateur_fichier(s_etat_processus,
 1213:                             s_element, s_format, 0, 0, ' ',
 1214:                             'F', &longueur_effective, &recursivite)) == NULL)
 1215:                     {
 1216:                         free(clef_utf8);
 1217: 
 1218:                         liberation(s_etat_processus, s_element);
 1219:                         liberation(s_etat_processus, s_format);
 1220:                         liberation(s_etat_processus, s_objet_argument_2);
 1221:                         liberation(s_etat_processus, s_objet_argument_1);
 1222: 
 1223:                         return;
 1224:                     }
 1225: 
 1226:                     if ((chaine_utf8 = transliteration(s_etat_processus,
 1227:                             chaine, d_locale, "UTF-8")) == NULL)
 1228:                     {
 1229:                         free(clef_utf8);
 1230:                         free(chaine);
 1231: 
 1232:                         liberation(s_etat_processus, s_objet_argument_2);
 1233:                         liberation(s_etat_processus, s_objet_argument_1);
 1234: 
 1235:                         return;
 1236:                     }
 1237: 
 1238:                     free(chaine);
 1239: 
 1240:                     if (alsprintf(&commande, "insert into data "
 1241:                             "(data, key_id, sequence) values "
 1242:                             "('%s', %lld, %lld)", chaine_utf8, id, ordre) < 0)
 1243:                     {
 1244:                         (*s_etat_processus).erreur_systeme =
 1245:                                 d_es_allocation_memoire;
 1246:                         return;
 1247:                     }
 1248: 
 1249:                     if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite,
 1250:                             commande, strlen(commande), &ppStmt, &queue)
 1251:                             != SQLITE_OK)
 1252:                     {
 1253:                         (*s_etat_processus).erreur_systeme =
 1254:                                 d_es_erreur_fichier;
 1255:                         return;
 1256:                     }
 1257: 
 1258:                     if (sqlite3_step(ppStmt) != SQLITE_DONE)
 1259:                     {
 1260:                         (*s_etat_processus).erreur_systeme =
 1261:                                 d_es_erreur_fichier;
 1262:                         return;
 1263:                     }
 1264: 
 1265:                     if (sqlite3_finalize(ppStmt) != SQLITE_OK)
 1266:                     {
 1267:                         (*s_etat_processus).erreur_systeme =
 1268:                                 d_es_erreur_fichier;
 1269:                         return;
 1270:                     }
 1271: 
 1272:                     free(commande);
 1273:                     free(chaine_utf8);
 1274: 
 1275:                     liberation(s_etat_processus, s_element);
 1276:                     liberation(s_etat_processus, s_format);
 1277: 
 1278:                     l_element_courant = (*l_element_courant).suivant;
 1279:                     l_element_courant_format = (*l_element_courant_format)
 1280:                             .suivant;
 1281: 
 1282:                     compteur++;
 1283:                     ordre++;
 1284:                 }
 1285: 
 1286:                 free(clef_utf8);
 1287: 
 1288:                 if ((l_element_courant != NULL) ||
 1289:                         (l_element_courant_format != NULL))
 1290:                 {
 1291:                     liberation(s_etat_processus, s_objet_argument_1);
 1292:                     liberation(s_etat_processus, s_objet_argument_2);
 1293: 
 1294:                     (*s_etat_processus).erreur_execution =
 1295:                             d_ex_erreur_format_fichier;
 1296:                     return;
 1297:                 }
 1298:             }
 1299:         }
 1300:         else if ((*((struct_fichier *) (*s_objet_argument_1).objet)).binaire
 1301:                 == 'Y')
 1302:         {
 1303:             /*
 1304:              * Fichiers non formatés
 1305:              */
 1306: 
 1307:             if ((chaine = formateur_fichier(s_etat_processus,
 1308:                     s_objet_argument_2, (*((struct_fichier *)
 1309:                     (*s_objet_argument_1).objet)).format, 0, 0, ' ', 'U',
 1310:                     &longueur_effective, &recursivite)) == NULL)
 1311:             {
 1312:                 liberation(s_etat_processus, s_objet_argument_2);
 1313:                 liberation(s_etat_processus, s_objet_argument_1);
 1314: 
 1315:                 return;
 1316:             }
 1317: 
 1318:             if ((*((struct_fichier *) (*s_objet_argument_1).objet)).acces
 1319:                     == 'S')
 1320:             {
 1321:                 BUG(((*descripteur).type != 'C'), uprintf("Bad filetype !\n"));
 1322: 
 1323:                 if (fseek((*descripteur).descripteur_c, (long) 0, SEEK_END)
 1324:                         != 0)
 1325:                 {
 1326:                     liberation(s_etat_processus, s_objet_argument_2);
 1327:                     liberation(s_etat_processus, s_objet_argument_1);
 1328: 
 1329:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
 1330:                     return;
 1331:                 }
 1332: 
 1333:                 if (fwrite(chaine, sizeof(unsigned char), longueur_effective,
 1334:                         (*descripteur).descripteur_c) !=
 1335:                         (size_t) longueur_effective)
 1336:                 {
 1337:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
 1338:                     return;
 1339:                 }
 1340:             }
 1341:             else if ((*((struct_fichier *) (*s_objet_argument_1).objet)).acces
 1342:                     == 'D')
 1343:             {
 1344:             }
 1345:             else
 1346:             {
 1347:                 /* Fichiers indexés : panique totale ! */
 1348:             }
 1349: 
 1350:             free(chaine);
 1351:         }
 1352:         else
 1353:         {
 1354:             /*
 1355:              * Fichiers de type FLOW
 1356:              */
 1357: 
 1358:             if ((*((struct_fichier *) (*s_objet_argument_1).objet)).acces
 1359:                     == 'S')
 1360:             {
 1361:                 BUG(((*descripteur).type != 'C'), uprintf("Bad filetype !\n"));
 1362: 
 1363:                 if ((*s_objet_argument_2).type != LST)
 1364:                 {
 1365:                     liberation(s_etat_processus, s_objet_argument_2);
 1366:                     liberation(s_etat_processus, s_objet_argument_1);
 1367: 
 1368:                     (*s_etat_processus).erreur_execution =
 1369:                             d_ex_erreur_type_argument;
 1370:                     return;
 1371:                 }
 1372: 
 1373:                 if ((*((struct_liste_chainee *) (*s_objet_argument_2).objet))
 1374:                         .donnee == NULL)
 1375:                 {
 1376:                     liberation(s_etat_processus, s_objet_argument_2);
 1377:                     liberation(s_etat_processus, s_objet_argument_1);
 1378: 
 1379:                     (*s_etat_processus).erreur_execution =
 1380:                             d_ex_erreur_type_argument;
 1381:                     return;
 1382:                 }
 1383: 
 1384:                 l_element_courant = (*s_objet_argument_2).objet;
 1385:                 l_element_courant_format = (struct_liste_chainee *)
 1386:                         (*(*((struct_fichier *) (*s_objet_argument_1).objet))
 1387:                         .format).objet;
 1388: 
 1389:                 while((l_element_courant != NULL) &&
 1390:                         (l_element_courant_format != NULL))
 1391:                 {
 1392:                     if ((*(*l_element_courant).donnee).type != CHN)
 1393:                     {
 1394:                         liberation(s_etat_processus, s_objet_argument_2);
 1395:                         liberation(s_etat_processus, s_objet_argument_1);
 1396: 
 1397:                         (*s_etat_processus).erreur_execution =
 1398:                                 d_ex_erreur_type_argument;
 1399:                         return;
 1400:                     }
 1401: 
 1402:                     if ((*(*l_element_courant_format).donnee).type != CHN)
 1403:                     {
 1404:                         liberation(s_etat_processus, s_objet_argument_2);
 1405:                         liberation(s_etat_processus, s_objet_argument_1);
 1406: 
 1407:                         (*s_etat_processus).erreur_execution =
 1408:                                 d_ex_erreur_type_argument;
 1409:                         return;
 1410:                     }
 1411: 
 1412:                     if ((format_chaine = conversion_majuscule((unsigned char *)
 1413:                             (*(*l_element_courant_format).donnee).objet))
 1414:                             == NULL)
 1415:                     {
 1416:                         (*s_etat_processus).erreur_systeme =
 1417:                                 d_es_allocation_memoire;
 1418:                         return;
 1419:                     }
 1420: 
 1421:                     if (strncmp("LENGTH*(", format_chaine, 8) != 0)
 1422:                     {
 1423:                         free(format_chaine);
 1424: 
 1425:                         liberation(s_etat_processus, s_objet_argument_2);
 1426:                         liberation(s_etat_processus, s_objet_argument_1);
 1427: 
 1428:                         (*s_etat_processus).erreur_execution =
 1429:                                 d_ex_erreur_format_fichier;
 1430:                         return;
 1431:                     }
 1432: 
 1433:                     longueur = strlen(format_chaine);
 1434: 
 1435:                     if (format_chaine[longueur - 1] != ')')
 1436:                     {
 1437:                         free(format_chaine);
 1438: 
 1439:                         liberation(s_etat_processus, s_objet_argument_2);
 1440:                         liberation(s_etat_processus, s_objet_argument_1);
 1441: 
 1442:                         (*s_etat_processus).erreur_execution =
 1443:                                 d_ex_erreur_format_fichier;
 1444:                         return;
 1445:                     }
 1446: 
 1447:                     format_chaine[longueur] = d_code_fin_chaine;
 1448: 
 1449:                     if (format_chaine[8] == '*')
 1450:                     {
 1451:                         format_degenere = d_vrai;
 1452:                     }
 1453:                     else
 1454:                     {
 1455:                         // Détermination de la longueur
 1456:                         format_degenere = d_faux;
 1457: 
 1458:                         if (sscanf(&(format_chaine[8]), "%ld", &longueur) != 1)
 1459:                         {
 1460:                             free(format_chaine);
 1461: 
 1462:                             liberation(s_etat_processus, s_objet_argument_2);
 1463:                             liberation(s_etat_processus, s_objet_argument_1);
 1464: 
 1465:                             (*s_etat_processus).erreur_execution =
 1466:                                     d_ex_erreur_format_fichier;
 1467:                             return;
 1468:                         }
 1469:                     }
 1470: 
 1471:                     free(format_chaine);
 1472: 
 1473:                     if ((chaine = formateur_flux(s_etat_processus,
 1474:                             (unsigned char *) (*(*l_element_courant).donnee)
 1475:                             .objet, &longueur_effective)) == NULL)
 1476:                     {
 1477:                         (*s_etat_processus).erreur_systeme =
 1478:                                 d_es_allocation_memoire;
 1479:                         return;
 1480:                     }
 1481: 
 1482:                     if ((format_degenere == d_vrai) ||
 1483:                             (longueur_effective < longueur))
 1484:                     {
 1485:                         if (fwrite(chaine, sizeof(unsigned char),
 1486:                                 longueur_effective,
 1487:                                 (*descripteur).descripteur_c) !=
 1488:                                 (size_t) longueur_effective)
 1489:                         {
 1490:                             (*s_etat_processus).erreur_systeme =
 1491:                                     d_es_erreur_fichier;
 1492:                             return;
 1493:                         }
 1494:                     }
 1495:                     else
 1496:                     {
 1497:                         if (fwrite(chaine, sizeof(unsigned char),
 1498:                                 longueur_effective,
 1499:                                 (*descripteur).descripteur_c) !=
 1500:                                 (size_t) longueur)
 1501:                         {
 1502:                             (*s_etat_processus).erreur_systeme =
 1503:                                     d_es_erreur_fichier;
 1504:                             return;
 1505:                         }
 1506:                     }
 1507: 
 1508:                     free(chaine);
 1509: 
 1510:                     l_element_courant = (*l_element_courant).suivant;
 1511:                     l_element_courant_format = (*l_element_courant_format)
 1512:                             .suivant;
 1513:                 }
 1514: 
 1515:                 if ((l_element_courant_format != NULL) ||
 1516:                         (l_element_courant != NULL))
 1517:                 {
 1518:                     liberation(s_etat_processus, s_objet_argument_2);
 1519:                     liberation(s_etat_processus, s_objet_argument_1);
 1520: 
 1521:                     (*s_etat_processus).erreur_execution =
 1522:                             d_ex_erreur_format_fichier;
 1523:                     return;
 1524:                 }
 1525:             }
 1526:             else
 1527:             {
 1528:                 liberation(s_etat_processus, s_objet_argument_1);
 1529:                 liberation(s_etat_processus, s_objet_argument_2);
 1530: 
 1531:                 (*s_etat_processus).erreur_execution =
 1532:                         d_ex_erreur_type_fichier;
 1533:                 return;
 1534:             }
 1535:         }
 1536:     }
 1537:     else if (((*s_objet_argument_2).type == LST) &&
 1538:             ((*s_objet_argument_1).type == SCK))
 1539:     {
 1540:         /*
 1541:          * Vérification de l'autorisation d'écriture
 1542:          */
 1543: 
 1544:         if ((*((struct_socket *) (*s_objet_argument_1).objet))
 1545:                 .protection == 'R')
 1546:         {
 1547:             liberation(s_etat_processus, s_objet_argument_2);
 1548:             liberation(s_etat_processus, s_objet_argument_1);
 1549: 
 1550:             (*s_etat_processus).erreur_execution = d_ex_erreur_acces_fichier;
 1551:             return;
 1552:         }
 1553: 
 1554:         if ((*((struct_socket *) (*s_objet_argument_1).objet)).binaire == 'N')
 1555:         {
 1556:             /*
 1557:              * Sockets formatées
 1558:              */
 1559: 
 1560:             if ((chaine = formateur_fichier(s_etat_processus,
 1561:                     s_objet_argument_2, (*((struct_socket *)
 1562:                     (*s_objet_argument_1).objet)).format, 0, 0, ' ', 'F',
 1563:                     &longueur_effective, &recursivite)) == NULL)
 1564:             {
 1565:                 liberation(s_etat_processus, s_objet_argument_2);
 1566:                 liberation(s_etat_processus, s_objet_argument_1);
 1567: 
 1568:                 return;
 1569:             }
 1570:         }
 1571:         else if ((*((struct_socket *) (*s_objet_argument_1).objet)).binaire
 1572:                 == 'Y')
 1573:         {
 1574:             /*
 1575:              * Sockets non formatées
 1576:              */
 1577: 
 1578:             chaine = NULL;
 1579:         }
 1580:         else
 1581:         {
 1582:             /*
 1583:              *  Sockets de type FLOW
 1584:              */
 1585: 
 1586:             if ((*((*((struct_liste_chainee *) (*s_objet_argument_2).objet))
 1587:                     .donnee)).type != CHN)
 1588:             {
 1589:                 liberation(s_etat_processus, s_objet_argument_2);
 1590:                 liberation(s_etat_processus, s_objet_argument_1);
 1591: 
 1592:                 (*s_etat_processus).erreur_execution =
 1593:                         d_ex_erreur_type_argument;
 1594:                 return;
 1595:             }
 1596: 
 1597:             if ((chaine = formateur_flux(s_etat_processus, (unsigned char *)
 1598:                     (*((*((struct_liste_chainee *) (*s_objet_argument_2)
 1599:                     .objet)).donnee)).objet, &longueur_effective)) == NULL)
 1600:             {
 1601:                 liberation(s_etat_processus, s_objet_argument_2);
 1602:                 liberation(s_etat_processus, s_objet_argument_1);
 1603: 
 1604:                 return;
 1605:             }
 1606:         }
 1607: 
 1608:         if ((strcmp((*((struct_socket *) (*s_objet_argument_1).objet)).type,
 1609:                 "STREAM") == 0) || (strcmp((*((struct_socket *)
 1610:                 (*s_objet_argument_1).objet)).type,
 1611:                 "SEQUENTIAL DATAGRAM") == 0))
 1612:         { // Sockets connectées
 1613: 
 1614:             action.sa_handler = SIG_IGN;
 1615:             action.sa_flags = SA_ONSTACK;
 1616: 
 1617:             if (sigaction(SIGPIPE, &action, &registre) != 0)
 1618:             {
 1619:                 (*s_etat_processus).erreur_systeme = d_es_signal;
 1620:                 return;
 1621:             }
 1622: 
 1623: #           ifndef SEMAPHORES_NOMMES
 1624:                 if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
 1625: #           else
 1626:                 if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 1627: #           endif
 1628:             {
 1629:                 if (sigaction(SIGPIPE, &registre, NULL) != 0)
 1630:                 {
 1631:                     (*s_etat_processus).erreur_systeme = d_es_signal;
 1632:                     return;
 1633:                 }
 1634: 
 1635:                 (*s_etat_processus).erreur_systeme = d_es_processus;
 1636:                 return;
 1637:             }
 1638: 
 1639:             if (send((*((struct_socket *) (*s_objet_argument_1).objet))
 1640:                     .socket, chaine, longueur_effective, 0) < 0)
 1641:             {
 1642:                 ios = errno;
 1643: 
 1644:                 if (sigaction(SIGPIPE, &registre, NULL) != 0)
 1645:                 {
 1646:                     (*s_etat_processus).erreur_systeme = d_es_signal;
 1647:                     return;
 1648:                 }
 1649: 
 1650: #               ifndef SEMAPHORES_NOMMES
 1651:                     while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
 1652: #               else
 1653:                     while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
 1654: #               endif
 1655:                 {
 1656:                     if (errno != EINTR)
 1657:                     {
 1658:                         (*s_etat_processus).erreur_systeme = d_es_processus;
 1659:                         return;
 1660:                     }
 1661:                 }
 1662: 
 1663:                 if ((ios == EPIPE) || (ios == ECONNRESET))
 1664:                 {
 1665:                     (*s_etat_processus).erreur_execution =
 1666:                             d_ex_erreur_acces_fichier;
 1667:                     return;
 1668:                 }
 1669: 
 1670:                 (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
 1671:                 return;
 1672:             }
 1673: 
 1674: #           ifndef SEMAPHORES_NOMMES
 1675:                 while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
 1676: #           else
 1677:                 while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
 1678: #           endif
 1679:             {
 1680:                 if (errno != EINTR)
 1681:                 {
 1682:                     if (sigaction(SIGPIPE, &registre, NULL) != 0)
 1683:                     {
 1684:                         (*s_etat_processus).erreur_systeme = d_es_signal;
 1685:                         return;
 1686:                     }
 1687: 
 1688:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 1689:                     return;
 1690:                 }
 1691:             }
 1692: 
 1693:             if (sigaction(SIGPIPE, &registre, NULL) != 0)
 1694:             {
 1695:                 (*s_etat_processus).erreur_systeme = d_es_signal;
 1696:                 return;
 1697:             }
 1698:         }
 1699:         else
 1700:         { // Sockets non connectées
 1701: 
 1702:             /*
 1703:              * Vérification de l'adresse distante
 1704:              */
 1705: 
 1706:             if (strcmp((*((struct_socket *) (*s_objet_argument_1).objet))
 1707:                     .adresse_distante, "") == 0)
 1708:             {
 1709:                 liberation(s_etat_processus, s_objet_argument_1);
 1710:                 liberation(s_etat_processus, s_objet_argument_2);
 1711: 
 1712:                 (*s_etat_processus).erreur_execution =
 1713:                         d_ex_erreur_acces_fichier;
 1714:                 return;
 1715:             }
 1716: 
 1717:             /*
 1718:              * Création de l'adresse logique
 1719:              */
 1720: 
 1721:             if ((*((struct_socket *) (*s_objet_argument_1).objet))
 1722:                     .domaine == PF_UNIX)
 1723:             {
 1724:                 adresse_unix.sun_family = AF_UNIX;
 1725:                 strncpy(adresse_unix.sun_path, (*((struct_socket *)
 1726:                         (*s_objet_argument_1).objet)).adresse_distante,
 1727:                         UNIX_PATH_MAX);
 1728:                 adresse_unix.sun_path[UNIX_PATH_MAX - 1] =
 1729:                         d_code_fin_chaine;
 1730: 
 1731: #               ifndef SEMAPHORES_NOMMES
 1732:                     if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
 1733: #               else
 1734:                     if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 1735: #               endif
 1736:                 {
 1737:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 1738:                     return;
 1739:                 }
 1740: 
 1741:                 if (sendto((*((struct_socket *)
 1742:                         (*s_objet_argument_1).objet)).socket, chaine,
 1743:                         longueur_effective, 0, (struct sockaddr *)
 1744:                         &adresse_unix, sizeof(adresse_unix)) < 0)
 1745:                 {
 1746:                     ios = errno;
 1747: 
 1748: #                   ifndef SEMAPHORES_NOMMES
 1749:                         while(sem_wait(&((*s_etat_processus).semaphore_fork))
 1750:                                 != 0)
 1751: #                   else
 1752:                         while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
 1753: #                   endif
 1754:                     {
 1755:                         if (errno != EINTR)
 1756:                         {
 1757:                             (*s_etat_processus).erreur_systeme = d_es_processus;
 1758:                             return;
 1759:                         }
 1760:                     }
 1761: 
 1762:                     if ((ios == EPIPE) || (ios == ECONNRESET))
 1763:                     {
 1764:                         (*s_etat_processus).erreur_execution =
 1765:                                 d_ex_erreur_acces_fichier;
 1766:                         return;
 1767:                     }
 1768: 
 1769:                     if (ios == EMSGSIZE)
 1770:                     {
 1771:                         (*s_etat_processus).erreur_execution =
 1772:                                 d_ex_taille_message;
 1773:                     }
 1774: 
 1775:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
 1776:                     return;
 1777:                 }
 1778: 
 1779: #               ifndef SEMAPHORES_NOMMES
 1780:                     while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
 1781: #               else
 1782:                     while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
 1783: #               endif
 1784:                 {
 1785:                     if (errno != EINTR)
 1786:                     {
 1787:                         (*s_etat_processus).erreur_systeme = d_es_processus;
 1788:                         return;
 1789:                     }
 1790:                 }
 1791:             }
 1792:             else if ((*((struct_socket *) (*s_objet_argument_1).objet))
 1793:                     .domaine == PF_INET)
 1794:             {
 1795:                 if (sscanf((*((struct_socket *)
 1796:                         (*s_objet_argument_1).objet))
 1797:                         .adresse_distante, "%d.%d.%d.%d(%d)",
 1798:                         &(adresse[0]), &(adresse[1]), &(adresse[2]),
 1799:                         &(adresse[3]), &port) == 5)
 1800:                 { // Adresse IPv4
 1801:                     calcul_adresse = 0;
 1802:                     for(i = 0; i < 4; calcul_adresse =
 1803:                             (256 * calcul_adresse) + adresse[i++]);
 1804: 
 1805:                     memset(&adresse_ipv4, 0, sizeof(adresse_ipv4));
 1806:                     adresse_ipv4.sin_family = AF_INET;
 1807:                     adresse_ipv4.sin_port = htons(port);
 1808:                     adresse_ipv4.sin_addr.s_addr = htonl(calcul_adresse);
 1809: 
 1810: #                   ifndef SEMAPHORES_NOMMES
 1811:                         if (sem_post(&((*s_etat_processus).semaphore_fork))
 1812:                                 != 0)
 1813: #                   else
 1814:                         if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 1815: #                   endif
 1816:                     {
 1817:                         (*s_etat_processus).erreur_systeme = d_es_processus;
 1818:                         return;
 1819:                     }
 1820: 
 1821:                     if (sendto((*((struct_socket *)
 1822:                             (*s_objet_argument_1).objet)).socket, chaine,
 1823:                             longueur_effective, 0, (struct sockaddr *)
 1824:                             &adresse_ipv4, sizeof(adresse_ipv4)) < 0)
 1825:                     {
 1826: #                       ifndef SEMAPHORES_NOMMES
 1827:                             while(sem_wait(&((*s_etat_processus)
 1828:                                     .semaphore_fork)) != 0)
 1829: #                       else
 1830:                             while(sem_wait((*s_etat_processus)
 1831:                                     .semaphore_fork) != 0)
 1832: #                       endif
 1833:                         {
 1834:                             if (errno != EINTR)
 1835:                             {
 1836:                                 (*s_etat_processus).erreur_systeme =
 1837:                                         d_es_processus;
 1838:                                 return;
 1839:                             }
 1840:                         }
 1841: 
 1842:                         (*s_etat_processus).erreur_systeme =
 1843:                                 d_es_erreur_fichier;
 1844:                         return;
 1845:                     }
 1846: 
 1847: #                   ifndef SEMAPHORES_NOMMES
 1848:                         while(sem_wait(&((*s_etat_processus).semaphore_fork))
 1849:                                 != 0)
 1850: #                   else
 1851:                         while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
 1852: #                   endif
 1853:                     {
 1854:                         if (errno != EINTR)
 1855:                         {
 1856:                             (*s_etat_processus).erreur_systeme = d_es_processus;
 1857:                             return;
 1858:                         }
 1859:                     }
 1860:                 }
 1861:                 else
 1862:                 {
 1863:                     liberation(s_etat_processus, s_objet_argument_1);
 1864:                     liberation(s_etat_processus, s_objet_argument_2);
 1865: 
 1866:                     (*s_etat_processus).erreur_execution =
 1867:                             d_ex_erreur_parametre_fichier;
 1868:                     return;
 1869:                 }
 1870:             }
 1871:             else if ((*((struct_socket *) (*s_objet_argument_1).objet))
 1872:                     .domaine == PF_INET6)
 1873:             {
 1874:                 if (sscanf((*((struct_socket *) (*s_objet_argument_1)
 1875:                         .objet)).adresse_distante, "%X:%X:%X:%X:%X:"
 1876:                         "%X:%X:%X:%X:%X:%X:%X:%X:%X:%X:%X(%d)",
 1877:                         &(adresse[0]), &(adresse[1]), &(adresse[2]),
 1878:                         &(adresse[3]), &(adresse[4]), &(adresse[5]),
 1879:                         &(adresse[6]), &(adresse[7]), &(adresse[8]),
 1880:                         &(adresse[9]), &(adresse[10]), &(adresse[11]),
 1881:                         &(adresse[12]), &(adresse[13]), &(adresse[14]),
 1882:                         &(adresse[15]), &port)== 17)
 1883:                 { // Adresse IPv6
 1884: #                   ifdef IPV6
 1885:                     memset(&adresse_ipv6, 0, sizeof(adresse_ipv6));
 1886:                     adresse_ipv6.sin6_family = AF_INET6;
 1887:                     adresse_ipv6.sin6_port = htons((uint16_t) port);
 1888: 
 1889:                     for(i = 0; i < 16;
 1890:                             adresse_ipv6.sin6_addr.s6_addr[i] =
 1891:                             adresse[i], i++);
 1892: 
 1893: #                   ifndef SEMAPHORES_NOMMES
 1894:                         if (sem_post(&((*s_etat_processus).semaphore_fork))
 1895:                                 != 0)
 1896: #                   else
 1897:                         if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 1898: #                   endif
 1899:                     {
 1900:                         (*s_etat_processus).erreur_systeme = d_es_processus;
 1901:                         return;
 1902:                     }
 1903: 
 1904:                     if (sendto((*((struct_socket *)
 1905:                             (*s_objet_argument_1).objet)).socket, chaine,
 1906:                             longueur_effective, 0, (struct sockaddr *)
 1907:                             &adresse_ipv6, sizeof(adresse_ipv6)) < 0)
 1908:                     {
 1909: #                       ifndef SEMAPHORES_NOMMES
 1910:                             while(sem_wait(&((*s_etat_processus)
 1911:                                     .semaphore_fork)) != 0)
 1912: #                       else
 1913:                             while(sem_wait((*s_etat_processus)
 1914:                                     .semaphore_fork) != 0)
 1915: #                       endif
 1916:                         {
 1917:                             if (errno != EINTR)
 1918:                             {
 1919:                                 (*s_etat_processus).erreur_systeme =
 1920:                                         d_es_processus;
 1921:                                 return;
 1922:                             }
 1923:                         }
 1924: 
 1925:                         (*s_etat_processus).erreur_systeme =
 1926:                                 d_es_erreur_fichier;
 1927:                         return;
 1928:                     }
 1929: 
 1930: #                   ifndef SEMAPHORES_NOMMES
 1931:                         while(sem_wait(&((*s_etat_processus).semaphore_fork))
 1932:                                 != 0)
 1933: #                   else
 1934:                         while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
 1935: #                   endif
 1936:                     {
 1937:                         if (errno != EINTR)
 1938:                         {
 1939:                             (*s_etat_processus).erreur_systeme =
 1940:                                     d_es_processus;
 1941:                             return;
 1942:                         }
 1943:                     }
 1944: #                   else
 1945:                     if ((*s_etat_processus).langue == 'F')
 1946:                     {
 1947:                         printf("+++Attention : Support du protocole"
 1948:                                 " IPv6 indisponible\n");
 1949:                     }
 1950:                     else
 1951:                     {
 1952:                         printf("+++Warning : IPv6 support "
 1953:                                 "unavailable\n");
 1954:                     }
 1955: #                   endif
 1956:                 }
 1957:                 else
 1958:                 {
 1959:                     liberation(s_etat_processus, s_objet_argument_1);
 1960:                     liberation(s_etat_processus, s_objet_argument_2);
 1961: 
 1962:                     (*s_etat_processus).erreur_execution =
 1963:                             d_ex_erreur_parametre_fichier;
 1964:                     return;
 1965:                 }
 1966:             }
 1967:             else 
 1968:             {
 1969:                 liberation(s_etat_processus, s_objet_argument_1);
 1970:                 liberation(s_etat_processus, s_objet_argument_2);
 1971: 
 1972:                 (*s_etat_processus).erreur_execution =
 1973:                         d_ex_erreur_parametre_fichier;
 1974:                 return;
 1975:             }
 1976:         }
 1977: 
 1978:         free(chaine);
 1979:     }
 1980:     else
 1981:     {
 1982:         liberation(s_etat_processus, s_objet_argument_2);
 1983:         liberation(s_etat_processus, s_objet_argument_1);
 1984: 
 1985:         (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
 1986:         return;
 1987:     }
 1988: 
 1989:     liberation(s_etat_processus, s_objet_argument_2);
 1990:     liberation(s_etat_processus, s_objet_argument_1);
 1991: 
 1992:     return;
 1993: }
 1994: 
 1995: 
 1996: /*
 1997: ================================================================================
 1998:   Fonction 'wflock'
 1999: ================================================================================
 2000:   Entrées : pointeur sur une structure struct_processus
 2001: --------------------------------------------------------------------------------
 2002:   Sorties :
 2003: --------------------------------------------------------------------------------
 2004:   Effets de bord : néant
 2005: ================================================================================
 2006: */
 2007: 
 2008: void
 2009: instruction_wflock(struct_processus *s_etat_processus)
 2010: {
 2011:     logical1                    drapeau;
 2012: 
 2013:     struct flock                lock;
 2014: 
 2015:     struct timespec             attente;
 2016: 
 2017:     struct_descripteur_fichier  *descripteur;
 2018: 
 2019:     struct_objet                *s_objet_argument_1;
 2020:     struct_objet                *s_objet_argument_2;
 2021: 
 2022:     unsigned char               *chaine;
 2023:     unsigned char               registre_instruction_valide;
 2024: 
 2025:     attente.tv_sec = 0;
 2026:     attente.tv_nsec = GRANULARITE_us * 1000;
 2027: 
 2028:     (*s_etat_processus).erreur_execution = d_ex;
 2029: 
 2030:     if ((*s_etat_processus).affichage_arguments == 'Y')
 2031:     {
 2032:         printf("\n  WFLOCK ");
 2033:         
 2034:         if ((*s_etat_processus).langue == 'F')
 2035:         {
 2036:             printf("(attente du positionnement d'un verrou sur un fichier)"
 2037:                     "\n\n");
 2038:         }
 2039:         else
 2040:         {
 2041:             printf("(wait for file lock)\n\n");
 2042:         }
 2043: 
 2044:         printf("    2: %s\n", d_FCH);
 2045:         printf("    1: %s (READ/WRITE/NONE)\n", d_CHN);
 2046: 
 2047:         return;
 2048:     }
 2049:     else if ((*s_etat_processus).test_instruction == 'Y')
 2050:     {
 2051:         (*s_etat_processus).nombre_arguments = -1;
 2052:         return;
 2053:     }
 2054: 
 2055:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
 2056:     {
 2057:         if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
 2058:         {
 2059:             return;
 2060:         }
 2061:     }
 2062: 
 2063:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
 2064:             &s_objet_argument_1) == d_erreur)
 2065:     {
 2066:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
 2067:         return;
 2068:     }
 2069: 
 2070:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
 2071:             &s_objet_argument_2) == d_erreur)
 2072:     {
 2073:         liberation(s_etat_processus, s_objet_argument_1);
 2074: 
 2075:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
 2076:         return;
 2077:     }
 2078: 
 2079:     if (((*s_objet_argument_2).type == FCH) &&
 2080:             ((*s_objet_argument_1).type == CHN))
 2081:     {
 2082:         drapeau = d_faux;
 2083: 
 2084:         do
 2085:         {
 2086:             if ((chaine = conversion_majuscule((unsigned char *)
 2087:                     (*s_objet_argument_1).objet)) == NULL)
 2088:             {
 2089:                 (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
 2090:                 return;
 2091:             }
 2092: 
 2093:             if (strcmp(chaine, "WRITE") == 0)
 2094:             {
 2095:                 lock.l_type = F_WRLCK;
 2096:             }
 2097:             else if (strcmp(chaine, "READ") == 0)
 2098:             {
 2099:                 lock.l_type = F_RDLCK;
 2100:             }
 2101:             else if (strcmp(chaine, "NONE") == 0)
 2102:             {
 2103:                 lock.l_type = F_UNLCK;
 2104:             }
 2105:             else
 2106:             {
 2107:                 free(chaine);
 2108: 
 2109:                 liberation(s_etat_processus, s_objet_argument_1);
 2110:                 liberation(s_etat_processus, s_objet_argument_2);
 2111: 
 2112:                 (*s_etat_processus).erreur_execution = d_ex_verrou_indefini;
 2113:                 return;
 2114:             }
 2115: 
 2116:             free(chaine);
 2117: 
 2118:             lock.l_whence = SEEK_SET;
 2119:             lock.l_start = 0;
 2120:             lock.l_len = 0;
 2121:             lock.l_pid = getpid();
 2122: 
 2123:             if ((descripteur = descripteur_fichier(s_etat_processus,
 2124:                     (struct_fichier *) (*s_objet_argument_2).objet)) == NULL)
 2125:             {
 2126:                 return;
 2127:             }
 2128: 
 2129:             if (fcntl(fileno((*descripteur).descripteur_c), F_GETLK, &lock)
 2130:                     == -1)
 2131:             {
 2132:                 liberation(s_etat_processus, s_objet_argument_1);
 2133:                 liberation(s_etat_processus, s_objet_argument_2);
 2134: 
 2135:                 (*s_etat_processus).erreur_execution = d_ex_fichier_verrouille;
 2136:                 return;
 2137:             }
 2138: 
 2139: #           ifndef SEMAPHORES_NOMMES
 2140:                 if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
 2141: #           else
 2142:                 if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 2143: #           endif
 2144:             {
 2145:                 (*s_etat_processus).erreur_systeme = d_es_processus;
 2146:                 return;
 2147:             }
 2148: 
 2149: #           ifndef SEMAPHORES_NOMMES
 2150:                 while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
 2151: #           else
 2152:                 while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
 2153: #           endif
 2154:             {
 2155:                 if (errno != EINTR)
 2156:                 {
 2157:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 2158:                     return;
 2159:                 }
 2160:             }
 2161: 
 2162:             if (lock.l_type == F_UNLCK)
 2163:             {
 2164:                 drapeau = d_vrai;
 2165:             }
 2166:             else
 2167:             {
 2168:                 if ((*s_etat_processus).nombre_interruptions_non_affectees != 0)
 2169:                 {
 2170:                     affectation_interruptions_logicielles(s_etat_processus);
 2171:                 }
 2172: 
 2173:                 if ((*s_etat_processus).nombre_interruptions_en_queue
 2174:                         != 0)
 2175:                 {
 2176:                     registre_instruction_valide =
 2177:                             (*s_etat_processus).instruction_valide;
 2178:                     traitement_interruptions_logicielles(
 2179:                             s_etat_processus);
 2180:                     (*s_etat_processus).instruction_valide =
 2181:                             registre_instruction_valide;
 2182:                 }
 2183: 
 2184:                 nanosleep(&attente, NULL);
 2185:                 scrutation_injection(s_etat_processus);
 2186: 
 2187:                 INCR_GRANULARITE(attente.tv_nsec);
 2188:             }
 2189:         } while((drapeau == d_faux) && ((*s_etat_processus)
 2190:                 .var_volatile_requete_arret != -1));
 2191:     }
 2192:     else
 2193:     {
 2194:         liberation(s_etat_processus, s_objet_argument_1);
 2195:         liberation(s_etat_processus, s_objet_argument_2);
 2196: 
 2197:         (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
 2198:         return;
 2199:     }
 2200: 
 2201:     return;
 2202: }
 2203: 
 2204: 
 2205: /*
 2206: ================================================================================
 2207:   Fonction 'wfproc'
 2208: ================================================================================
 2209:   Entrées : pointeur sur une structure struct_processus
 2210: --------------------------------------------------------------------------------
 2211:   Sorties :
 2212: --------------------------------------------------------------------------------
 2213:   Effets de bord : néant
 2214: ================================================================================
 2215: */
 2216: 
 2217: void
 2218: instruction_wfproc(struct_processus *s_etat_processus)
 2219: {
 2220:     logical1                    drapeau_fin;
 2221: 
 2222:     struct_liste_chainee        *l_element_courant;
 2223: 
 2224:     struct_objet                *s_objet_argument;
 2225: 
 2226:     struct timespec             attente;
 2227: 
 2228:     unsigned char               registre_instruction_valide;
 2229: 
 2230:     (*s_etat_processus).erreur_execution = d_ex;
 2231: 
 2232:     attente.tv_sec = 0;
 2233:     attente.tv_nsec = GRANULARITE_us * 1000;
 2234: 
 2235:     if ((*s_etat_processus).affichage_arguments == 'Y')
 2236:     {
 2237:         printf("\n  WFPROC ");
 2238: 
 2239:         if ((*s_etat_processus).langue == 'F')
 2240:         {
 2241:             printf("(attente de la fin d'un processus fils)\n\n");
 2242:         }
 2243:         else
 2244:         {
 2245:             printf("(wait for child process end)\n\n");
 2246:         }
 2247: 
 2248:         printf("    1: %s\n", d_PRC);
 2249: 
 2250:         return;
 2251:     }
 2252:     else if ((*s_etat_processus).test_instruction == 'Y')
 2253:     {
 2254:         (*s_etat_processus).nombre_arguments = -1;
 2255:         return;
 2256:     }
 2257: 
 2258:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
 2259:     {
 2260:         if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
 2261:         {
 2262:             return;
 2263:         }
 2264:     }
 2265: 
 2266:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
 2267:             &s_objet_argument) == d_erreur)
 2268:     {
 2269:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
 2270:         return;
 2271:     }
 2272: 
 2273:     if ((*s_objet_argument).type == PRC)
 2274:     {
 2275:         drapeau_fin = d_faux;
 2276: 
 2277:         if ((*s_etat_processus).profilage == d_vrai)
 2278:         {
 2279:             profilage(s_etat_processus, "Interprocess or interthread "
 2280:                     "communications (WFPROC)");
 2281: 
 2282:             if ((*s_etat_processus).erreur_systeme != d_es)
 2283:             {
 2284:                 return;
 2285:             }
 2286:         }
 2287: 
 2288:         if (pthread_mutex_lock(&((*s_etat_processus).mutex)) != 0)
 2289:         {
 2290:             if ((*s_etat_processus).profilage == d_vrai)
 2291:             {
 2292:                 profilage(s_etat_processus, NULL);
 2293:             }
 2294: 
 2295:             (*s_etat_processus).erreur_systeme = d_es_processus;
 2296:             return;
 2297:         }
 2298: 
 2299:         while(drapeau_fin == d_faux)
 2300:         {
 2301:             l_element_courant = (struct_liste_chainee *)
 2302:                     (*s_etat_processus).l_base_pile_processus;
 2303: 
 2304:             while(l_element_courant != NULL)
 2305:             {
 2306:                 if ((*(*((struct_processus_fils *) (*(*l_element_courant)
 2307:                         .donnee).objet)).thread).processus_detache == d_vrai)
 2308:                 {
 2309:                     if ((*(*((struct_processus_fils *)
 2310:                             (*s_objet_argument).objet)).thread)
 2311:                             .processus_detache == d_vrai)
 2312:                     {
 2313:                         if ((*(*((struct_processus_fils *)
 2314:                                 (*(*l_element_courant)
 2315:                                 .donnee).objet)).thread).pid ==
 2316:                                 (*(*((struct_processus_fils *)
 2317:                                 (*s_objet_argument).objet)).thread).pid)
 2318:                         {
 2319:                             break;
 2320:                         }
 2321:                     }
 2322:                 }
 2323:                 else
 2324:                 {
 2325:                     if ((*(*((struct_processus_fils *)
 2326:                             (*s_objet_argument).objet)).thread)
 2327:                             .processus_detache == d_faux)
 2328:                     {
 2329:                         if ((pthread_equal((*(*((struct_processus_fils *)
 2330:                                 (*(*l_element_courant).donnee).objet)).thread)
 2331:                                 .tid, (*(*((struct_processus_fils *)
 2332:                                 (*s_objet_argument).objet)).thread).tid) != 0)
 2333:                                 && ((*(*((struct_processus_fils *)
 2334:                                 (*(*l_element_courant).donnee).objet)).thread)
 2335:                                 .pid == (*(*((struct_processus_fils *)
 2336:                                 (*s_objet_argument).objet)).thread).pid))
 2337:                         {
 2338:                             break;
 2339:                         }
 2340:                     }
 2341:                 }
 2342: 
 2343:                 l_element_courant = (*l_element_courant).suivant;
 2344:             }
 2345: 
 2346:             if ((*s_etat_processus).var_volatile_requete_arret != 0)
 2347:             {
 2348:                 if ((*s_etat_processus).profilage == d_vrai)
 2349:                 {
 2350:                     profilage(s_etat_processus, NULL);
 2351:                 }
 2352: 
 2353:                 if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
 2354:                 {
 2355:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 2356:                     return;
 2357:                 }
 2358: 
 2359:                 liberation(s_etat_processus, s_objet_argument);
 2360:                 return;
 2361:             }
 2362: 
 2363:             if (l_element_courant == NULL)
 2364:             {
 2365:                 /*
 2366:                  * Si l_element_courant vaut NULL, le processus n'existe plus.
 2367:                  */
 2368: 
 2369:                 drapeau_fin = d_vrai;
 2370:             }
 2371:             else
 2372:             {
 2373:                 if ((*(*((struct_processus_fils *) (*(*l_element_courant)
 2374:                         .donnee).objet)).thread).processus_detache == d_vrai)
 2375:                 {
 2376:                     if (envoi_signal_processus((*(*((struct_processus_fils *)
 2377:                             (*(*l_element_courant).donnee).objet)).thread).pid,
 2378:                             rpl_signull) != 0)
 2379:                     {
 2380:                         drapeau_fin = d_vrai;
 2381:                     }
 2382:                     else
 2383:                     {
 2384:                         drapeau_fin = d_faux;
 2385:                     }
 2386:                 }
 2387:                 else
 2388:                 {
 2389:                     if (pthread_mutex_lock(&((*(*((struct_processus_fils *)
 2390:                             (*(*l_element_courant).donnee).objet)).thread)
 2391:                             .mutex)) != 0)
 2392:                     {
 2393:                         if ((*s_etat_processus).profilage == d_vrai)
 2394:                         {
 2395:                             profilage(s_etat_processus, NULL);
 2396:                         }
 2397: 
 2398:                         (*s_etat_processus).erreur_systeme = d_es_processus;
 2399:                         return;
 2400:                     }
 2401: 
 2402:                     if ((*(*((struct_processus_fils *)
 2403:                             (*(*l_element_courant).donnee).objet)).thread)
 2404:                             .thread_actif == d_faux)
 2405:                     {
 2406:                         drapeau_fin = d_vrai;
 2407:                     }
 2408:                     else
 2409:                     {
 2410:                         drapeau_fin = d_faux;
 2411:                     }
 2412: 
 2413:                     if (pthread_mutex_unlock(&((*(*((struct_processus_fils *)
 2414:                             (*(*l_element_courant).donnee).objet)).thread)
 2415:                             .mutex)) != 0)
 2416:                     {
 2417:                         if ((*s_etat_processus).profilage == d_vrai)
 2418:                         {
 2419:                             profilage(s_etat_processus, NULL);
 2420:                         }
 2421: 
 2422:                         (*s_etat_processus).erreur_systeme = d_es_processus;
 2423:                         return;
 2424:                     }
 2425:                 }
 2426: 
 2427:                 if (drapeau_fin == d_faux)
 2428:                 {
 2429:                     /*
 2430:                      * Le processus n'est pas terminé
 2431:                      */
 2432: 
 2433:                     if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
 2434:                     {
 2435:                         if ((*s_etat_processus).profilage == d_vrai)
 2436:                         {
 2437:                             profilage(s_etat_processus, NULL);
 2438:                         }
 2439: 
 2440:                         (*s_etat_processus).erreur_systeme =
 2441:                                 d_es_processus;
 2442:                         return;
 2443:                     }
 2444: 
 2445:                     if ((*s_etat_processus).nombre_interruptions_non_affectees
 2446:                             != 0)
 2447:                     {
 2448:                         affectation_interruptions_logicielles(s_etat_processus);
 2449:                     }
 2450: 
 2451:                     if ((*s_etat_processus).nombre_interruptions_en_queue
 2452:                             != 0)
 2453:                     {
 2454:                         registre_instruction_valide =
 2455:                                 (*s_etat_processus).instruction_valide;
 2456:                         traitement_interruptions_logicielles(
 2457:                                 s_etat_processus);
 2458:                         (*s_etat_processus).instruction_valide =
 2459:                                 registre_instruction_valide;
 2460:                     }
 2461: 
 2462: #                   ifndef SEMAPHORES_NOMMES
 2463:                         if (sem_post(&((*s_etat_processus).semaphore_fork))
 2464:                                 != 0)
 2465: #                   else
 2466:                         if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 2467: #                   endif
 2468:                     {
 2469:                         (*s_etat_processus).erreur_systeme = d_es_processus;
 2470:                         return;
 2471:                     }
 2472: 
 2473:                     nanosleep(&attente, NULL);
 2474: 
 2475: #                   ifndef SEMAPHORES_NOMMES
 2476:                         while(sem_wait(&((*s_etat_processus).semaphore_fork))
 2477:                                 != 0)
 2478: #                   else
 2479:                         while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
 2480: #                   endif
 2481:                     {
 2482:                         if (errno != EINTR)
 2483:                         {
 2484:                             (*s_etat_processus).erreur_systeme = d_es_processus;
 2485:                             return;
 2486:                         }
 2487:                     }
 2488: 
 2489:                     scrutation_injection(s_etat_processus);
 2490: 
 2491:                     if (pthread_mutex_lock(&((*s_etat_processus).mutex)) != 0)
 2492:                     {
 2493:                         if ((*s_etat_processus).profilage == d_vrai)
 2494:                         {
 2495:                             profilage(s_etat_processus, NULL);
 2496:                         }
 2497: 
 2498:                         (*s_etat_processus).erreur_systeme =
 2499:                                 d_es_processus;
 2500:                         return;
 2501:                     }
 2502:                 }
 2503:             }
 2504: 
 2505:             INCR_GRANULARITE(attente.tv_nsec);
 2506:         }
 2507: 
 2508:         if ((*s_etat_processus).profilage == d_vrai)
 2509:         {
 2510:             profilage(s_etat_processus, NULL);
 2511:         }
 2512: 
 2513:         if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
 2514:         {
 2515:             (*s_etat_processus).erreur_systeme = d_es_processus;
 2516:             return;
 2517:         }
 2518:     }
 2519:     else
 2520:     {
 2521:         liberation(s_etat_processus, s_objet_argument);
 2522: 
 2523:         (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
 2524:         return;
 2525:     }
 2526: 
 2527:     liberation(s_etat_processus, s_objet_argument);
 2528: 
 2529:     return;
 2530: }
 2531: 
 2532: 
 2533: /*
 2534: ================================================================================
 2535:   Fonction 'wfdata'
 2536: ================================================================================
 2537:   Entrées : pointeur sur une structure struct_processus
 2538: --------------------------------------------------------------------------------
 2539:   Sorties :
 2540: --------------------------------------------------------------------------------
 2541:   Effets de bord : néant
 2542: ================================================================================
 2543: */
 2544: 
 2545: void
 2546: instruction_wfdata(struct_processus *s_etat_processus)
 2547: {
 2548:     logical1                    drapeau_fin;
 2549: 
 2550:     struct_liste_chainee        *l_element_courant;
 2551: 
 2552:     struct_objet                *s_objet_argument;
 2553: 
 2554:     struct timespec             attente;
 2555: 
 2556:     unsigned char               registre_instruction_valide;
 2557: 
 2558:     (*s_etat_processus).erreur_execution = d_ex;
 2559: 
 2560:     attente.tv_sec = 0;
 2561:     attente.tv_nsec = GRANULARITE_us * 1000;
 2562: 
 2563:     if ((*s_etat_processus).affichage_arguments == 'Y')
 2564:     {
 2565:         printf("\n  WFDATA ");
 2566: 
 2567:         if ((*s_etat_processus).langue == 'F')
 2568:         {
 2569:             printf("(attente de données d'un processus fils)\n\n");
 2570:         }
 2571:         else
 2572:         {
 2573:             printf("(wait for data from child process)\n\n");
 2574:         }
 2575: 
 2576:         printf("    1: %s\n", d_PRC);
 2577: 
 2578:         return;
 2579:     }
 2580:     else if ((*s_etat_processus).test_instruction == 'Y')
 2581:     {
 2582:         (*s_etat_processus).nombre_arguments = -1;
 2583:         return;
 2584:     }
 2585: 
 2586:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
 2587:     {
 2588:         if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
 2589:         {
 2590:             return;
 2591:         }
 2592:     }
 2593: 
 2594:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
 2595:             &s_objet_argument) == d_erreur)
 2596:     {
 2597:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
 2598:         return;
 2599:     }
 2600: 
 2601:     if ((*s_objet_argument).type == PRC)
 2602:     {
 2603:         drapeau_fin = d_faux;
 2604: 
 2605:         if ((*s_etat_processus).profilage == d_vrai)
 2606:         {
 2607:             profilage(s_etat_processus, "Interprocess or interthread "
 2608:                     "communications (WFDATA)");
 2609: 
 2610:             if ((*s_etat_processus).erreur_systeme != d_es)
 2611:             {
 2612:                 return;
 2613:             }
 2614:         }
 2615: 
 2616:         if (pthread_mutex_lock(&((*s_etat_processus).mutex)) != 0)
 2617:         {
 2618:             if ((*s_etat_processus).profilage == d_vrai)
 2619:             {
 2620:                 profilage(s_etat_processus, NULL);
 2621:             }
 2622: 
 2623:             (*s_etat_processus).erreur_systeme = d_es_processus;
 2624:             return;
 2625:         }
 2626: 
 2627:         while(drapeau_fin == d_faux)
 2628:         {
 2629:             l_element_courant = (struct_liste_chainee *)
 2630:                     (*s_etat_processus).l_base_pile_processus;
 2631: 
 2632:             while(l_element_courant != NULL)
 2633:             {
 2634:                 if ((*(*((struct_processus_fils *) (*(*l_element_courant)
 2635:                         .donnee).objet)).thread).processus_detache == d_vrai)
 2636:                 {
 2637:                     if (((*(*((struct_processus_fils *) (*(*l_element_courant)
 2638:                             .donnee).objet)).thread).pid ==
 2639:                             (*(*((struct_processus_fils *)
 2640:                             (*s_objet_argument).objet)).thread).pid)
 2641:                             && ((*(*((struct_processus_fils *)
 2642:                             (*s_objet_argument).objet)).thread)
 2643:                             .processus_detache == d_vrai))
 2644:                     {
 2645:                         break;
 2646:                     }
 2647:                 }
 2648:                 else
 2649:                 {
 2650:                     if ((pthread_equal((*(*((struct_processus_fils *)
 2651:                             (*(*l_element_courant).donnee).objet)).thread).tid,
 2652:                             (*(*((struct_processus_fils *) (*s_objet_argument)
 2653:                             .objet)).thread).tid) != 0) &&
 2654:                             ((*(*((struct_processus_fils *)
 2655:                             (*(*l_element_courant).donnee).objet)).thread).pid
 2656:                             == (*(*((struct_processus_fils *)
 2657:                             (*s_objet_argument).objet)).thread).pid) &&
 2658:                             ((*(*((struct_processus_fils *)
 2659:                             (*s_objet_argument).objet)).thread)
 2660:                             .processus_detache == d_faux))
 2661:                     {
 2662:                         break;
 2663:                     }
 2664:                 }
 2665: 
 2666:                 l_element_courant = (*l_element_courant).suivant;
 2667:             }
 2668: 
 2669:             if ((*s_etat_processus).var_volatile_requete_arret != 0)
 2670:             {
 2671:                 if ((*s_etat_processus).profilage == d_vrai)
 2672:                 {
 2673:                     profilage(s_etat_processus, NULL);
 2674:                 }
 2675: 
 2676:                 if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
 2677:                 {
 2678:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 2679:                     return;
 2680:                 }
 2681: 
 2682:                 liberation(s_etat_processus, s_objet_argument);
 2683:                 return;
 2684:             }
 2685: 
 2686:             if (l_element_courant != NULL)
 2687:             {
 2688:                 if (pthread_mutex_lock(&((*(*((struct_processus_fils *)
 2689:                         (*(*l_element_courant).donnee).objet)).thread).mutex))
 2690:                         != 0)
 2691:                 {
 2692:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 2693:                     return;
 2694:                 }
 2695: 
 2696:                 if ((*(*((struct_processus_fils *) (*(*l_element_courant)
 2697:                         .donnee).objet)).thread).nombre_objets_dans_pipe != 0)
 2698:                 {
 2699:                     if (pthread_mutex_unlock(&((*(*((struct_processus_fils *)
 2700:                             (*(*l_element_courant).donnee).objet)).thread)
 2701:                             .mutex)) != 0)
 2702:                     {
 2703:                         (*s_etat_processus).erreur_systeme = d_es_processus;
 2704:                         return;
 2705:                     }
 2706: 
 2707:                     drapeau_fin = d_vrai;
 2708:                 }
 2709:                 else
 2710:                 {
 2711:                     if (pthread_mutex_unlock(&((*(*((struct_processus_fils *)
 2712:                             (*(*l_element_courant).donnee).objet)).thread)
 2713:                             .mutex)) != 0)
 2714:                     {
 2715:                         (*s_etat_processus).erreur_systeme = d_es_processus;
 2716:                         return;
 2717:                     }
 2718: 
 2719:                     if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
 2720:                     {
 2721:                         if ((*s_etat_processus).profilage == d_vrai)
 2722:                         {
 2723:                             profilage(s_etat_processus, NULL);
 2724:                         }
 2725: 
 2726:                         (*s_etat_processus).erreur_systeme =
 2727:                                 d_es_processus;
 2728:                         return;
 2729:                     }
 2730: 
 2731: #                   ifndef SEMAPHORES_NOMMES
 2732:                         if (sem_post(&((*s_etat_processus).semaphore_fork))
 2733:                                 != 0)
 2734: #                   else
 2735:                         if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 2736: #                   endif
 2737:                     {
 2738:                         (*s_etat_processus).erreur_systeme = d_es_processus;
 2739:                         return;
 2740:                     }
 2741: 
 2742:                     nanosleep(&attente, NULL);
 2743: 
 2744: #                   ifndef SEMAPHORES_NOMMES
 2745:                         while(sem_wait(&((*s_etat_processus).semaphore_fork))
 2746:                                 != 0)
 2747: #                   else
 2748:                         while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
 2749: #                   endif
 2750:                     {
 2751:                         if (errno != EINTR)
 2752:                         {
 2753:                             (*s_etat_processus).erreur_systeme = d_es_processus;
 2754:                             return;
 2755:                         }
 2756:                     }
 2757: 
 2758:                     scrutation_injection(s_etat_processus);
 2759: 
 2760:                     if ((*s_etat_processus).nombre_interruptions_non_affectees
 2761:                             != 0)
 2762:                     {
 2763:                         affectation_interruptions_logicielles(s_etat_processus);
 2764:                     }
 2765: 
 2766:                     if ((*s_etat_processus).nombre_interruptions_en_queue != 0)
 2767:                     {
 2768:                         registre_instruction_valide =
 2769:                                 (*s_etat_processus).instruction_valide;
 2770:                         traitement_interruptions_logicielles(s_etat_processus);
 2771:                         (*s_etat_processus).instruction_valide =
 2772:                                 registre_instruction_valide;
 2773:                     }
 2774: 
 2775:                     if ((*s_etat_processus).var_volatile_requete_arret != 0)
 2776:                     {
 2777:                         if ((*s_etat_processus).profilage == d_vrai)
 2778:                         {
 2779:                             profilage(s_etat_processus, NULL);
 2780:                         }
 2781: 
 2782:                         return;
 2783:                     }
 2784: 
 2785:                     if (pthread_mutex_lock(&((*s_etat_processus).mutex)) != 0)
 2786:                     {
 2787:                         if ((*s_etat_processus).profilage == d_vrai)
 2788:                         {
 2789:                             profilage(s_etat_processus, NULL);
 2790:                         }
 2791: 
 2792:                         (*s_etat_processus).erreur_systeme =
 2793:                                 d_es_processus;
 2794:                         return;
 2795:                     }
 2796:                 }
 2797:             }
 2798:             else
 2799:             {
 2800:                 drapeau_fin = d_vrai;
 2801:                 (*s_etat_processus).erreur_execution = d_ex_processus;
 2802:             }
 2803: 
 2804:             INCR_GRANULARITE(attente.tv_nsec);
 2805:         }
 2806: 
 2807:         if ((*s_etat_processus).profilage == d_vrai)
 2808:         {
 2809:             profilage(s_etat_processus, NULL);
 2810:         }
 2811: 
 2812:         if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
 2813:         {
 2814:             (*s_etat_processus).erreur_systeme = d_es_processus;
 2815:             return;
 2816:         }
 2817:     }
 2818:     else
 2819:     {
 2820:         liberation(s_etat_processus, s_objet_argument);
 2821: 
 2822:         (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
 2823:         return;
 2824:     }
 2825: 
 2826:     liberation(s_etat_processus, s_objet_argument);
 2827: 
 2828:     return;
 2829: }
 2830: 
 2831: 
 2832: /*
 2833: ================================================================================
 2834:   Fonction 'wfsock'
 2835: ================================================================================
 2836:   Entrées : pointeur sur une structure struct_processus
 2837: --------------------------------------------------------------------------------
 2838:   Sorties :
 2839: --------------------------------------------------------------------------------
 2840:   Effets de bord : néant
 2841: ================================================================================
 2842: */
 2843: 
 2844: void
 2845: instruction_wfsock(struct_processus *s_etat_processus)
 2846: {
 2847:     int                     erreur;
 2848: 
 2849:     logical1                drapeau;
 2850: 
 2851:     socklen_t               longueur;
 2852: 
 2853:     struct_liste_chainee    *l_element_courant;
 2854: 
 2855:     struct_objet            *s_objet_argument;
 2856:     struct_objet            *s_objet_resultat;
 2857: 
 2858:     struct pollfd           s_poll;
 2859: 
 2860:     struct sockaddr_in      adresse_ipv4;
 2861: #   ifdef IPV6
 2862:     struct sockaddr_in6     adresse_ipv6;
 2863: #   endif
 2864: 
 2865:     unsigned long           i;
 2866: 
 2867:     if ((*s_etat_processus).affichage_arguments == 'Y')
 2868:     {
 2869:         printf("\n  WFSOCK ");
 2870: 
 2871:         if ((*s_etat_processus).langue == 'F')
 2872:         {
 2873:             printf("(attente d'une connexion sur une socket)\n\n");
 2874:         }
 2875:         else
 2876:         {
 2877:             printf("(wait for connection on a socket)\n\n");
 2878:         }
 2879: 
 2880:         printf("    1: %s\n", d_SCK);
 2881:         printf("->  2: %s\n", d_SCK);
 2882:         printf("    1: %s\n", d_SCK);
 2883: 
 2884:         return;
 2885:     }
 2886:     else if ((*s_etat_processus).test_instruction == 'Y')
 2887:     {
 2888:         (*s_etat_processus).nombre_arguments = -1;
 2889:         return;
 2890:     }
 2891: 
 2892:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
 2893:     {
 2894:         if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
 2895:         {
 2896:             return;
 2897:         }
 2898:     }
 2899: 
 2900:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
 2901:             &s_objet_argument) == d_erreur)
 2902:     {
 2903:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
 2904:         return;
 2905:     }
 2906: 
 2907:     if ((*s_objet_argument).type == SCK)
 2908:     {
 2909:         if ((strcmp((*((struct_socket *) (*s_objet_argument).objet)).type,
 2910:                 "STREAM") != 0) && (strcmp((*((struct_socket *)
 2911:                 (*s_objet_argument).objet)).type, "SEQUENTIAL DATAGRAM") != 0))
 2912:         {
 2913:             // Mode non connecté : l'attente se fait sur un poll()
 2914: 
 2915:             if ((s_objet_resultat = copie_objet(s_etat_processus,
 2916:                     s_objet_argument, 'P')) == NULL)
 2917:             {
 2918:                 (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
 2919:                 return;
 2920:             }
 2921: 
 2922:             s_poll.fd = (*((struct_socket *) (*s_objet_argument).objet)).socket;
 2923:             s_poll.events = POLLIN;
 2924:             s_poll.revents = 0;
 2925: 
 2926:             do
 2927:             {
 2928:                 drapeau = d_vrai;
 2929: 
 2930: #               ifndef SEMAPHORES_NOMMES
 2931:                 if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
 2932: #               else
 2933:                 if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 2934: #               endif
 2935:                 {
 2936:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 2937:                     return;
 2938:                 }
 2939: 
 2940:                 if (poll(&s_poll, 1, -1) < 0)
 2941:                 {
 2942:                     erreur = errno;
 2943: 
 2944: #                   ifndef SEMAPHORES_NOMMES
 2945:                     while(sem_wait(&((*s_etat_processus)
 2946:                             .semaphore_fork)) != 0)
 2947: #                   else
 2948:                     while(sem_wait((*s_etat_processus).semaphore_fork)
 2949:                             != 0)
 2950: #                   endif
 2951: 
 2952:                     if (erreur != EINTR)
 2953:                     {
 2954:                         liberation(s_etat_processus, s_objet_argument);
 2955:                         liberation(s_etat_processus, s_objet_resultat);
 2956: 
 2957:                         (*s_etat_processus).erreur_execution =
 2958:                                 d_ex_erreur_acces_fichier;
 2959:                         return;
 2960:                     }
 2961: 
 2962:                     scrutation_injection(s_etat_processus);
 2963: 
 2964:                     if ((*s_etat_processus).var_volatile_requete_arret != 0)
 2965:                     {
 2966:                         drapeau = d_vrai;
 2967:                     }
 2968:                     else
 2969:                     {
 2970:                         drapeau = d_faux;
 2971:                     }
 2972:                 }
 2973:                 else
 2974:                 {
 2975: #                   ifndef SEMAPHORES_NOMMES
 2976:                         while(sem_wait(&((*s_etat_processus)
 2977:                                 .semaphore_fork)) != 0)
 2978: #                   else
 2979:                         while(sem_wait((*s_etat_processus).semaphore_fork)
 2980:                                 != 0)
 2981: #                   endif
 2982:                     {
 2983:                         if (errno != EINTR)
 2984:                         {
 2985:                             (*s_etat_processus).erreur_systeme =
 2986:                                     d_es_processus;
 2987:                             return;
 2988:                         }
 2989:                     }
 2990:                 }
 2991:             } while(drapeau == d_faux);
 2992: 
 2993:             if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
 2994:                     s_objet_argument) == d_erreur)
 2995:             {
 2996:                 return;
 2997:             }
 2998: 
 2999:             if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
 3000:                     s_objet_resultat) == d_erreur)
 3001:             {
 3002:                 return;
 3003:             }
 3004:         }
 3005:         else
 3006:         {
 3007:             // Mode connecté
 3008: 
 3009:             if ((s_objet_resultat = copie_objet(s_etat_processus,
 3010:                     s_objet_argument, 'O')) == NULL)
 3011:             {
 3012:                 (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
 3013:                 return;
 3014:             }
 3015: 
 3016:             (*((struct_socket *) (*s_objet_resultat).objet)).effacement = 'N';
 3017:             (*((struct_socket *) (*s_objet_resultat).objet)).socket_en_ecoute
 3018:                     = 'N';
 3019: 
 3020:             if ((*((struct_socket *) (*s_objet_resultat).objet)).domaine ==
 3021:                     PF_INET)
 3022:             {
 3023:                 longueur = sizeof(adresse_ipv4);
 3024: 
 3025:                 do
 3026:                 {
 3027:                     drapeau = d_vrai;
 3028: 
 3029: #               ifndef SEMAPHORES_NOMMES
 3030:                         if (sem_post(&((*s_etat_processus).semaphore_fork))
 3031:                                 != 0)
 3032: #               else
 3033:                         if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 3034: #               endif
 3035:                     {
 3036:                         (*s_etat_processus).erreur_systeme = d_es_processus;
 3037:                         return;
 3038:                     }
 3039: 
 3040:                     if (((*((struct_socket *) (*s_objet_resultat).objet))
 3041:                             .socket = accept((*((struct_socket *)
 3042:                             (*s_objet_argument).objet)).socket,
 3043:                             (struct sockaddr *) &adresse_ipv4, &longueur))
 3044:                             < 0)
 3045:                     {
 3046:                         erreur = errno;
 3047: 
 3048: #                       ifndef SEMAPHORES_NOMMES
 3049:                         while(sem_wait(&((*s_etat_processus)
 3050:                                 .semaphore_fork)) != 0)
 3051: #                       else
 3052:                         while(sem_wait((*s_etat_processus).semaphore_fork)
 3053:                                 != 0)
 3054: #                       endif
 3055:                         {
 3056:                             if (errno != EINTR)
 3057:                             {
 3058:                                 (*s_etat_processus).erreur_systeme =
 3059:                                         d_es_processus;
 3060:                                 return;
 3061:                             }
 3062:                         }
 3063: 
 3064:                         if (erreur != EINTR)
 3065:                         {
 3066:                             liberation(s_etat_processus, s_objet_argument);
 3067:                             liberation(s_etat_processus, s_objet_resultat);
 3068: 
 3069:                             (*s_etat_processus).erreur_execution =
 3070:                                     d_ex_erreur_acces_fichier;
 3071:                             return;
 3072:                         }
 3073: 
 3074:                         scrutation_injection(s_etat_processus);
 3075: 
 3076:                         if ((*s_etat_processus).var_volatile_requete_arret != 0)
 3077:                         {
 3078:                             drapeau = d_vrai;
 3079:                         }
 3080:                         else
 3081:                         {
 3082:                             drapeau = d_faux;
 3083:                         }
 3084:                     }
 3085:                     else
 3086:                     {
 3087: #                   ifndef SEMAPHORES_NOMMES
 3088:                             while(sem_wait(&((*s_etat_processus)
 3089:                                     .semaphore_fork)) != 0)
 3090: #                   else
 3091:                             while(sem_wait((*s_etat_processus).semaphore_fork)
 3092:                                     != 0)
 3093: #                   endif
 3094:                         {
 3095:                             if (errno != EINTR)
 3096:                             {
 3097:                                 (*s_etat_processus).erreur_systeme =
 3098:                                         d_es_processus;
 3099:                                 return;
 3100:                             }
 3101:                         }
 3102:                     }
 3103:                 } while(drapeau == d_faux);
 3104: 
 3105:                 if (((*((struct_socket *) (*s_objet_resultat).objet))
 3106:                         .adresse_distante = malloc(22 *
 3107:                         sizeof(unsigned char))) == NULL)
 3108:                 {
 3109:                     (*s_etat_processus).erreur_systeme =
 3110:                             d_es_allocation_memoire;
 3111:                     return;
 3112:                 }
 3113: 
 3114:                 sprintf((*((struct_socket *) (*s_objet_resultat).objet))
 3115:                         .adresse_distante, "%d.%d.%d.%d(%d)",
 3116:                         (ntohl(adresse_ipv4.sin_addr.s_addr) >> 24) & 0xFF,
 3117:                         (ntohl(adresse_ipv4.sin_addr.s_addr) >> 16) & 0xFF,
 3118:                         (ntohl(adresse_ipv4.sin_addr.s_addr) >> 8) & 0xFF,
 3119:                         ntohl(adresse_ipv4.sin_addr.s_addr) & 0xFF,
 3120:                         ntohs(adresse_ipv4.sin_port));
 3121:             }
 3122:             else if ((*((struct_socket *) (*s_objet_resultat).objet)).domaine ==
 3123:                     PF_INET6)
 3124:             {
 3125: #           ifdef IPV6
 3126:                 longueur = sizeof(adresse_ipv6);
 3127: 
 3128:                 do
 3129:                 {
 3130:                     drapeau = d_vrai;
 3131: 
 3132: #               ifndef SEMAPHORES_NOMMES
 3133:                         if (sem_post(&((*s_etat_processus).semaphore_fork))
 3134:                                 != 0)
 3135: #               else
 3136:                         if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 3137: #               endif
 3138:                     {
 3139:                         (*s_etat_processus).erreur_systeme = d_es_processus;
 3140:                         return;
 3141:                     }
 3142: 
 3143:                     if (((*((struct_socket *) (*s_objet_resultat).objet))
 3144:                             .socket = accept((*((struct_socket *)
 3145:                             (*s_objet_argument).objet)).socket,
 3146:                             (struct sockaddr *) &adresse_ipv6, &longueur)) < 0)
 3147:                     {
 3148:                         erreur = errno;
 3149: 
 3150: #                   ifndef SEMAPHORES_NOMMES
 3151:                             while(sem_wait(&((*s_etat_processus)
 3152:                                     .semaphore_fork)) != 0)
 3153: #                   else
 3154:                             while(sem_wait((*s_etat_processus).semaphore_fork)
 3155:                                     != 0)
 3156: #                   endif
 3157:                         {
 3158:                             if (errno != EINTR)
 3159:                             {
 3160:                                 (*s_etat_processus).erreur_systeme =
 3161:                                         d_es_processus;
 3162:                                 return;
 3163:                             }
 3164:                         }
 3165: 
 3166:                         if (erreur != EINTR)
 3167:                         {
 3168:                             liberation(s_etat_processus, s_objet_argument);
 3169:                             liberation(s_etat_processus, s_objet_resultat);
 3170: 
 3171:                             (*s_etat_processus).erreur_execution =
 3172:                                     d_ex_erreur_acces_fichier;
 3173:                             return;
 3174:                         }
 3175: 
 3176:                         scrutation_injection(s_etat_processus);
 3177: 
 3178:                         if ((*s_etat_processus).var_volatile_requete_arret != 0)
 3179:                         {
 3180:                             drapeau = d_vrai;
 3181:                         }
 3182:                         else
 3183:                         {
 3184:                             drapeau = d_faux;
 3185:                         }
 3186:                     }
 3187:                     else
 3188:                     {
 3189: #                   ifndef SEMAPHORES_NOMMES
 3190:                             while(sem_wait(&((*s_etat_processus)
 3191:                                     .semaphore_fork)) != 0)
 3192: #                   else
 3193:                             while(sem_wait((*s_etat_processus).semaphore_fork)
 3194:                                     != 0)
 3195: #                   endif
 3196:                         {
 3197:                             if (errno != EINTR)
 3198:                             {
 3199:                                 (*s_etat_processus).erreur_systeme =
 3200:                                         d_es_processus;
 3201:                                 return;
 3202:                             }
 3203:                         }
 3204:                     }
 3205:                 } while(drapeau == d_faux);
 3206: 
 3207:                 if (((*((struct_socket *) (*s_objet_resultat).objet))
 3208:                         .adresse_distante = malloc(55 *
 3209:                         sizeof(unsigned char))) == NULL)
 3210:                 {
 3211:                     (*s_etat_processus).erreur_systeme =
 3212:                             d_es_allocation_memoire;
 3213:                     return;
 3214:                 }
 3215: 
 3216:                 (*((struct_socket *) (*s_objet_resultat).objet))
 3217:                         .adresse_distante = d_code_fin_chaine;
 3218: 
 3219:                 for(i = 0; i < 16; i++)
 3220:                 {
 3221:                     sprintf((*((struct_socket *) (*s_objet_resultat)
 3222:                             .objet)).adresse_distante, (i == 0) ? "%s%X"
 3223:                             : "%s:%X", (*((struct_socket *) (*s_objet_resultat)
 3224:                             .objet)).adresse_distante,
 3225:                             adresse_ipv6.sin6_addr.s6_addr[i]);
 3226:                 }
 3227: 
 3228:                 sprintf((*((struct_socket *) (*s_objet_resultat)
 3229:                         .objet)).adresse_distante, "%s(%u)",
 3230:                         (*((struct_socket *) (*s_objet_resultat)
 3231:                         .objet)).adresse_distante,
 3232:                         ntohs(adresse_ipv6.sin6_port));
 3233: #           else
 3234:                 if ((*s_etat_processus).langue == 'F')
 3235:                 {
 3236:                     printf("+++Attention : Support du protocole"
 3237:                             " IPv6 indisponible\n");
 3238:                 }
 3239:                 else
 3240:                 {
 3241:                     printf("+++Warning : IPv6 support "
 3242:                             "unavailable\n");
 3243:                 }
 3244: #           endif
 3245:             }
 3246:             else
 3247:             {
 3248:                 longueur = 0;
 3249: 
 3250:                 do
 3251:                 {
 3252:                     drapeau = d_vrai;
 3253: 
 3254: #               ifndef SEMAPHORES_NOMMES
 3255:                         if (sem_post(&((*s_etat_processus).semaphore_fork))
 3256:                                 != 0)
 3257: #               else
 3258:                         if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 3259: #               endif
 3260:                     {
 3261:                         (*s_etat_processus).erreur_systeme = d_es_processus;
 3262:                         return;
 3263:                     }
 3264: 
 3265:                     if (((*((struct_socket *) (*s_objet_resultat).objet))
 3266:                             .socket = accept((*((struct_socket *)
 3267:                             (*s_objet_argument).objet)).socket, NULL,
 3268:                             &longueur)) < 0)
 3269:                     {
 3270:                         erreur = errno;
 3271: 
 3272: #                   ifndef SEMAPHORES_NOMMES
 3273:                             while(sem_wait(&((*s_etat_processus)
 3274:                                     .semaphore_fork)) != 0)
 3275: #                   else
 3276:                             while(sem_wait((*s_etat_processus).semaphore_fork)
 3277:                                     != 0)
 3278: #                   endif
 3279:                         {
 3280:                             if (errno != EINTR)
 3281:                             {
 3282:                                 (*s_etat_processus).erreur_systeme =
 3283:                                         d_es_processus;
 3284:                                 return;
 3285:                             }
 3286:                         }
 3287: 
 3288:                         if (erreur != EINTR)
 3289:                         {
 3290:                             liberation(s_etat_processus, s_objet_argument);
 3291:                             liberation(s_etat_processus, s_objet_resultat);
 3292: 
 3293:                             (*s_etat_processus).erreur_execution =
 3294:                                     d_ex_erreur_acces_fichier;
 3295:                             return;
 3296:                         }
 3297: 
 3298:                         scrutation_injection(s_etat_processus);
 3299: 
 3300:                         if ((*s_etat_processus).var_volatile_requete_arret != 0)
 3301:                         {
 3302:                             drapeau = d_vrai;
 3303:                         }
 3304:                         else
 3305:                         {
 3306:                             drapeau = d_faux;
 3307:                         }
 3308:                     }
 3309:                     else
 3310:                     {
 3311: #                   ifndef SEMAPHORES_NOMMES
 3312:                             while(sem_wait(&((*s_etat_processus)
 3313:                                     .semaphore_fork)) != 0)
 3314: #                   else
 3315:                             while(sem_wait((*s_etat_processus).semaphore_fork)
 3316:                                     != 0)
 3317: #                   endif
 3318:                         {
 3319:                             if (errno != EINTR)
 3320:                             {
 3321:                                 (*s_etat_processus).erreur_systeme =
 3322:                                         d_es_processus;
 3323:                                 return;
 3324:                             }
 3325:                         }
 3326:                     }
 3327:                 } while(drapeau == d_faux);
 3328:             }
 3329: 
 3330:             // Si accept() renvoie une erreur non récupérée, il ne peut s'agir
 3331:             // que de EINTR sachant qu'une requête d'arrêt est en court de
 3332:             // traitement.
 3333: 
 3334:             if ((*((struct_socket *) (*s_objet_resultat).objet)).socket >= 0)
 3335:             {
 3336:                 l_element_courant = (*s_etat_processus).s_sockets;
 3337: 
 3338:                 if (l_element_courant == NULL)
 3339:                 {
 3340:                     if (((*s_etat_processus).s_sockets =
 3341:                             allocation_maillon(s_etat_processus)) == NULL)
 3342:                     {
 3343:                         (*s_etat_processus).erreur_systeme =
 3344:                                 d_es_allocation_memoire;
 3345:                         return;
 3346:                     }
 3347: 
 3348:                     (*(*s_etat_processus).s_sockets).suivant = NULL;
 3349:                     l_element_courant = (*s_etat_processus).s_sockets;
 3350:                 }
 3351:                 else
 3352:                 {
 3353:                     /*
 3354:                      * Ajout d'un élément à la fin de la liste chaînée
 3355:                      */
 3356: 
 3357:                     while((*l_element_courant).suivant != NULL)
 3358:                     {
 3359:                         l_element_courant = (*l_element_courant).suivant;
 3360:                     }
 3361: 
 3362:                     if (((*l_element_courant).suivant =
 3363:                             allocation_maillon(s_etat_processus)) == NULL)
 3364:                     {
 3365:                         (*s_etat_processus).erreur_systeme =
 3366:                                 d_es_allocation_memoire;
 3367:                         return;
 3368:                     }
 3369: 
 3370:                     l_element_courant = (*l_element_courant).suivant;
 3371:                     (*l_element_courant).suivant = NULL;
 3372:                 }
 3373: 
 3374:                 if (((*l_element_courant).donnee = copie_objet(s_etat_processus,
 3375:                         s_objet_resultat, 'O')) == NULL)
 3376:                 {
 3377:                     (*s_etat_processus).erreur_systeme =
 3378:                             d_es_allocation_memoire;
 3379:                     return;
 3380:                 }
 3381:             }
 3382: 
 3383:             if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
 3384:                     s_objet_argument) == d_erreur)
 3385:             {
 3386:                 return;
 3387:             }
 3388: 
 3389:             if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
 3390:                     s_objet_resultat) == d_erreur)
 3391:             {
 3392:                 return;
 3393:             }
 3394:         }
 3395:     }
 3396:     else
 3397:     {
 3398:         liberation(s_etat_processus, s_objet_argument);
 3399: 
 3400:         (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
 3401:         return;
 3402:     }
 3403: 
 3404:     return;
 3405: }
 3406: 
 3407: 
 3408: /*
 3409: ================================================================================
 3410:   Fonction 'wfswi'
 3411: ================================================================================
 3412:   Entrées : pointeur sur une structure struct_processus
 3413: --------------------------------------------------------------------------------
 3414:   Sorties :
 3415: --------------------------------------------------------------------------------
 3416:   Effets de bord : néant
 3417: ================================================================================
 3418: */
 3419: 
 3420: void
 3421: instruction_wfswi(struct_processus *s_etat_processus)
 3422: {
 3423:     integer8                    interruption;
 3424: 
 3425:     logical1                    drapeau_fin;
 3426: 
 3427:     struct_objet                *s_objet_argument;
 3428: 
 3429:     struct timespec             attente;
 3430: 
 3431:     (*s_etat_processus).erreur_execution = d_ex;
 3432: 
 3433:     attente.tv_sec = 0;
 3434:     attente.tv_nsec = GRANULARITE_us * 1000;
 3435: 
 3436:     if ((*s_etat_processus).affichage_arguments == 'Y')
 3437:     {
 3438:         printf("\n  WFSWI ");
 3439: 
 3440:         if ((*s_etat_processus).langue == 'F')
 3441:         {
 3442:             printf("(attente d'une interruption)\n\n");
 3443:         }
 3444:         else
 3445:         {
 3446:             printf("(wait for interrupt)\n\n");
 3447:         }
 3448: 
 3449:         printf("    1: %s\n", d_INT);
 3450: 
 3451:         return;
 3452:     }
 3453:     else if ((*s_etat_processus).test_instruction == 'Y')
 3454:     {
 3455:         (*s_etat_processus).nombre_arguments = -1;
 3456:         return;
 3457:     }
 3458: 
 3459:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
 3460:     {
 3461:         if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
 3462:         {
 3463:             return;
 3464:         }
 3465:     }
 3466: 
 3467:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
 3468:             &s_objet_argument) == d_erreur)
 3469:     {
 3470:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
 3471:         return;
 3472:     }
 3473: 
 3474:     if ((*s_objet_argument).type == INT)
 3475:     {
 3476:         drapeau_fin = d_faux;
 3477: 
 3478:         interruption = (*((integer8 *) (*s_objet_argument).objet));
 3479: 
 3480:         if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
 3481:         {
 3482:             liberation(s_etat_processus, s_objet_argument);
 3483: 
 3484:             (*s_etat_processus).erreur_execution = d_ex_interruption_invalide;
 3485:             return;
 3486:         }
 3487: 
 3488:         while(drapeau_fin == d_faux)
 3489:         {
 3490:             if ((*s_etat_processus).var_volatile_requete_arret != 0)
 3491:             {
 3492:                 liberation(s_etat_processus, s_objet_argument);
 3493:                 return;
 3494:             }
 3495: 
 3496:             if ((*s_etat_processus).nombre_interruptions_non_affectees != 0)
 3497:             {
 3498:                 affectation_interruptions_logicielles(s_etat_processus);
 3499:             }
 3500: 
 3501:             if ((*s_etat_processus).queue_interruptions[interruption - 1] > 0)
 3502:             {
 3503:                 drapeau_fin = d_vrai;
 3504:             }
 3505:             else
 3506:             {
 3507:                 nanosleep(&attente, NULL);
 3508:                 scrutation_injection(s_etat_processus);
 3509:                 INCR_GRANULARITE(attente.tv_nsec);
 3510:             }
 3511:         }
 3512:     }
 3513:     else
 3514:     {
 3515:         liberation(s_etat_processus, s_objet_argument);
 3516: 
 3517:         (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
 3518:         return;
 3519:     }
 3520: 
 3521:     liberation(s_etat_processus, s_objet_argument);
 3522: 
 3523:     return;
 3524: }
 3525: 
 3526: 
 3527: /*
 3528: ================================================================================
 3529:   Fonction 'wfpoke'
 3530: ================================================================================
 3531:   Entrées : pointeur sur une structure struct_processus
 3532: --------------------------------------------------------------------------------
 3533:   Sorties :
 3534: --------------------------------------------------------------------------------
 3535:   Effets de bord : néant
 3536: ================================================================================
 3537: */
 3538: 
 3539: void
 3540: instruction_wfpoke(struct_processus *s_etat_processus)
 3541: {
 3542:     struct timespec             attente;
 3543: 
 3544:     unsigned char               registre_instruction_valide;
 3545: 
 3546:     (*s_etat_processus).erreur_execution = d_ex;
 3547: 
 3548:     attente.tv_sec = 0;
 3549:     attente.tv_nsec = GRANULARITE_us * 1000;
 3550: 
 3551:     if ((*s_etat_processus).affichage_arguments == 'Y')
 3552:     {
 3553:         printf("\n  WFPOKE ");
 3554: 
 3555:         if ((*s_etat_processus).langue == 'F')
 3556:         {
 3557:             printf("(attente de données en provenance du processus père)\n\n");
 3558:             printf("  Aucun argument\n");
 3559:         }
 3560:         else
 3561:         {
 3562:             printf("(wait for data from parent process)\n\n");
 3563:             printf("  No argument\n");
 3564:         }
 3565: 
 3566:         return;
 3567:     }
 3568:     else if ((*s_etat_processus).test_instruction == 'Y')
 3569:     {
 3570:         (*s_etat_processus).nombre_arguments = -1;
 3571:         return;
 3572:     }
 3573: 
 3574:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
 3575:     {
 3576:         if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
 3577:         {
 3578:             return;
 3579:         }
 3580:     }
 3581: 
 3582:     if ((*s_etat_processus).presence_pipes == d_faux)
 3583:     {
 3584:         (*s_etat_processus).erreur_execution = d_ex_absence_processus_pere;
 3585:         return;
 3586:     }
 3587: 
 3588:     if ((*s_etat_processus).nombre_objets_injectes > 0)
 3589:     {
 3590:         return;
 3591:     }
 3592: 
 3593:     if ((*s_etat_processus).profilage == d_vrai)
 3594:     {
 3595:         profilage(s_etat_processus, "Interprocess or interthread "
 3596:                 "communications (WFPOKE)");
 3597: 
 3598:         if ((*s_etat_processus).erreur_systeme != d_es)
 3599:         {
 3600:             return;
 3601:         }
 3602:     }
 3603: 
 3604:     do
 3605:     {
 3606: #       ifndef SEMAPHORES_NOMMES
 3607:             if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
 3608: #       else
 3609:             if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 3610: #       endif
 3611:         {
 3612:             (*s_etat_processus).erreur_systeme = d_es_processus;
 3613:             return;
 3614:         }
 3615: 
 3616:         nanosleep(&attente, NULL);
 3617: 
 3618: #       ifndef SEMAPHORES_NOMMES
 3619:             while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
 3620: #       else
 3621:             while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
 3622: #       endif
 3623:         {
 3624:             if (errno != EINTR)
 3625:             {
 3626:                 (*s_etat_processus).erreur_systeme = d_es_processus;
 3627:                 return;
 3628:             }
 3629:         }
 3630: 
 3631:         scrutation_injection(s_etat_processus);
 3632: 
 3633:         if ((*s_etat_processus).nombre_interruptions_non_affectees != 0)
 3634:         {
 3635:             affectation_interruptions_logicielles(s_etat_processus);
 3636:         }
 3637: 
 3638:         if ((*s_etat_processus).nombre_interruptions_en_queue != 0)
 3639:         {
 3640:             registre_instruction_valide =
 3641:                     (*s_etat_processus).instruction_valide;
 3642:             traitement_interruptions_logicielles(s_etat_processus);
 3643:             (*s_etat_processus).instruction_valide =
 3644:                     registre_instruction_valide;
 3645:         }
 3646: 
 3647:         if ((*s_etat_processus).var_volatile_requete_arret != 0)
 3648:         {
 3649:             if ((*s_etat_processus).profilage == d_vrai)
 3650:             {
 3651:                 profilage(s_etat_processus, NULL);
 3652:             }
 3653: 
 3654:             return;
 3655:         }
 3656: 
 3657:         INCR_GRANULARITE(attente.tv_nsec);
 3658:     } while((*s_etat_processus).nombre_objets_injectes == 0);
 3659: 
 3660:     return;
 3661: }
 3662: 
 3663: 
 3664: /*
 3665: ================================================================================
 3666:   Fonction 'wfack'
 3667: ================================================================================
 3668:   Entrées : pointeur sur une structure struct_processus
 3669: --------------------------------------------------------------------------------
 3670:   Sorties :
 3671: --------------------------------------------------------------------------------
 3672:   Effets de bord : néant
 3673: ================================================================================
 3674: */
 3675: 
 3676: void
 3677: instruction_wfack(struct_processus *s_etat_processus)
 3678: {
 3679:     struct timespec             attente;
 3680: 
 3681:     unsigned char               registre_instruction_valide;
 3682: 
 3683:     (*s_etat_processus).erreur_execution = d_ex;
 3684: 
 3685:     attente.tv_sec = 0;
 3686:     attente.tv_nsec = GRANULARITE_us * 1000;
 3687: 
 3688:     if ((*s_etat_processus).affichage_arguments == 'Y')
 3689:     {
 3690:         printf("\n  WFACK ");
 3691: 
 3692:         if ((*s_etat_processus).langue == 'F')
 3693:         {
 3694:             printf("(attente des acquittements de lecture)\n\n");
 3695:             printf("  Aucun argument\n");
 3696:         }
 3697:         else
 3698:         {
 3699:             printf("(wait for reading of data acknowledgement)\n\n");
 3700:             printf("  No argument\n");
 3701:         }
 3702: 
 3703:         return;
 3704:     }
 3705:     else if ((*s_etat_processus).test_instruction == 'Y')
 3706:     {
 3707:         (*s_etat_processus).nombre_arguments = -1;
 3708:         return;
 3709:     }
 3710: 
 3711:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
 3712:     {
 3713:         if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
 3714:         {
 3715:             return;
 3716:         }
 3717:     }
 3718: 
 3719:     if ((*s_etat_processus).presence_pipes == d_faux)
 3720:     {
 3721:         (*s_etat_processus).erreur_execution = d_ex_absence_processus_pere;
 3722:         return;
 3723:     }
 3724: 
 3725:     if ((*s_etat_processus).profilage == d_vrai)
 3726:     {
 3727:         profilage(s_etat_processus, "Interprocess or interthread communications"
 3728:                 " (WFACK)");
 3729: 
 3730:         if ((*s_etat_processus).erreur_systeme != d_es)
 3731:         {
 3732:             return;
 3733:         }
 3734:     }
 3735: 
 3736:     while((*s_etat_processus).nombre_objets_envoyes_non_lus != 0)
 3737:     {
 3738:         scrutation_injection(s_etat_processus);
 3739: 
 3740:         if ((*s_etat_processus).nombre_interruptions_non_affectees != 0)
 3741:         {
 3742:             affectation_interruptions_logicielles(s_etat_processus);
 3743:         }
 3744: 
 3745:         if ((*s_etat_processus).nombre_interruptions_en_queue != 0)
 3746:         {
 3747:             registre_instruction_valide =
 3748:                     (*s_etat_processus).instruction_valide;
 3749:             traitement_interruptions_logicielles(s_etat_processus);
 3750:             (*s_etat_processus).instruction_valide =
 3751:                     registre_instruction_valide;
 3752:         }
 3753: 
 3754:         if ((*s_etat_processus).var_volatile_requete_arret != 0)
 3755:         {
 3756:             if ((*s_etat_processus).profilage == d_vrai)
 3757:             {
 3758:                 profilage(s_etat_processus, NULL);
 3759:             }
 3760: 
 3761:             return;
 3762:         }
 3763: 
 3764: #       ifndef SEMAPHORES_NOMMES
 3765:             if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
 3766: #       else
 3767:             if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 3768: #       endif
 3769:         {
 3770:             (*s_etat_processus).erreur_systeme = d_es_processus;
 3771:             return;
 3772:         }
 3773: 
 3774:         nanosleep(&attente, NULL);
 3775:         INCR_GRANULARITE(attente.tv_nsec);
 3776: 
 3777: #       ifndef SEMAPHORES_NOMMES
 3778:             while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
 3779: #       else
 3780:             while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
 3781: #       endif
 3782:         {
 3783:             if (errno != EINTR)
 3784:             {
 3785:                 (*s_etat_processus).erreur_systeme = d_es_processus;
 3786:                 return;
 3787:             }
 3788:         }
 3789:     }
 3790: 
 3791:     if ((*s_etat_processus).profilage == d_vrai)
 3792:     {
 3793:         profilage(s_etat_processus, NULL);
 3794:     }
 3795: 
 3796:     return;
 3797: }
 3798: 
 3799: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>