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: dk4delfile08.ctr
12 */
13 
14 /**	@file dk4delfile08.c The dk4delfile08 module.
15 */
16 
17 
18 #include "dk4conf.h"
19 
20 #if DK4_ON_WINDOWS
21 #ifndef WINDOWS_H_INCLUDED
22 #include <windows.h>
23 #define	WINDOWS_H_INCLUDED 1
24 #endif
25 #endif
26 
27 #include <libdk4c/dk4delfile08.h>
28 
29 #include <stdio.h>
30 
31 #if	DK4_HAVE_ASSERT_H
32 #ifndef	ASSERT_H_INCLUDED
33 #include <assert.h>
34 #define	ASSERT_H_INCLUDED 1
35 #endif
36 #endif
37 
38 #if DK4_HAVE_ERRNO_H
39 #ifndef ERRNO_H_INCLUDED
40 #include <errno.h>
41 #define	ERRNO_H_INCLUDED 1
42 #endif
43 #endif
44 
45 #if DK4_HAVE_IO_H
46 #ifndef IO_H_INCLUDED
47 #include <io.h>
48 #define IO_H_INCLUDED 1
49 #endif
50 #endif
51 
52 #if DK4_HAVE_UNISTD_H
53 #ifndef UNISTD_H_INCLUDED
54 #include <unistd.h>
55 #define	UNISTD_H_INCLUDED 1
56 #endif
57 #endif
58 
59 
60 
61 int
dk4delete_file_c8(const char * fn,dk4_er_t * erp)62 dk4delete_file_c8(const char *fn, dk4_er_t *erp)
63 {
64   int		 back = 0;
65 #if	DK4_USE_ASSERT
66   assert(NULL != fn);
67 #endif
68   if (NULL != fn) {
69 #if DK4_ON_WINDOWS
70     /* +++ Windows */
71 #if DK4_WIN_AVOID_CRT || DK4_WIN_DENY_CRT
72     if (DeleteFileA(fn)) {
73       back = 1;
74     } else {
75       dk4error_set_ldetails(
76         erp, DK4_E_DELETE_FILE_FAILED,
77 	(long)((unsigned long)GetLastError())
78       );
79     }
80 #else
81     if (DeleteFileA(fn)) {
82       back = 1;
83     } else {
84       if (NULL != erp) {
85         errno = 0;
86         if (0 == _unlink(fn)) {
87 	  back = 1;
88 	} else {
89           dk4error_set_idetails(erp, DK4_E_UNLINK_FAILED, errno);
90 	}
91       }
92     }
93 #endif
94     /* --- Windows */
95 #else
96     /* +++ non-Windows */
97 #if DK4_HAVE_UNLINK
98     errno = 0;
99     if (0 == unlink(fn)) {
100       back = 1;
101     } else {
102       dk4error_set_idetails(erp, DK4_E_UNLINK_FAILED, errno);
103     }
104 #else
105 #if DK4_HAVE__UNLINK
106     errno = 0;
107     if (0 == _unlink(fn)) {
108       back = 1;
109     } else {
110       dk4error_set_idetails(erp, DK4_E_UNLINK_FAILED, errno);
111     }
112 #else
113     dk4error_set_simple_error_code(erp, DK4_E_NOT_SUPPORTED);
114 #endif
115 #endif
116     /* --- non-Windows */
117 #endif
118   } else {
119     dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
120   }
121   return back;
122 }
123 
124