%% options copyright owner = Dirk Krause copyright year = 2015-xxxx license = bsd %% header /** @file dk4fopda.h File open. */ #include "dk4app.h" #include "dk4fopc8.h" #ifndef DK4FOPT_H_INCLUDED #include "dk4fopt.h" #endif #ifdef __cplusplus extern "C" { #endif /** Open a file after doing security checks. CRT on Windows: Required. @param name File name. @param mode Opening mode. @param tests Set of tests, see dk4fopc8.h. @param app Application structure for diagnostics, may be NULL. */ FILE * dk4fopen_app(const dkChar *name, const dkChar *mode, int tests, dk4_app_t *app); #ifdef __cplusplus } #endif %% module #if 0 #define _POSIX_C_SOURCE 200112L #define _XOPEN_SOURCE 600 #ifdef _GNU_SOURCE #undef _GNU_SOURCE #endif #endif #include "dk4conf.h" #if DK4_HAVE_STRING_H #include #endif #if DK4_HAVE_ERRNO_H #include #endif #include "dk4const.h" #include "dk4fopd.h" #include "dk4fopda.h" #include "dk4error.h" FILE * dk4fopen_app(const dkChar *name, const dkChar *mode, int tests, dk4_app_t *app) { dk4_er_t er; FILE *back = NULL; if ((NULL != name) && (NULL != mode)) { dk4error_init(&er); back = dk4fopen(name, mode, tests, &er); if (NULL == back) { switch (er.ec) { case DK4_E_INVALID_ARGUMENTS: { /* Bug, this function should not be called with name or mode NULL */ } break; case DK4_E_SYNTAX: { /* ERROR: File name does not refer to regular file */ dk4app_log_base3(app, DK4_LL_ERROR, 108, 109, name); } break; case DK4_E_SEC_CHECK: { if (0 != (DK4_FOPEN_SC_IS_REGULAR & er.dt.iDetails1)) { /* ERROR: Not a regular file */ dk4app_log_base3(app, DK4_LL_ERROR, 108, 109, name); } if (0 != (DK4_FOPEN_SC_WR_SYMLINK_IN_PATH & er.dt.iDetails1)) { /* ERROR: Path contains symbolic link */ dk4app_log_base3(app, DK4_LL_ERROR, 108, 110, name); } if (0 != (DK4_FOPEN_SC_WR_PATH_IS_SYMLINK & er.dt.iDetails1)) { /* ERROR: Path is a symbolic link */ dk4app_log_base3(app, DK4_LL_ERROR, 108, 111, name); } if (0 != (DK4_FOPEN_SC_WR_SYMLINK_OWNER & er.dt.iDetails1)) { /* ERROR: Symbolic link owner is not file owner */ dk4app_log_base3(app, DK4_LL_ERROR, 108, 112, name); } } break; case DK4_E_OPEN_WRITE_FAILED: case DK4_E_OPEN_READ_FAILED: { switch (er.dt.iDetails1) { #ifdef EACCES case EACCES : { dk4app_log_base3(app, DK4_LL_ERROR, 108, 55, name); } break; #endif #ifdef EINTR case EINTR : { dk4app_log_base3(app, DK4_LL_ERROR, 108, 113, name); } break; #endif #ifdef EISDIR case EISDIR : { dk4app_log_base3(app, DK4_LL_ERROR, 108, 52, name); } break; #endif #ifdef ELOOP case ELOOP : { dk4app_log_base3(app, DK4_LL_ERROR, 108, 61, name); } break; #endif #ifdef EMFILE case EMFILE : { dk4app_log_base3(app, DK4_LL_ERROR, 108, 114, name); } break; #endif #ifdef ENAMETOOLONG case ENAMETOOLONG : { dk4app_log_base3(app, DK4_LL_ERROR, 108, 65, name); } break; #endif #ifdef ENFILE case ENFILE : { dk4app_log_base3(app, DK4_LL_ERROR, 108, 115, name); } break; #endif #ifdef ENOENT case ENOENT : { dk4app_log_base3(app, DK4_LL_ERROR, 108, 51, name); } break; #endif #ifdef ENOSPC case ENOSPC : { dk4app_log_base3(app, DK4_LL_ERROR, 108, 60, name); } break; #endif #ifdef ENOTDIR case ENOTDIR : { dk4app_log_base3(app, DK4_LL_ERROR, 108, 150, name); } break; #endif #ifdef ENXIO case ENXIO : { dk4app_log_base3(app, DK4_LL_ERROR, 108, 116, name); } break; #endif #ifdef EOVERFLOW case EOVERFLOW : { dk4app_log_base3(app, DK4_LL_ERROR, 108, 117, name); } break; #endif #ifdef EROFS case EROFS : { dk4app_log_base3(app, DK4_LL_ERROR, 108, 56, name); } break; #endif default: { dk4app_log_with_errno( app, DK4_LL_ERROR, 108, 79, 80, 108, 77, name, er.dt.iDetails1 ); } break; } } break; } } } return back; }