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
File utility functions

Convinece wrappers arround stat. More...

Files

file  fileutil.c
 File utilities to test files (fstat)
 

Functions

int is_file (const char *path)
 Determine if a file exists. More...
 
int is_dir (const char *path)
 Determine if a path is a directory. More...
 
int is_exec (const char *path)
 Determine if a file is executable. More...
 
int mk_dir (const char *dir, mode_t mode, uid_t user, gid_t group)
 Create a directory. More...
 

Detailed Description

Convinece wrappers arround stat.

Function Documentation

int is_dir ( const char *  path)

Determine if a path is a directory.

Parameters
pathPath of directory to check.
Returns
1 if the path exists and is a directory 0 othewise.

Definition at line 55 of file fileutil.c.

55  {
56  struct stat sr;
57  if (!stat(path, &sr) && S_ISDIR(sr.st_mode)) {
58  return 1;
59  } else {
60  return 0;
61  }
62 }
int is_exec ( const char *  path)

Determine if a file is executable.

Parameters
pathPath of file to check.
Returns
1 if the path exists and is executable 0 othewise.

Definition at line 67 of file fileutil.c.

67  {
68  struct stat sr;
69  if (!stat(path, &sr) && (S_IXUSR & sr.st_mode)) {
70  return 1;
71  } else {
72  return 0;
73  }
74 }
int is_file ( const char *  path)

Determine if a file exists.

Parameters
pathFilename.
Returns
1 if the file exists 0 othewise.

Definition at line 43 of file fileutil.c.

43  {
44  struct stat sr;
45  if (!stat(path, &sr)) {
46  return 1;
47  } else {
48  return 0;
49  }
50 }
int mk_dir ( const char *  dir,
mode_t  mode,
uid_t  user,
gid_t  group 
)

Create a directory.

On *NIX systems a mode, uid and gid can be used to set initial permisions.

Parameters
dirDirectory to create.
modeInitial mode to set.
userInitial UID.
groupInitial GID.
Returns
non 0 on success on failure the directory may be created but no ownership not set.

Definition at line 87 of file fileutil.c.

87  {
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 }