MED fichier: Fichier source de MEDfileExist.c

MED fichier

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

MEDfileExist.c
Aller à la documentation de ce fichier.
1 /* This file is part of MED.
2 *
3 * COPYRIGHT (C) 1999 - 2015 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 #ifdef PPRO_NT_CALL
24 #define R_OK 4 /* Test for read permission. */
25 #define W_OK 2 /* Test for write permission. */
26 #define X_OK 1 /* Test for execute permission. */
27 #define F_OK 0 /* Test for existence. */
28 #else
29 #include <unistd.h>
30 #endif
31
32 #ifndef PPRO_NT_CALL
33 #include <libgen.h>
34 #endif
35
36 #include <string.h>
37
38
50 med_err
51 MEDfileExist(const char* const filename,
52 const med_access_mode accessmode,
53 med_bool * const fileexist,
54 med_bool * const accessok )
55 {
56 med_idt _fid = 0;
57 med_err _ret = -1;
58 int _mode = R_OK;
59 char *_filename = NULL;
60
61 #ifdef PPRO_NT_CALL
62 char _dirname[_MAX_PATH];
63 char _drive[_MAX_DRIVE];
64 char _direc[_MAX_DIR];
65 #else
66 char *_dirname = NULL;
67 #endif
68
69 /*
70 * On inhibe le gestionnaire d'erreur HDF
71 */
72 _MEDmodeErreurVerrouiller();
73
74 /*
75 * On ouvre le fichier MED sous HDF
76 */
77 if ( access(filename,F_OK) ) {
78
79 *fileexist = MED_FALSE;
80 *accessok = MED_FALSE;
81 if (accessmode==MED_ACC_RDONLY) goto SORTIE;
82 _mode = _mode|W_OK|X_OK;
83
84 #ifndef PPRO_NT_CALL
85 if (!(_filename = strndup (filename,2*MED_PATHNAME_SIZE))) {
86 MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"strndup");
87 SSCRUTE(filename);SSCRUTE(_filename);goto ERROR;
88 }
89 #else
90 if (!(_filename = _strdup (filename))) {
91 MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"strndup");
92 SSCRUTE(filename);SSCRUTE(_filename);goto ERROR;
93 }
94 #endif
95
96 #ifndef PPRO_NT_CALL
97 if (!(_dirname = dirname(_filename))) {
98 MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"dirname");
99 SSCRUTE(_filename);SSCRUTE(_dirname);goto ERROR;
100 }
101 #else
102 _splitpath(_filename, _drive, _direc, NULL, NULL);
103 if (!strlen(_direc)) {
104 MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"_splitpath");
105 SSCRUTE(_filename);SSCRUTE(_direc);goto ERROR;
106 }
107 // Join drive letter and directory name:
108 _makepath(_dirname, _drive, _direc, NULL, NULL);
109 #endif
110 if ( access(_dirname,_mode) ) *accessok = MED_FALSE; else *accessok = MED_TRUE;
111
112 } else {
113
114 *fileexist = MED_TRUE;
115 (accessmode!=MED_ACC_RDONLY) && (_mode=_mode|W_OK);
116 if ( access(filename,_mode) ) *accessok = MED_FALSE; else *accessok = MED_TRUE;
117
118 }
119
120
121 SORTIE:
122 _ret=0;
123
124 ERROR:
125
126 if (_filename) free(_filename);
127
128 return _ret;
129 }
130
med_err
herr_t med_err
Definition: med.h:327
MED_ERR_
#define MED_ERR_(rt, r1, r2, r3)
Definition: med_utils.h:158
med_access_mode
med_access_mode
Definition: med.h:118
MED_TRUE
Definition: med.h:257
MED_ERR_CALL
#define MED_ERR_CALL
Definition: med_err.h:45
MED_PATHNAME_SIZE
#define MED_PATHNAME_SIZE
Definition: med.h:87
med_config.h
MEDfileExist
med_err MEDfileExist(const char *const filename, const med_access_mode accessmode, med_bool *const fileexist, med_bool *const accessok)
Interroge l'existence d'un fichier de nom filename et la possibilité de l'ouvrir selon le mode d'accè...
Definition: MEDfileExist.c:51
MED_FALSE
Definition: med.h:257
med_idt
hid_t med_idt
Definition: med.h:326
med_outils.h
med.h
filename
#define filename
Definition: test10.c:73
med_bool
med_bool
Definition: med.h:257
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