summaryrefslogtreecommitdiff
path: root/support/dktools/dk4appdelfile.c
blob: 26b14ecf1c86e0d679d1eb58bb3edee1d38f2eea (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
/*
	WARNING: This file was generated by dkct.
	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: dk4appdelfile.ctr
*/

/*
Copyright (C) 2015-2017, Dirk Krause

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice,
  this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above opyright notice,
  this list of conditions and the following disclaimer in the documentation
  and/or other materials provided with the distribution.
* Neither the name of the author nor the names of contributors may be used
  to endorse or promote products derived from this software without specific
  prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

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


#line 10 "dk4appdelfile.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 DK4DELFILE_H_INCLUDED
#include "dk4delfile.h"
#endif

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

#ifndef DK4CONST_H_INCLUDED
#include "dk4const.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



void
dk4app_del_file_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: {
      /* ERROR: Failed to delete file, no function available */
      dk4app_log_base3(app, DK4_LL_ERROR, 41, 54, fn);
    } break;
#if DK4_ON_WINDOWS
    case DK4_E_DELETE_FILE_FAILED : {
      if (ERROR_FILE_NOT_FOUND == (erp->dt).lDetails1) {
        dk4app_log_base3(app, DK4_LL_ERROR, 41, 51, fn);
        goto finished;
      }
      if (ERROR_ACCESS_DENIED == (erp->dt).lDetails1) {
        dk4app_log_base3(app, DK4_LL_ERROR, 41, 55, fn);
        goto finished;
      }
      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,41,69,70,71,fn,eb1,eb2);
      } else {
        dk4app_log_base3(app, DK4_LL_ERROR, 41, 77, fn);
      }
      goto finished;
    } break;
#endif
    case DK4_E_UNLINK_FAILED: {
      switch ((erp->dt).iDetails1) {
#ifdef EACCES
        case EACCES: {
          dk4app_log_base3(app, DK4_LL_ERROR, 41, 55, fn);
        } break;
#endif
#ifdef EBUSY
        case EBUSY: {
          dk4app_log_base3(app, DK4_LL_ERROR, 41, 49, fn);
        } break;
#endif
#ifdef EFAULT
        case EFAULT: {
          dk4app_log_base3(app, DK4_LL_ERROR, 41, 50, fn);
        } break;
#endif
#ifdef EIO
        case EIO: {
          dk4app_log_base3(app, DK4_LL_ERROR, 41, 59, fn);
        } break;
#endif
#ifdef EISDIR
        case EISDIR: {
          dk4app_log_base3(app, DK4_LL_ERROR, 41, 52, fn);
        } break;
#endif
#ifdef ELOOP
        case ELOOP: {
          dk4app_log_base3(app, DK4_LL_ERROR, 41, 61, fn);
        } break;
#endif
#ifdef ENAMETOOLONG
        case ENAMETOOLONG: {
          dk4app_log_base3(app, DK4_LL_ERROR, 41, 65, fn);
        } break;
#endif
#ifdef ENOENT
        case ENOENT: {
          dk4app_log_base3(app, DK4_LL_ERROR, 41, 51, fn);
        } break;
#endif
#ifdef ENOMEM
        case ENOMEM: {
          dk4app_log_base3(app, DK4_LL_ERROR, 41, 62, fn);
        } break;
#endif
#ifdef ENOTDIR
        case ENOTDIR: {
          dk4app_log_base3(app, DK4_LL_ERROR, 41, 150, fn);
        } break;
#endif
#ifdef EPERM
        case EPERM: {
          dk4app_log_base3(app, DK4_LL_ERROR, 41, 58, fn);
        } break;
#endif
#ifdef EROFS
        case EROFS: {
          dk4app_log_base3(app, DK4_LL_ERROR, 41, 56, fn);
        } break;
#endif
        default: {
          dk4app_log_with_errno(
            app, DK4_LL_ERROR, 41, 79, 80, 41, 77, fn, (erp->dt).iDetails1
          );
        } break;
      }
    } break;
    default: {
      dk4app_log_base3(app, DK4_LL_ERROR, 41, 77, fn);
    } break;
  }
#if DK4_ON_WINDOWS
  finished: ;
#endif
}



int
dk4app_del_file(const dkChar *fn, dk4_app_t *app)
{
  const dkChar 	*msg[3];
  dk4_er_t	 er;
  int		 back = 0;
  if (NULL != fn) {
    if (NULL != app) {
      if (0 != dk4app_log_do(app, DK4_LL_DEBUG)) {
        if ((NULL != app->msg_debug) && (26 < app->sz_msg_debug)) {
	  msg[0] = (app->msg_debug)[26];
	  msg[1] = fn;
	  msg[2] = NULL;
	  dk4app_log_msg(app, DK4_LL_DEBUG, msg, 2);
	}
      }
    }
    dk4error_init(&er);
    back = dk4delete_file(fn, &er);
    if (0 == back) {
      if (0 != dk4file_exists(fn, NULL)) {
        dk4app_del_file_report(fn, &er, app);
      } else {
        back = 1;	/* File does not exist */
      }
    }
  }
  return back;
}