MED fichier
MEDmeshUniversalNameWr.c
Aller à la documentation de ce fichier.
1 /* This file is part of MED.
2  *
3  * COPYRIGHT (C) 1999 - 2020 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 
19 #include <med.h>
20 #include <med_config.h>
21 #include <med_outils.h>
22 
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <string.h>
26 
27 #ifdef PPRO_NT_CALL
28 // Windows Header Files:
29 #include <windows.h>
30 #include <Lmcons.h>
31 #include <sys/timeb.h>
32 #include <time.h>
33 #else
34 
35 #if TIME_WITH_SYS_TIME
36 # include <sys/time.h>
37 # include <time.h>
38 #else
39 # if HAVE_SYS_TIME_H
40 # include <sys/time.h>
41 # else
42 # include <time.h>
43 # endif
44 #endif
45 
46 #ifndef HAVE_UNISTD_H
47 #error "unistd.h required."
48 #endif
49 
50 # include <unistd.h>
51 
52 #if defined(HAVE_GETPWUID) && defined(HAVE_GETEUID)
53 # include <sys/types.h>
54 # include <pwd.h>
55 #endif
56 
57 #endif
58 
67 med_err
69  const char * const meshname)
70 {
71  med_access_mode _MED_ACCESS_MODE;
72  med_err _ret=-1;
73  med_idt _meshid=0;
75  char _unvname [MED_LNAME_SIZE+1]="";
76  time_t _time;
77 #ifdef PPRO_NT_CALL
78  struct timeb _tp;
79  char _lpBuffer [UNLEN+1]="";
80  long _nSize = UNLEN+1;
81 #else
82  struct timeval _tp;
83  struct passwd* mypasswd;
84 #endif
85 
86 
87  /*
88  * On inhibe le gestionnaire d'erreur
89  */
91  if (_MEDcheckVersion30(fid) < 0) goto ERROR_;
92 
93  if ( (_MED_ACCESS_MODE = _MEDmodeAcces(fid) ) == MED_ACC_UNDEF ) {
95  goto ERROR_;
96  }
97 
98  if ( _MED_ACCESS_MODE == MED_ACC_RDONLY) {
100  ISCRUTE_int(_MED_ACCESS_MODE);
101  goto ERROR_;
102  }
103 
104  /*
105  * Si le maillage n'existe pas => erreur
106  */
107  strcat(_path,meshname);
108  if ((_meshid = _MEDdatagroupOuvrir(fid,_path)) < 0) {
110  ISCRUTE_id(_meshid);goto ERROR_;
111  }
112 
113  /*
114  * Creation/Ecriture de l'attribut nom universel
115  */
116 
117 #ifdef PPRO_NT_CALL
118 
119  if ( GetUserName(_lpBuffer,&_nSize) == 0 ) goto ERROR_;
120  if ( _nSize > MED_NAME_SIZE ) _nSize = MED_NAME_SIZE;
121  strncpy(_unvname,_lpBuffer,_nSize);
122  strcat(_unvname," ");
123  _time=time(&_time);
124  strcat(_unvname,ctime(&_time));
125  ftime(&_tp);
126  _nSize = strlen(_unvname)-1;
127  if ( sprintf(&_unvname[_nSize]," %hu",_tp.millitm) < 0 ) goto ERROR_;
128 
129 #else
130 #if defined(HAVE_GETPWUID) && defined(HAVE_GETEUID)
131  mypasswd=getpwuid(geteuid());
132  if ( mypasswd == NULL ) {
133  MESSAGE("Impossible d'obtenir le nom de l'utilisateur effectif");
134  goto ERROR_;
135  }
136  strcat(_unvname,mypasswd->pw_name);
137 #elif defined(HAVE_CUSERID)
138  if ( !cuserid(_unvname) ) {
139  MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"cuserid");
140  SSCRUTE(_path); goto ERROR_;
141  }
142 #else
143 #error "There is no ( getpwuid && geteuid) nor cuserid"
144 #endif
145  strcat(_unvname," ");
146  _time=time(&_time);
147  strcat(_unvname,ctime(&_time));
148  if ( gettimeofday(&_tp,NULL) < 0 ) {
149  MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"gettimeofday");
150  SSCRUTE(_path); goto ERROR_;
151  }
152  if ( sprintf(&_unvname[strlen(_unvname)-1]," %li",_tp.tv_usec) < 0 ) {
153  MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"sprintf");
154  SSCRUTE(_path); goto ERROR_;
155  }
156 #endif
157 
158  if ( _MEDattributeStringWr(_meshid,MED_NOM_UNV,MED_LNAME_SIZE,_unvname) < 0) {
160  SSCRUTE(meshname);SSCRUTE(MED_NOM_UNI);
161  SSCRUTE(_unvname);goto ERROR_;
162  }
163 
164  _ret = 0;
165  ERROR_:
166 
167  if (_meshid>0) if (_MEDdatagroupFermer(_meshid) < 0) {
169  ISCRUTE_id(_meshid);
170  }
171 
172  return _ret;
173 }
174 
MED_ERR_OPEN
#define MED_ERR_OPEN
Definition: med_err.h:37
med.h
MED_LNAME_SIZE
#define MED_LNAME_SIZE
Definition: med.h:83
MED_ERR_CALL
#define MED_ERR_CALL
Definition: med_err.h:48
_MEDcheckVersion30
MEDC_EXPORT med_err _MEDcheckVersion30(med_idt fid)
_MEDmodeAcces
MEDC_EXPORT med_access_mode _MEDmodeAcces(med_idt oid)
MED_NOM_UNV
#define MED_NOM_UNV
Definition: med_outils.h:42
MESSAGE
#define MESSAGE(chaine)
Definition: med_utils.h:324
_MEDdatagroupFermer
MEDC_EXPORT med_err _MEDdatagroupFermer(med_idt id)
MED_ERR_API
#define MED_ERR_API
Definition: med_err.h:111
ISCRUTE_id
#define ISCRUTE_id(entier)
Definition: med_utils.h:319
MED_MESH_GRP
#define MED_MESH_GRP
Definition: med_outils.h:160
MED_ERR_WRITE
#define MED_ERR_WRITE
Definition: med_err.h:29
MED_ERR_ACCESSMODE
#define MED_ERR_ACCESSMODE
Definition: med_err.h:104
med_outils.h
med_access_mode
med_access_mode
Definition: med.h:120
_MEDattributeStringWr
MEDC_EXPORT med_err _MEDattributeStringWr(med_idt pid, const char *const attname, const med_size attsize, const char *const val)
_MEDmodeErreurVerrouiller
MEDC_EXPORT void _MEDmodeErreurVerrouiller(void)
med_err
herr_t med_err
Definition: med.h:323
med_idt
hid_t med_idt
Definition: med.h:322
MED_ACC_RDONLY
@ MED_ACC_RDONLY
Definition: med.h:120
MED_ERR_DATAGROUP
#define MED_ERR_DATAGROUP
Definition: med_err.h:99
MED_NOM_UNI
#define MED_NOM_UNI
Definition: med_outils.h:62
MED_NAME_SIZE
#define MED_NAME_SIZE
Definition: med.h:81
MED_ERR_MESH_MSG
#define MED_ERR_MESH_MSG
Definition: med_err.h:133
MED_ERR_UNRECOGNIZED
#define MED_ERR_UNRECOGNIZED
Definition: med_err.h:39
MEDmeshUniversalNameWr
med_err MEDmeshUniversalNameWr(const med_idt fid, const char *const meshname)
Cette routine permet l'écriture du nom universel d'un maillage.
Definition: MEDmeshUniversalNameWr.c:68
MED_ERR_FILE_MSG
#define MED_ERR_FILE_MSG
Definition: med_err.h:132
ISCRUTE_int
#define ISCRUTE_int(entier)
Definition: med_utils.h:314
MED_ERR_ATTRIBUTE
#define MED_ERR_ATTRIBUTE
Definition: med_err.h:100
MED_ERR_INVALID
#define MED_ERR_INVALID
Definition: med_err.h:40
MED_MESH_GRP_SIZE
#define MED_MESH_GRP_SIZE
Definition: med_outils.h:161
SSCRUTE
#define SSCRUTE(chaine)
Definition: med_utils.h:323
med_config.h
MED_ERR_
#define MED_ERR_(rt, r1, r2, r3)
Definition: med_utils.h:160
MED_ACC_UNDEF
@ MED_ACC_UNDEF
Definition: med.h:124
_MEDdatagroupOuvrir
MEDC_EXPORT med_idt _MEDdatagroupOuvrir(med_idt pid, const char *const nom)
MED_ERR_CLOSE
#define MED_ERR_CLOSE
Definition: med_err.h:30