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