File:  [local] / rpl / src / instructions_w1.c
Revision 1.90: download - view: text, annotated - select for diffs - revision graph
Fri Apr 25 07:37:33 2014 UTC (10 years ago) by bertrand
Branches: MAIN
CVS tags: rpl-4_1_18, HEAD
En route pour la 4.1.18.

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

CVSweb interface <joel.bertrand@systella.fr>