1 /*
2 Copyright (C) 2015-2021, Dirk Krause
3 SPDX-License-Identifier: BSD-3-Clause
4 */
5 
6 /*
7 	WARNING: This file was generated by the dkct program (see
8 	http://dktools.sourceforge.net/ for details).
9 	Changes you make here will be lost if dkct is run again!
10 	You should modify the original source and run dkct on it.
11 	Original source: dk4fopda.ctr
12 */
13 
14 /**	@file dk4fopda.c The dk4fopda module.
15 */
16 
17 
18 
19 #if 0
20 #define _POSIX_C_SOURCE	200112L
21 #define	_XOPEN_SOURCE	600
22 #ifdef	_GNU_SOURCE
23 #undef	_GNU_SOURCE
24 #endif
25 #endif
26 
27 
28 #include "dk4conf.h"
29 
30 #if DK4_HAVE_STRING_H
31 #include <string.h>
32 #endif
33 
34 #if DK4_HAVE_ERRNO_H
35 #include <errno.h>
36 #endif
37 
38 #include <libdk4base/dk4const.h>
39 #include <libdk4c/dk4fopd.h>
40 #include <libdk4app/dk4fopda.h>
41 #include <libdk4base/dk4error.h>
42 
43 #if DK4_HAVE_ASSERT_H
44 #ifndef	ASSERT_H_INCLUDED
45 #include <assert.h>
46 #define	ASSERT_H_INCLUDED 1
47 #endif
48 #endif
49 
50 
51 FILE *
dk4fopen_app(const dkChar * name,const dkChar * mode,int tests,dk4_app_t * app)52 dk4fopen_app(const dkChar *name, const dkChar *mode, int tests, dk4_app_t *app)
53 {
54   dk4_er_t	 er;
55   FILE		*back	= NULL;
56 
57 #if	DK4_USE_ASSERT
58   assert(NULL != name);
59   assert(NULL != mode);
60 #endif
61   if ((NULL != name) && (NULL != mode)) {
62     dk4error_init(&er);
63     back = dk4fopen(name, mode, tests, &er);
64     if (NULL == back) {
65       switch (er.ec) {
66         case DK4_E_INVALID_ARGUMENTS: {
67           /* Bug, this function should not be called with name or mode NULL */
68         } break;
69         case DK4_E_SYNTAX: {
70           /* ERROR: File name does not refer to regular file */
71 	  dk4app_log_base3(app, DK4_LL_ERROR, 108, 109, name);
72         } break;
73         case DK4_E_SEC_CHECK: {
74 	  if (0 != (DK4_FOPEN_SC_IS_REGULAR & er.dt.iDetails1)) {
75 	    /* ERROR: Not a regular file */
76 	    dk4app_log_base3(app, DK4_LL_ERROR, 108, 109, name);
77 	  }
78 	  if (0 != (DK4_FOPEN_SC_WR_SYMLINK_IN_PATH & er.dt.iDetails1)) {
79 	    /* ERROR: Path contains symbolic link */
80 	    dk4app_log_base3(app, DK4_LL_ERROR, 108, 110, name);
81 	  }
82 	  if (0 != (DK4_FOPEN_SC_WR_PATH_IS_SYMLINK & er.dt.iDetails1)) {
83 	    /* ERROR: Path is a symbolic link */
84 	    dk4app_log_base3(app, DK4_LL_ERROR, 108, 111, name);
85 	  }
86 	  if (0 != (DK4_FOPEN_SC_WR_SYMLINK_OWNER & er.dt.iDetails1)) {
87 	    /* ERROR: Symbolic link owner is not file owner */
88 	    dk4app_log_base3(app, DK4_LL_ERROR, 108, 112, name);
89 	  }
90         } break;
91         case DK4_E_OPEN_WRITE_FAILED: case DK4_E_OPEN_READ_FAILED: {
92 	  switch (er.dt.iDetails1) {
93 #ifdef EACCES
94 	    case EACCES : {
95 	      dk4app_log_base3(app, DK4_LL_ERROR, 108, 55, name);
96 	    } break;
97 #endif
98 #ifdef EINTR
99 	    case EINTR : {
100 	      dk4app_log_base3(app, DK4_LL_ERROR, 108, 113, name);
101 	    } break;
102 #endif
103 #ifdef EISDIR
104 	    case EISDIR : {
105 	      dk4app_log_base3(app, DK4_LL_ERROR, 108, 52, name);
106 	    } break;
107 #endif
108 #ifdef ELOOP
109 	    case ELOOP : {
110 	      dk4app_log_base3(app, DK4_LL_ERROR, 108, 61, name);
111 	    } break;
112 #endif
113 #ifdef EMFILE
114 	    case EMFILE : {
115 	      dk4app_log_base3(app, DK4_LL_ERROR, 108, 114, name);
116 	    } break;
117 #endif
118 #ifdef ENAMETOOLONG
119 	    case ENAMETOOLONG : {
120 	      dk4app_log_base3(app, DK4_LL_ERROR, 108, 65, name);
121 	    } break;
122 #endif
123 #ifdef ENFILE
124 	    case ENFILE : {
125 	      dk4app_log_base3(app, DK4_LL_ERROR, 108, 115, name);
126 	    } break;
127 #endif
128 #ifdef ENOENT
129 	    case ENOENT : {
130 	      dk4app_log_base3(app, DK4_LL_ERROR, 108, 51, name);
131 	    } break;
132 #endif
133 #ifdef ENOSPC
134 	    case ENOSPC : {
135 	      dk4app_log_base3(app, DK4_LL_ERROR, 108, 60, name);
136 	    } break;
137 #endif
138 #ifdef ENOTDIR
139 	    case ENOTDIR : {
140 	      dk4app_log_base3(app, DK4_LL_ERROR, 108, 150, name);
141 	    } break;
142 #endif
143 #ifdef ENXIO
144 	    case ENXIO : {
145 	      dk4app_log_base3(app, DK4_LL_ERROR, 108, 116, name);
146 	    } break;
147 #endif
148 #ifdef EOVERFLOW
149 	    case EOVERFLOW : {
150 	      dk4app_log_base3(app, DK4_LL_ERROR, 108, 117, name);
151 	    } break;
152 #endif
153 #ifdef EROFS
154 	    case EROFS : {
155 	      dk4app_log_base3(app, DK4_LL_ERROR, 108, 56, name);
156 	    } break;
157 #endif
158 	    default: {
159 	      dk4app_log_with_errno(
160 	        app, DK4_LL_ERROR, 108, 79, 80, 108, 77,
161 		name, er.dt.iDetails1
162 	      );
163 	    } break;
164 	  }
165 	} break;
166       }
167     }
168   }
169   return back;
170 }
171 
172 
173 
174