DTS Application Library  0.2.3
Application library containing referenced objects and interfaces to common libraries
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
fileutil.c
Go to the documentation of this file.
1 /*
2  Distrotech Solutions wxWidgets Gui Interface
3  Copyright (C) 2013 Gregory Hinton Nietsky <gregory@distrotech.co.za>
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
25 #include <sys/types.h>
26 #include <sys/stat.h>
27 #include <unistd.h>
28 #include <errno.h>
29 #include <string.h>
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <math.h>
33 #include <fcntl.h>
34 #include <ctype.h>
35 #ifdef __WIN32
36 #else
37 #include <grp.h>
38 #endif
39 
43 extern int is_file(const char *path) {
44  struct stat sr;
45  if (!stat(path, &sr)) {
46  return 1;
47  } else {
48  return 0;
49  }
50 }
51 
55 extern int is_dir(const char *path) {
56  struct stat sr;
57  if (!stat(path, &sr) && S_ISDIR(sr.st_mode)) {
58  return 1;
59  } else {
60  return 0;
61  }
62 }
63 
67 extern int is_exec(const char *path) {
68  struct stat sr;
69  if (!stat(path, &sr) && (S_IXUSR & sr.st_mode)) {
70  return 1;
71  } else {
72  return 0;
73  }
74 }
75 
84 #ifdef __WIN32
85 extern int mk_dir(const char *dir) {
86 #else
87 extern int mk_dir(const char *dir, mode_t mode, uid_t user, gid_t group) {
88 #endif
89  struct stat sr;
90 
91 #ifdef __WIN32
92  if ((stat(dir, &sr) && (errno == ENOENT)) && !mkdir(dir)) {
93 #else
94  if ((stat(dir, &sr) && (errno == ENOENT)) && !mkdir(dir, mode) && !chown(dir, user, group)) {
95 #endif
96  return 0;
97  }
98  return -1;
99 }
100 
int is_exec(const char *path)
Determine if a file is executable.
Definition: fileutil.c:67
int mk_dir(const char *dir, mode_t mode, uid_t user, gid_t group)
Create a directory.
Definition: fileutil.c:87
int is_file(const char *path)
Determine if a file exists.
Definition: fileutil.c:43
int is_dir(const char *path)
Determine if a path is a directory.
Definition: fileutil.c:55