MED fichier: Fichier source de MEDmeshUniversalNameWr.c

MED fichier

- Documentation MED
- Guides d'utilisation
- Guides de référence

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