File:  [local] / rpl / src / instructions_w1.c
Revision 1.120: download - view: text, annotated - select for diffs - revision graph
Fri Jan 10 11:15:49 2020 UTC (4 years, 3 months ago) by bertrand
Branches: MAIN
CVS tags: HEAD
Modification du copyright.

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

CVSweb interface <joel.bertrand@systella.fr>