MEDunvCr.c
Aller à la documentation de ce fichier.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <med.h>
00020 #include <med_config.h>
00021 #include <med_outils.h>
00022
00023 #include <stdlib.h>
00024 #include <stdio.h>
00025 #include <string.h>
00026
00027 #ifdef PPRO_NT
00028
00029 #include <windows.h>
00030 #include <Lmcons.h>
00031 #include <sys/timeb.h>
00032 #else
00033
00034 #if TIME_WITH_SYS_TIME
00035 # include <sys/time.h>
00036 # include <time.h>
00037 #else
00038 # if HAVE_SYS_TIME_H
00039 # include <sys/time.h>
00040 # else
00041 # include <time.h>
00042 # endif
00043 #endif
00044
00045 #ifndef HAVE_UNISTD_H
00046 #error "unistd.h required."
00047 #endif
00048
00049 # include <unistd.h>
00050
00051 #if defined(HAVE_GETPWUID) && defined(HAVE_GETEUID)
00052 # include <sys/types.h>
00053 # include <pwd.h>
00054 #endif
00055
00056 #endif
00057
00058 med_err
00059 MEDunvCr(med_idt fid, char *maa)
00060 {
00061 med_idt maaid;
00062 char chemin [MED_TAILLE_MAA+MED_TAILLE_NOM+1]="";
00063 char nomu [MED_TAILLE_LNOM+1]="";
00064 time_t temps;
00065 #ifdef PPRO_NT
00066 struct timeb tp;
00067 char lpBuffer [UNLEN+1]="";
00068 long nSize = UNLEN+1;
00069 #else
00070 struct passwd* mypasswd;
00071 struct timeval tp;
00072 #endif
00073 med_err ret=-1;
00074
00075
00076
00077
00078 _MEDmodeErreurVerrouiller();
00079 if (MEDcheckVersion(fid) < 0) return -1;
00080
00081
00082
00083
00084
00085 strcpy(chemin,MED_MAA);
00086 strcat(chemin,maa);
00087 if ((maaid = _MEDdatagroupOuvrir(fid,chemin)) < 0) goto ERROR_;
00088
00089
00090
00091
00092
00093 #ifdef PPRO_NT
00094 if ( GetUserName(lpBuffer,&nSize) == 0 ) goto ERROR_;
00095 if ( nSize > MED_TAILLE_NOM ) nSize = MED_TAILLE_NOM;
00096 strncpy(nomu,lpBuffer,nSize);
00097 strcat(nomu," ");
00098 temps=time(&temps);
00099 strcat(nomu,ctime(&temps));
00100 ftime(&tp);
00101 nSize = strlen(nomu)-1;
00102 if ( sprintf(&nomu[nSize]," %hu",tp.millitm) < 0 ) goto ERROR_;
00103 #else
00104 #if defined(HAVE_GETPWUID) && defined(HAVE_GETEUID)
00105 mypasswd=getpwuid(geteuid());
00106 if ( mypasswd == NULL ) {
00107 MESSAGE("Impossible d'obtenir le nom de l'utilisateur effectif");
00108 goto ERROR_;
00109 }
00110 strcat(nomu,mypasswd->pw_name);
00111 #elif defined(HAVE_CUSERID)
00112 if ( !cuserid(nomu) ) {
00113 MESSAGE("Impossible d'obtenir le nom de l'utilisateur effectif");
00114 goto ERROR_;
00115 }
00116 #else
00117 #error "There is no ( getpwuid && geteuid) nor cuserid"
00118 #endif
00119 strcat(nomu," ");
00120 temps=time(&temps);
00121 strcat(nomu,ctime(&temps));
00122 if ( gettimeofday(&tp,NULL) < 0 ) goto ERROR_;
00123 if ( sprintf(&nomu[strlen(nomu)-1]," %li",tp.tv_usec) < 0 ) {
00124 MESSAGE("Erreur à la construction du nom universel.");
00125 goto ERROR_;
00126 }
00127 #endif
00128 if ((ret = _MEDattrStringEcrire(maaid,MED_NOM_UNV,MED_TAILLE_LNOM,nomu)) < 0)
00129 goto ERROR_;
00130
00131
00132
00133
00134 ret = 0;
00135 ERROR_:
00136 if ( maaid > 0) if (_MEDdatagroupFermer(maaid) < 0) {
00137 MESSAGE("Impossible de fermer le datagroup : ");
00138 ISCRUTE_int(maaid); ret = -1;
00139 }
00140
00141 return ret;
00142 }
00143