summaryrefslogtreecommitdiff
path: root/support/dktools/dk4appdeldir.c
blob: 41f3dde9d04820fdf38f2b07096059fd6aac717d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
/*
Copyright (C) 2015-2020, Dirk Krause
SPDX-License-Identifier: BSD-3-Clause
*/

/*
	WARNING: This file was generated by the dkct program (see
	http://dktools.sourceforge.net/ for details).
	Changes you make here will be lost if dkct is run again!
	You should modify the original source and run dkct on it.
	Original source: dk4appdeldir.ctr
*/

/**	@file dk4appdeldir.c The dk4appdeldir module.
*/


#line 10 "dk4appdeldir.ctr"


#include "dk4conf.h"
#include "dk4types.h"

#if DK4_ON_WINDOWS
#ifndef WINDOWS_H_INCLUDED
#include <windows.h>
#define WINDOWS_H_INCLUDED 1
#endif
#endif

#ifndef DK4MEM_H_INCLUDED
#include "dk4mem.h"
#endif

#ifndef DK4APP_H_INCLUDED
#include "dk4app.h"
#endif

#ifndef DK4DELDIR_H_INCLUDED
#include "dk4deldir.h"
#endif

#ifndef DK4CONST_H_INCLUDED
#include "dk4const.h"
#endif

#ifndef DK4STATD_H_INCLUDED
#include "dk4statd.h"
#endif

#ifndef DK4FILED_H_INCLUDED
#include "dk4filed.h"
#endif

#ifndef DK4MAODD_H_INCLUDED
#include "dk4maodd.h"
#endif

#ifndef DK4MAODH_H_INCLUDED
#include "dk4maodh.h"
#endif

#if DK4_HAVE_ERRNO_H
#ifndef ERRNO_H_INCLUDED
#include <errno.h>
#define	ERRNO_H_INCLUDED 1
#endif
#endif

#if DK4_HAVE_ASSERT_H
#ifndef	ASSERT_H_INCLUDED
#include <assert.h>
#define	ASSERT_H_INCLUDED 1
#endif
#endif




#line 70 "dk4appdeldir.ctr"



void
dk4app_del_dir_report(const dkChar *fn, const dk4_er_t *erp, dk4_app_t *app)
{
#if DK4_ON_WINDOWS
  dkChar	 eb1[8 * sizeof(DWORD)];
  dkChar	 eb2[8 * sizeof(DWORD)];
  int		 res;
#endif
  switch (erp->ec) {
    case DK4_E_NOT_SUPPORTED: {
      dk4app_log_base3(app, DK4_LL_ERROR, 66, 54, fn);
    } break;
#if DK4_ON_WINDOWS
    case DK4_E_REMOVE_DIRECTORY_FAILED : {
      res = dk4ma_write_decimal_unsigned(
        eb1, DK4_SIZEOF(eb1,dkChar), (dk4_um_t)((erp->dt).lDetails1), 0, NULL
      );
      if (0 != res) {
        res = dk4ma_write_hex_unsigned(
          eb2, DK4_SIZEOF(eb2,dkChar),
          (dk4_um_t)((erp->dt).lDetails1), 0, NULL
        );
      }
      if (0 != res) {
        dk4app_log_base7(app,DK4_LL_ERROR,66,69,70,71,fn,eb1,eb2);
      } else {
        dk4app_log_base3(app, DK4_LL_ERROR, 66, 77, fn);
      }
    } break;
#endif
    case DK4_E_RMDIR_FAILED: {
      switch ((erp->dt).iDetails1) {
#ifdef EACCES
        case EACCES: {
          dk4app_log_base3(app, DK4_LL_ERROR, 66, 55, fn);
        } break;
#endif
#ifdef EBUSY
        case EBUSY: {
          dk4app_log_base3(app, DK4_LL_ERROR, 66, 49, fn);
        } break;
#endif
#ifdef EIO
        case EIO: {
          dk4app_log_base3(app, DK4_LL_ERROR, 66, 59, fn);
        } break;
#endif
#ifdef EFAULT
        case EFAULT: {
          dk4app_log_base3(app, DK4_LL_ERROR, 66, 50, fn);
        } break;
#endif
#ifdef EINVAL
        case EINVAL: {
          /* ERROR: Invalid path name */
          dk4app_log_base3(app, DK4_LL_ERROR, 66, 68, fn);
        } break;
#endif
#ifdef ELOOP
        case ELOOP: {
          dk4app_log_base3(app, DK4_LL_ERROR, 66, 61, fn);
        } break;
#endif
#ifdef ENAMETOOLONG
        case ENAMETOOLONG: {
          dk4app_log_base3(app, DK4_LL_ERROR, 66, 65, fn);
        } break;
#endif
#ifdef ENOENT
        case ENOENT: {
          dk4app_log_base3(app, DK4_LL_ERROR, 66, 51, fn);
        } break;
#endif
#ifdef ENOMEM
        case ENOMEM: {
          dk4app_log_base3(app, DK4_LL_ERROR, 66, 62, fn);
        } break;
#endif
#ifdef ENOTDIR
        case ENOTDIR: {
          dk4app_log_base3(app, DK4_LL_ERROR, 66, 150, fn);
        } break;
#endif
#ifdef ENOTEMPTY
        case ENOTEMPTY: {
          dk4app_log_base3(app, DK4_LL_ERROR, 66, 67, fn);
        } break;
#endif
#if defined(EEXIST) && (EEXIST != ENOTEMPTY)
        case EEXIST: {
          dk4app_log_base3(app, DK4_LL_ERROR, 66, 67, fn);
        } break;
#endif
#ifdef EPERM
        case EPERM: {
          dk4app_log_base3(app, DK4_LL_ERROR, 66, 58, fn);
        } break;
#endif
#ifdef EROFS
        case EROFS: {
          dk4app_log_base3(app, DK4_LL_ERROR, 66, 56, fn);
        } break;
#endif
        default: {
          dk4app_log_with_errno(
            app, DK4_LL_ERROR, 66, 79, 80, 66, 77, fn, (erp->dt).iDetails1
          );
        } break;
      }
    } break;
    default: {
      dk4app_log_base3(app, DK4_LL_ERROR, 66, 77, fn);
    } break;
  }
}



int
dk4app_del_dir(const dkChar *fn, dk4_app_t *app)
{
  const dkChar 	*msg[3];
  dk4_er_t	 er;
  int		 back = 0;
  

#line 198 "dk4appdeldir.ctr"
#if	DK4_USE_ASSERT
  assert(NULL != fn);
#endif
  if (NULL != fn) {					

#line 202 "dk4appdeldir.ctr"
    if (NULL != app) {
      if (0 != dk4app_log_do(app, DK4_LL_DEBUG)) {
        if ((NULL != app->msg_debug) && (25 < app->sz_msg_debug)) {
	  msg[0] = (app->msg_debug)[25];
	  msg[1] = fn;
	  msg[2] = NULL;
	  dk4app_log_msg(app, DK4_LL_DEBUG, msg, 2);
	}
      }
    }
    dk4error_init(&er);
    back = dk4delete_directory(fn, &er);
    if (0 == back) {					

#line 215 "dk4appdeldir.ctr"
      if (0 != dk4file_exists(fn, NULL)) {
        dk4app_del_dir_report(fn, &er, app);
      } else {					

#line 218 "dk4appdeldir.ctr"
        back = 1;	/* File does not exist */
      }
    }
  }
  

#line 223 "dk4appdeldir.ctr"
  return back;
}