1 /*  This file is part of MED.
2  *
3  *  COPYRIGHT (C) 1999 - 2019  EDF R&D, CEA/DEN
4  *  MED is free software: you can redistribute it and/or modify
5  *  it under the terms of the GNU Lesser General Public License as published by
6  *  the Free Software Foundation, either version 3 of the License, or
7  *  (at your option) any later version.
8  *
9  *  MED is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU Lesser General Public License for more details.
13  *
14  *  You should have received a copy of the GNU Lesser General Public License
15  *  along with MED.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include <med.h>
19 #include <med_config.h>
20 #include <med_outils.h>
21 
22 #include <string.h>
23 
_MEDfileCommentRd30(int dummy,...)24 void _MEDfileCommentRd30(int dummy, ...) {
25 
26   med_idt _rootId=0;
27   med_err _ret=-1;
28   med_bool attributeexist=MED_FALSE;
29 
30   MED_VARGS_DECL(const, med_idt , , fid     );
31   MED_VARGS_DECL(, char*, const   , comment );
32   MED_VARGS_DECL(, med_err *     ,, fret    );
33 
34   va_list params;
35   va_start(params,dummy);
36 
37   MED_VARGS_DEF(const, med_idt , , fid     );
38   MED_VARGS_DEF(, char*, const   , comment );
39   MED_VARGS_DEF(, med_err *     ,, fret    );
40 
41 
42   _MEDmodeErreurVerrouiller();
43 
44   if ( _MEDattributeExist(fid, "/",MED_COMMENT_NAME, &attributeexist ) < 0 ) {
45     MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"_MEDattributeExist");
46   }
47 
48   if ( !attributeexist ) { _ret=MED_ERR_DOESNTEXIST;goto ERROR;}
49 
50   /* The file descriptor is read
51      and returned in "comment". */
52   if ((_rootId = _MEDdatagroupOuvrir(fid,"/")) < 0) {
53     MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP," : '/'");
54     goto ERROR;
55   }
56 
57   if (_MEDattrStringLire(_rootId,MED_COMMENT_NAME,
58 			 MED_COMMENT_SIZE,(char*)comment) < 0) {
59     MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE," : '/'");
60     goto ERROR;
61   }
62 
63   _ret=0;
64  ERROR :
65   if (_rootId > 0)
66     if (_MEDdatagroupFermer(_rootId) < 0) {
67       MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP," : '/'");
68       _ret = -1;
69     }
70 
71   va_end(params);
72   *fret = _ret;
73   return;
74 }
75