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: dk4stat.ctr
12 */
13 
14 /**	@file dk4stat.c The dk4stat module.
15 */
16 
17 
18 #include "dk4conf.h"
19 #include <libdk4c/dk4stat.h>
20 #if DK4_CHAR_SIZE > 1
21 #include <libdk4c/dk4statw.h>
22 #else
23 #include <libdk4c/dk4stat8.h>
24 #endif
25 
26 #if DK4_HAVE_ASSERT_H
27 #ifndef	ASSERT_H_INCLUDED
28 #include <assert.h>
29 #define	ASSERT_H_INCLUDED 1
30 #endif
31 #endif
32 
33 
34 
35 
36 
37 
38 
39 int
dk4stat_is_regular(const dk4_stat_t * stb,dk4_er_t * erp)40 dk4stat_is_regular(const dk4_stat_t *stb, dk4_er_t *erp)
41 {
42   int		back	=	0;
43 #if	DK4_USE_ASSERT
44   assert(NULL != stb);
45 #endif
46   if (NULL != stb) {
47 #if DK4_ON_WINDOWS
48     if (((stb->st_mode) & _S_IFMT) == _S_IFREG) {
49       back = 1;
50     }
51 #else
52     if (((stb->st_mode) & S_IFMT) == S_IFREG) {
53       back = 1;
54     }
55 #endif
56   } else {
57     dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
58   }
59   return back;
60 }
61 
62 
63 
64 int
dk4stat_is_directory(const dk4_stat_t * stb,dk4_er_t * erp)65 dk4stat_is_directory(const dk4_stat_t *stb, dk4_er_t *erp)
66 {
67   int		back	=	0;
68 #if	DK4_USE_ASSERT
69   assert(NULL != stb);
70 #endif
71   if (NULL != stb) {
72 #if DK4_ON_WINDOWS
73     if (((stb->st_mode) & _S_IFMT) == _S_IFDIR) {
74       back = 1;
75     }
76 #else
77     if (((stb->st_mode) & S_IFMT) == S_IFDIR) {
78       back = 1;
79     }
80 #endif
81   } else {
82     dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
83   }
84   return back;
85 }
86 
87 
88 int
dk4stat_is_symlink(const dk4_stat_t * stb,dk4_er_t * erp)89 dk4stat_is_symlink(const dk4_stat_t *stb, dk4_er_t *erp)
90 {
91   int		back	=	0;
92 #if	DK4_USE_ASSERT
93   assert(NULL != stb);
94 #endif
95   if (NULL != stb) {
96 #if DK4_ON_WINDOWS
97 
98 #else
99 #if defined(S_IFMT) && defined(S_IFLNK)
100     if (S_IFLNK == ((stb->st_mode) & S_IFMT)) {
101       back = 1;
102     }
103 #endif
104 #endif
105   } else {
106     dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
107   }
108   return back;
109 }
110 
111 
112 
113 int
dk4stat_is_unix_domain_socket(const dk4_stat_t * stb,dk4_er_t * erp)114 dk4stat_is_unix_domain_socket(const dk4_stat_t *stb, dk4_er_t *erp)
115 {
116   int		 back	= 0;
117 #if	DK4_USE_ASSERT
118   assert(NULL != stb);
119 #endif
120   if (NULL != stb) {
121 #if DK4_ON_WINDOWS
122 
123 #else
124 #if defined(S_IFMT) && defined(S_IFSOCK)
125     if (S_IFSOCK == ((stb->st_mode) & S_IFMT)) {
126       back = 1;
127     }
128 #endif
129 #endif
130   } else {
131     dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
132   }
133   return back;
134 }
135