File:  [local] / rpl / src / instructions_w1.c
Revision 1.77: download - view: text, annotated - select for diffs - revision graph
Mon Mar 11 15:41:06 2013 UTC (11 years, 1 month ago) by bertrand
Branches: MAIN
CVS tags: HEAD
Patch permettant d'envoyer une trame de données sur une socket en mode
non formaté.

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

CVSweb interface <joel.bertrand@systella.fr>