dksf.h File Reference

Access to system functions. More...

#include <dk.h>
#include <dktypes.h>
#include <dksfc.h>

Go to the source code of this file.

Defines

#define DK_SF_SEC_WG   1
 Security check: File group writable?
#define DK_SF_SEC_WO   2
 Security check: File writable for others (all)?
#define DK_SF_SEC_OWNER   4
 Security check: For symlinks, do symlink owner and file owner match?
#define DK_SF_SEC_DIR   8
 Security check: Is the path name a directory?

Functions

dk_stat_tdkstat_open (char *n)
 Create a dk_stat_t structure and collect information about a file.
dk_stat_tdkstat_new (void)
 Create a new empty dk_stat_t structure.
int dkstat_get (dk_stat_t *p, char *n)
 Load information about a file into a dk_stat_t structure.
void dkstat_delete (dk_stat_t *p)
 Release memory for a structure obtained by dkstat_new().
void dkstat_close (dk_stat_t *p)
 Close a dk_stat_t structure obtained by dkstat_open() and release memory.
int dkstat_filetype (dk_stat_t *p)
 Get file type.
int dkstat_permissions (dk_stat_t *p)
 Get permissions.
unsigned long dkstat_inode (dk_stat_t *p)
 Get inode number.
unsigned long dkstat_device (dk_stat_t *p)
 Get device number.
unsigned long dkstat_rdevice (dk_stat_t *p)
 Get relative device number.
unsigned long dkstat_nlinks (dk_stat_t *p)
 Get number of links.
dk_long_long_unsigned_t dkstat_size (dk_stat_t *p)
 Get file size.
dk_long_long_unsigned_t dkstat_size_ok (dk_stat_t *p, int *ok)
 Get file size, indicate numeric overflow error if necessary.
long dkstat_uid (dk_stat_t *p)
 Get owner UID.
long dkstat_gid (dk_stat_t *p)
 Get owner GID.
char * dkstat_ctime (dk_stat_t *p)
 Get creation time.
char * dkstat_atime (dk_stat_t *p)
 Get last access time.
char * dkstat_mtime (dk_stat_t *p)
 Get last modification time.
int dkstat_far_link (dk_stat_t *p)
 Check whether or not the file is a far symbolic link (link to a destination outside the current file system).
dk_dir_tdkdir_open (char *n)
 Open a directory.
void dkdir_close (dk_dir_t *d)
 Close a directory.
dk_dir_tdkdir_new (void)
 Create a new empty dk_dir_t structure.
void dkdir_delete (dk_dir_t *d)
 Release memory for dk_dir_t structure.
int dkdir_start_search (dk_dir_t *d, char *n)
 Start traversing directory.
void dkdir_end_search (dk_dir_t *d)
 End traversing a directory.
int dkdir_next (dk_dir_t *d)
 Check for next directory entry.
char * dkdir_get_fullname (dk_dir_t *d)
 Retrieve full file name.
char * dkdir_get_shortname (dk_dir_t *d)
 Retrieve short file name.
long dkdir_uid (dk_dir_t *d)
 Get owner UID.
long dkdir_gid (dk_dir_t *d)
 Get owner GID.
char * dkdir_ctime (dk_dir_t *d)
 Get creation time.
char * dkdir_atime (dk_dir_t *d)
 Get last access time.
char * dkdir_mtime (dk_dir_t *d)
 Get modification time.
int dkdir_filetype (dk_dir_t *d)
 Get file type.
int dkdir_permissions (dk_dir_t *d)
 Get permissions.
unsigned long dkdir_inode (dk_dir_t *d)
 Get inode number.
unsigned long dkdir_device (dk_dir_t *d)
 Get device number.
unsigned long dkdir_rdevice (dk_dir_t *d)
 Get relative device number.
unsigned long dkdir_nlinks (dk_dir_t *d)
 Get number of links.
dk_long_long_unsigned_t dkdir_size (dk_dir_t *d)
 Get entry size.
dk_long_long_unsigned_t dkdir_size_ok (dk_dir_t *d, int *ok)
 Get entry size and check for overflow.
dk_stat_tdkdir_stat (dk_dir_t *d)
 Retrieve all information about the current entry.
int dksf_must_expand_filename (char *n)
 Check whether file name needs expansion.
dk_fne_tdkfne_open (char *n, int f, int d)
 Open file name expander.
void dkfne_close (dk_fne_t *f)
 Close file name expander.
int dkfne_next (dk_fne_t *f)
 Check for next file matching the pattern.
char * dkfne_get_one (dk_fne_t *f)
 Check whether or not the pattern matches exactly one file name.
char * dkfne_get_fullname (dk_fne_t *f)
 Get full file name.
char * dkfne_get_shortname (dk_fne_t *f)
 Get short file name.
int dkfne_get_error_code (dk_fne_t *f, int r)
 Retrieve error code.
int dksf_mkdir (char *p, int m)
 Make directory.
int dksf_chmod (char *p, int m)
 Change access permissions.
int dksf_fchmod (int fd, int m)
 Change access permissions of an opened file.
int dksf_have_getuid (void)
 Check whether the system supports user IDs.
long dksf_getuid (void)
 Get current user ID.
int dksf_have_geteuid (void)
 Check whether the system supports dksf_geteuid().
long dksf_geteuid (void)
 Get effective user ID.
int dksf_have_getgid (void)
 Check whether the system supports group IDs and dksf_getgid().
long dksf_getgid (void)
 Get group ID.
int dksf_have_getegid (void)
 Check whether the system supports dksf_getegid().
long dksf_getegid (void)
 Get effective group ID.
int dksf_have_getpid (void)
 Check whether the system supports process IDs and dksf_getpid().
long dksf_getpid (void)
 Get process ID.
int dksf_have_getppid (void)
 Check whether the system supports dksf_getppid().
long dksf_getppid (void)
 Get parent process ID.
int dksf_have_getpgrp (void)
 Check whether the system supports process group IDs and dksf_getpgrp().
long dksf_getpgrp (void)
 Get process group ID.
int dksf_have_getpgid (void)
 Check whether the system supports dksf_getpgid().
long dksf_getpgid (long p)
 Get process group ID of another process.
int dksf_get_uname (char *b, size_t s)
 Get current user name.
int dksf_get_euname (char *b, size_t s)
 Get effective user name.
int dksf_get_home (char *b, size_t s)
 Get current users home directory.
int dksf_get_ehome (char *b, size_t s)
 Get effective users home directory.
int dksf_get_hostname (char *b, size_t s)
 Get host name.
int dksf_get_domainname (char *b, size_t s)
 Get DNS domain name of host.
int dksf_get_tempdir (char *b, size_t s)
 Get name of directory for temporary files.
long dksf_get_maxpathlen (void)
 Get maximum length of a path in characters.
long dksf_get_maxfiles (void)
 Get maximum number of open files.
int dksf_getcwd (char *b, size_t s)
 Get current working directory.
int dksf_get_executable (char *b, size_t s, char *d, char *p, int w)
 Get full file name (including path) of executable file.
int dksf_path_combine (char *b, size_t s, char *c, char *p)
 Combine paths.
int dksf_is_abs_path (char *p)
 Check absolute path name.
char * dksf_get_file_type_dot (char *p)
 Find file name suffix.
char * dksf_get_last_filename (char *p)
 Find last path name component.
void dksf_time_convert (char *b, time_t t)
 Convert time stamp to text representation.
void dksf_correct_fnsep (char *p)
 Correct file name separators.
int dksf_remove_directory (char *p)
 Remove directory.
int dksf_remove_file (char *p)
 Remove a file.
int dksf_allowed_to_write (char *p, int i, int *r)
 Security checks before overwriting a file.
FILE * dksf_msfo (char *p, char *m, int i, int *r)
 Open a file, apply security checks.
FILE * dksf_fopen (char *p, char *m)
 Open a file, apply security checks.
int dksf_fdesk_binary (int f, int b)
 Switch file descriptor to binary mode.
int dksf_get_filetype (char *p)
 Get file type.
int dksf_is_directory (char *p)
 Check whether a path name is a directory.
int dksf_no_core (void)
 Deny the creation of core files.
int dksf_echo_test_tty (void)
 Check whether or not standard input is connected to a terminal.
int dksf_echo_save (dk_echo_t *e)
 Save current keyboard echo setting.
int dksf_echo_restore (dk_echo_t *e)
 Restore keyboard echo setting.
int dksf_echo_is_tty (dk_echo_t *e)
 Check whether the keyboard echo data belongs to a terminal.
int dksf_echo_off (dk_echo_t *e)
 Turn keyboard echo off.
unsigned long dksf_filesize_bytes (void)
 Get size of file size data type in bytes.
unsigned long dksf_long_long_bytes (void)
 Get size of long long type in bytes.
int dksf_must_rebuild (char *d, char *s)
 Check whether a destination file must be rebuild.


Detailed Description

Access to system functions.

Unless otherwise stated, int functions in this module return a positive number to indicate success or a true condition, 0 to indicate an error or an unfullfilled condition. Pointer functions return valid pointers on success, NULL on error.

The dkstat_xxx() function group can be used to obtain information about a file or directory. In a first step information about the file is collected and stored in a dk_stat_t data structure. The further dkstat_xxx() functions can be used to retrieve details from the structure.

          dk_stat_t *p;
          p = dk_stat_open("x.txt");
          if(p) {
            ... retrieve information from p ...
            dkstat_close(p);
          }

The dkdir_xxx() function group can be used to traverse directories.

          dk_dir_t *p;
          p = dkdir_open(".");
          if(p) {
            while(dkdir_next(p)) {
              ... yet another entry found ...
              ... retrieve information from p ...
            }
            dkdir_close(p);
          }

The dkfne_xxx() function group can be used to expand file name patterns (some Windows command interpreters do not expand wildcards and leave this up to applications).

To find all regular file names (1 in dkfne_open()) but no directories (0 in dkfne_open()) matching a file name pattern n use:

        char *n = ... file name ... ;
        char *fn = NULL;
        dk_fne_t *fne;
        if(dksf_must_expand_filename(n)) {
          fne = dkfne_open(n, 1, 0);
          if(fne) {
            while(dkfne_next(fne)) {
              fn = dkfne_get_fullname(fne);
              ... fn is a file name ...
            }
            dkfne_close(fne);
            ... fn can not longer be used, it pointed into fne ...
          } else {
            ... error, failed to create fne ...
          }
        }

If file name pattern n should choose exactly one file name use:

        char *n = ... file name ... ;
        char *fn = NULL;
        dk_fne_t *fne;
        if(dksf_must_expand_filename(n)) {
          fne = dkfne_open(n, 1, 0);
          if(fne) {
            fn = dkfne_get_one(fne);
            if(fn) {
              ... fn is a file name ...
            } else {
              ... error, not exactly one name matches ...
            }
            dkfne_close(fne);
            ... fn can not longer be used, it pointed into fne ...
          } else {
            ... error, failed to create fne ...
          }
        }

The dksf_echo_xxx() function group deals with keyboard echo on terminals.

          dk_echo_t echodata;
          if(dksf_echo_test_tty()) {
            ... standard input is connected to terminal ...
            if(dksf_echo_save(&echodata)) {
              if(dksf_echo_off(&echodata)) {
                ... ask user for password ...
                ... read password from standard input ...
              } else {
                ... error, failed to turn echo off ...
              }
              dksf_echo_restore(&echodata);
            } else {
              ... error, failed to save current echo state ...
            }
          } else {
            ... error, standard input is not a terminal ...
          }

Function Documentation

char* dkdir_atime ( dk_dir_t d  ) 

Get last access time.

Parameters:
d Directory structure.
Returns:
The last access time stamp as text.

void dkdir_close ( dk_dir_t d  ) 

Close a directory.

Parameters:
d Directory to close.

char* dkdir_ctime ( dk_dir_t d  ) 

Get creation time.

Parameters:
d Directory structure.
Returns:
The creation time as text.

void dkdir_delete ( dk_dir_t d  ) 

Release memory for dk_dir_t structure.

Parameters:
d Directory structure.

unsigned long dkdir_device ( dk_dir_t d  ) 

Get device number.

Parameters:
d Directory structure.
Returns:
The device number.

void dkdir_end_search ( dk_dir_t d  ) 

End traversing a directory.

The function finishes a directory traversal formerly started by dkdir_start_search().

Parameters:
d Directory structure.

int dkdir_filetype ( dk_dir_t d  ) 

Get file type.

Parameters:
d Directory structure.
Returns:
The file type.

char* dkdir_get_fullname ( dk_dir_t d  ) 

Retrieve full file name.

Parameters:
d Directory structure.
Returns:
The full file name of the last entry found.

char* dkdir_get_shortname ( dk_dir_t d  ) 

Retrieve short file name.

Parameters:
d Directory structure.
Returns:
The short file name of the last entry found.

long dkdir_gid ( dk_dir_t d  ) 

Get owner GID.

Parameters:
d Directory structure.
Returns:
The owners GID.

unsigned long dkdir_inode ( dk_dir_t d  ) 

Get inode number.

Parameters:
d Directory structure.
Returns:
The inode number.

char* dkdir_mtime ( dk_dir_t d  ) 

Get modification time.

Parameters:
d Directory structure.
Returns:
Modification time stamp as text.

dk_dir_t* dkdir_new ( void   ) 

Create a new empty dk_dir_t structure.

A pointer to a the new structure is returned. The memory must be release using dkdir_delete() after usage.

Returns:
Pointer to the new structure.

int dkdir_next ( dk_dir_t d  ) 

Check for next directory entry.

This function checks whether or not there is yet another entry in the directory which was not yet found in the current directory traversal. If this function returns successfully you can use the functions below -- dkdir_get_fullname(), dkdir_get_shortname(), dkdir_uid(), dkdir_gid(), dkdir_ctime(), dkdir_atime(), dkdir_mtime(), dkdir_filetype(), dkdir_permissions(), dkdir_inode(), dkdir_device(), dkdir_rdevice(), dkdir_nlinks(), dkdir_size() and dkdir_size_ok() -- to obtain information about the entry. The char * functions return pointers to elements of d, these pointers can not longer be used after dkdir_delete() or dkdir_close(). The d members will change in the next call to dkdir_next().

Parameters:
d Directory structure.
Returns:
Flag to indicate success.

unsigned long dkdir_nlinks ( dk_dir_t d  ) 

Get number of links.

Parameters:
d Directory structure.
Returns:
The number of links.

dk_dir_t* dkdir_open ( char *  n  ) 

Open a directory.

Parameters:
n Name of directory.
Returns:
Pointer to directory traversal structure dk_dir_t. The dk_dir_t structure must be released after usage calling dkdir_close().

int dkdir_permissions ( dk_dir_t d  ) 

Get permissions.

Parameters:
d Directory structure.
Returns:
The file permissions.

unsigned long dkdir_rdevice ( dk_dir_t d  ) 

Get relative device number.

Parameters:
d Directory structure.
Returns:
The relative device number.

dk_long_long_unsigned_t dkdir_size ( dk_dir_t d  ) 

Get entry size.

Parameters:
d Directory structure.
Returns:
The file size of the entry.

dk_long_long_unsigned_t dkdir_size_ok ( dk_dir_t d,
int *  ok 
)

Get entry size and check for overflow.

Parameters:
d Directory structure
ok Pointer to variable receiving an error code if an error occurs.
Returns:
The file size of the entry.

int dkdir_start_search ( dk_dir_t d,
char *  n 
)

Start traversing directory.

The function starts a new directory traversal for a dk_dir_t structure. This is only necessary for a dk_dir_t obtained from dkdir_new().

Parameters:
d Directory structure.
n Name of directory.
Returns:
Flag to indicate success.

dk_stat_t* dkdir_stat ( dk_dir_t d  ) 

Retrieve all information about the current entry.

This function returns a pointer to a member of d. Do not attempt to release this memory using dkstat_close(). The pointer can not be used after the dk_dir_t structure was released using dkdir_close() or dkdir_delete().

Parameters:
d Directory structure.
Returns:
Pointer to file information.

long dkdir_uid ( dk_dir_t d  ) 

Get owner UID.

Parameters:
d Directory structure.
Returns:
The entry owners UID.

void dkfne_close ( dk_fne_t f  ) 

Close file name expander.

Parameters:
f File name expander to close and release.

int dkfne_get_error_code ( dk_fne_t f,
int  r 
)

Retrieve error code.

This function returns the error code for the last error occured. Optionally the error code variable can be reset.

Parameters:
f File name expander.
r Flag to indicate whether (non-zero value) or not (0) the error code member variable must be reset.
Returns:
The error code of the last error.

char* dkfne_get_fullname ( dk_fne_t f  ) 

Get full file name.

Parameters:
f File name expander.
Returns:
Pointer to the file name.

char* dkfne_get_one ( dk_fne_t f  ) 

Check whether or not the pattern matches exactly one file name.

If the function returns successfully you can use dkfne_get_fullname() or dkfne_get_shortname() to retrieve the name of the entry found. These functions return pointers to components of f, so the pointer can not be used after releasing the structure using dkfne_close(). The components are modified by the next call to dkfne_next() or dkfne_get_one().

Parameters:
f File name expander.
Returns:
Flag to indicate success.

char* dkfne_get_shortname ( dk_fne_t f  ) 

Get short file name.

Parameters:
f File name expander.
Returns:
Pointer to the file name.

int dkfne_next ( dk_fne_t f  ) 

Check for next file matching the pattern.

If the function returns successfully you can use dkfne_get_fullname() or dkfne_get_shortname() to retrieve the name of the entry found. These functions return pointers to components of f, so the pointer can not be used after releasing the structure using dkfne_close(). The components are modified by the next call to dkfne_next() or dkfne_get_one().

Parameters:
f File name expander.
Returns:
Flag to indicate success.

dk_fne_t* dkfne_open ( char *  n,
int  f,
int  d 
)

Open file name expander.

The file name expander structure (dk_fne_t) is created in dynamically allocated memory, you must release it after usage calling the dkfne_close() function.

Parameters:
n File name pattern containing wildcards ('*', '?').
f Flag whether (non-zero value) or not (0) to search for files.
d Flag whether (non-zero value) nor not (0) to search for directories.
Returns:
Pointer to new file name expander on success, NULL on error.

int dksf_allowed_to_write ( char *  p,
int  i,
int *  r 
)

Security checks before overwriting a file.

This function checks whether a file can be overwritten. Even if file permissions allow writing we should do additional checks:

  • The file must not be a directory (DK_SF_SEC_DIR).
  • For symbolic links the following checks are added:
    • The symbolic link owner must be the owner of the link destination (DK_SF_SEC_OWNER).
    • The symbolic link must not reside in a group writable directory (DK_SF_SEC_WG).
    • The symbolic link must not reside in a public writable directory (DK_SF_SEC_WO).
      Parameters:
      p Path name of file to open.
      i Security checks to ignore (or-combination of DK_SF_SEC_xxx constants.
      r Pointer to a variable to receive the reason if opening The file is denied due to failed security checks.
      Returns:
      Flag to indicate whether or not the file can be written.

int dksf_chmod ( char *  p,
int  m 
)

Change access permissions.

Parameters:
p Path name of the file or directory.
m New access permissions (or-combination of DK_PERM_...-constants).
Returns:
Flag to indicate success.

void dksf_correct_fnsep ( char *  p  ) 

Correct file name separators.

Some systems use slashes other systems use backslashes to separate parts in a path name. This function converts slashes into backslashes or backslashes into slashes.

Parameters:
p Path name.

int dksf_echo_is_tty ( dk_echo_t e  ) 

Check whether the keyboard echo data belongs to a terminal.

Parameters:
e Structure for keyboard echo data.
Returns:
Check result.

int dksf_echo_off ( dk_echo_t e  ) 

Turn keyboard echo off.

Parameters:
e Structure for keyboard echo data.
Returns:
Flag to indicate success.

int dksf_echo_restore ( dk_echo_t e  ) 

Restore keyboard echo setting.

Parameters:
e Structure to restore data from.
Returns:
Flag to indicate success.

int dksf_echo_save ( dk_echo_t e  ) 

Save current keyboard echo setting.

Parameters:
e Structure to save data to.
Returns:
Flag to indicate success.

int dksf_echo_test_tty ( void   ) 

Check whether or not standard input is connected to a terminal.

Returns:
Check result.
Examples:
stotest.c.

int dksf_fchmod ( int  fd,
int  m 
)

Change access permissions of an opened file.

Parameters:
fd File descriptor.
m New access permissions (or-combination of DK_PER_...-constants).
Returns:
Flag to indicate success.

int dksf_fdesk_binary ( int  f,
int  b 
)

Switch file descriptor to binary mode.

On Windows systems this function switches a file descriptor f to binary or text mode depending on the b flag. On other systems this function has no impact.

Parameters:
f File descriptor.
b Flag to indicate whether to bring the file descriptor into binary or text mode.
Returns:
Flag to indicate whether or not the file descriptor was in binary mode before the function was invoked.

unsigned long dksf_filesize_bytes ( void   ) 

Get size of file size data type in bytes.

Returns:
The size.

FILE* dksf_fopen ( char *  p,
char *  m 
)

Open a file, apply security checks.

This function is intended as a replacement for fopen(). Before calling fopen() all the DK_SF_SEC_xxx security checks are applied.

Parameters:
p Path name of file to open.
m File open mode, i.e. "r", "w"...
Returns:
Pointer to FILE structure.
Examples:
stotest.c.

int dksf_get_domainname ( char *  b,
size_t  s 
)

Get DNS domain name of host.

Parameters:
b Pointer to buffer receiving the result.
s Size of b.
Returns:
Success flag.

int dksf_get_ehome ( char *  b,
size_t  s 
)

Get effective users home directory.

Parameters:
b Pointer to buffer receiving the result.
s Size of b.
Returns:
Success flag.

int dksf_get_euname ( char *  b,
size_t  s 
)

Get effective user name.

Parameters:
b Pointer to buffer receiving the result.
s Size of b.
Returns:
Success flag.

int dksf_get_executable ( char *  b,
size_t  s,
char *  d,
char *  p,
int  w 
)

Get full file name (including path) of executable file.

Parameters:
b Pointer to buffer receiving the result.
s Size of b.
d Current working directory.
p Program name from argv[0].
w Flag to allow Windows functions GetModuleFileNameA() and GetModuleHandle() on Windows systems. Recommended value: 1.
Returns:
Success flag.

char* dksf_get_file_type_dot ( char *  p  ) 

Find file name suffix.

The function searches for the suffix of the file name p.

Parameters:
p Path name.
Returns:
Pointer to the dot starting the file name suffix.

int dksf_get_filetype ( char *  p  ) 

Get file type.

This function returns the file type (regular file, directory, socket...) as DK_SF_FT_xxx constant.

Parameters:
p Path name.
Returns:
The file type.

int dksf_get_home ( char *  b,
size_t  s 
)

Get current users home directory.

Parameters:
b Pointer to buffer receiving the result.
s Size of b.
Returns:
Success flag.

int dksf_get_hostname ( char *  b,
size_t  s 
)

Get host name.

Parameters:
b Pointer to buffer receiving the result.
s Size of b.
Returns:
Success flag.

char* dksf_get_last_filename ( char *  p  ) 

Find last path name component.

Parameters:
p Path name.
Returns:
Pointer to last component in path name.

long dksf_get_maxfiles ( void   ) 

Get maximum number of open files.

Returns:
Maximum number of open files.

long dksf_get_maxpathlen ( void   ) 

Get maximum length of a path in characters.

Returns:
Maximum path length.

int dksf_get_tempdir ( char *  b,
size_t  s 
)

Get name of directory for temporary files.

Parameters:
b Pointer to buffer receiving the result.
s Size of b.
Returns:
Success flag.

int dksf_get_uname ( char *  b,
size_t  s 
)

Get current user name.

Parameters:
b Pointer to buffer receiving the result.
s Size of b.
Returns:
Success flag.

int dksf_getcwd ( char *  b,
size_t  s 
)

Get current working directory.

Parameters:
b Pointer to buffer receiving the result.
s Size of b.
Returns:
Success flag.

long dksf_getegid ( void   ) 

Get effective group ID.

Returns:
The effective group ID.

long dksf_geteuid ( void   ) 

Get effective user ID.

Returns:
The effective user ID.

long dksf_getgid ( void   ) 

Get group ID.

Returns:
The group ID.

long dksf_getpgid ( long  p  ) 

Get process group ID of another process.

Parameters:
p The process ID of a process.
Returns:
The process group id of p.

long dksf_getpgrp ( void   ) 

Get process group ID.

Returns:
The processgroup ID of the current process.

long dksf_getpid ( void   ) 

Get process ID.

Returns:
The process ID.

long dksf_getppid ( void   ) 

Get parent process ID.

Returns:
The process ID of the parent process.

long dksf_getuid ( void   ) 

Get current user ID.

Returns:
The user ID.

int dksf_have_getegid ( void   ) 

Check whether the system supports dksf_getegid().

Returns:
Flag to indicate whether the system supports dksf_getedid().

int dksf_have_geteuid ( void   ) 

Check whether the system supports dksf_geteuid().

Returns:
Flag to indicate whether the system supports dksf_geteuid().

int dksf_have_getgid ( void   ) 

Check whether the system supports group IDs and dksf_getgid().

Returns:
Flag to indicate whether the system supports dksf_getgid().

int dksf_have_getpgid ( void   ) 

Check whether the system supports dksf_getpgid().

Returns:
Flag to indicate whether the system supports dksf_getpgid().

int dksf_have_getpgrp ( void   ) 

Check whether the system supports process group IDs and dksf_getpgrp().

Returns:
Flag to indicate whether the system supports dksf_getpgrp().

int dksf_have_getpid ( void   ) 

Check whether the system supports process IDs and dksf_getpid().

Returns:
Flag to indicate whether the system supports dksf_getpid().

int dksf_have_getppid ( void   ) 

Check whether the system supports dksf_getppid().

Returns:
Flag to indicate whether the system supports dksf_getppid().

int dksf_have_getuid ( void   ) 

Check whether the system supports user IDs.

Returns:
Flag to indicate whether the system supports user IDs.

int dksf_is_abs_path ( char *  p  ) 

Check absolute path name.

The function checks, whether or not p is an absolute path name.

Parameters:
p The path name to check
Returns:
Flag to indicate whether or not p is an absolute path name.

int dksf_is_directory ( char *  p  ) 

Check whether a path name is a directory.

Parameters:
p Path name.
Returns:
Flag to indicate whether or not the path is a directory.

unsigned long dksf_long_long_bytes ( void   ) 

Get size of long long type in bytes.

Returns:
The size.

int dksf_mkdir ( char *  p,
int  m 
)

Make directory.

Parameters:
p Path name of the new directory.
m Access permissions to the new directory (or-combined DK_PERM_...-constants).
Returns:
Flag to indicate success.

FILE* dksf_msfo ( char *  p,
char *  m,
int  i,
int *  r 
)

Open a file, apply security checks.

Before opening the file this function uses dksf_allowed_to_write() for additional security checks.

Parameters:
p Path name of file to open
m File open mode, i.e. "r", "w",...
i Security checks to ignore (or-combination of DK_SF_SEC_xxx constants).
r Pointer to a variable to receive the reason if opening the file is denied due to failed security checks.
Returns:
Pointer to a FILE structure.

int dksf_must_expand_filename ( char *  n  ) 

Check whether file name needs expansion.

This function checks whether the file name must be expanded. A file name must be expanded on Windows systems if the name contains wildcards ('*' or '?').

Parameters:
n File name to inspect.
Returns:
Flag to indicate whether or not the file name must be expanded.

int dksf_must_rebuild ( char *  d,
char *  s 
)

Check whether a destination file must be rebuild.

Parameters:
d Name of destination file.
s Name of source file.
Returns:
1 for rebuild, 0 for not necessary.

int dksf_no_core ( void   ) 

Deny the creation of core files.

This functtion sets the allowed size of core files to 0 if supported by the system.

int dksf_path_combine ( char *  b,
size_t  s,
char *  c,
char *  p 
)

Combine paths.

Parameters:
b Pointer to buffer receiving the result.
s Size of b.
c Base directory (i.e. current directory).
p Path name to add.
Returns:
Success flag.

int dksf_remove_directory ( char *  p  ) 

Remove directory.

The directory is removed, including all contents.

Parameters:
p Path name of directory to delete.
Returns:
Success flag.

int dksf_remove_file ( char *  p  ) 

Remove a file.

Parameters:
p Path name of the file.
Returns:
Success flag.

void dksf_time_convert ( char *  b,
time_t  t 
)

Convert time stamp to text representation.

Parameters:
b Buffer to receive result, must be 21 at least.
t Time stamp.

char* dkstat_atime ( dk_stat_t p  ) 

Get last access time.

Parameters:
p Pointer to dk_stat_t structure.
Returns:
Pointer to string containing last access time as text.

void dkstat_close ( dk_stat_t p  ) 

Close a dk_stat_t structure obtained by dkstat_open() and release memory.

Parameters:
p Pointer to dk_stat_t structure to release.

char* dkstat_ctime ( dk_stat_t p  ) 

Get creation time.

Parameters:
p Pointer to dk_stat_t structure.
Returns:
Pointer to string containing creation time as text.

void dkstat_delete ( dk_stat_t p  ) 

Release memory for a structure obtained by dkstat_new().

Parameters:
p Pointer to dk_stat_t structure to release.

unsigned long dkstat_device ( dk_stat_t p  ) 

Get device number.

Parameters:
p Pointer to dk_stat_t structure.
Returns:
The device number.

int dkstat_far_link ( dk_stat_t p  ) 

Check whether or not the file is a far symbolic link (link to a destination outside the current file system).

Parameters:
p Pointer to dk_stat_t structure.
Returns:
Flag to indicate whether or not the file is a far link.

int dkstat_filetype ( dk_stat_t p  ) 

Get file type.

The file type is returned as DK_FT_xxx constant. If the file name pointed to a symbolic link the result is an or-combination of the real file type and DK_FT_SYMLINK.

Parameters:
p Pointer to dk_stat_t structure.
Returns:
The file type.

int dkstat_get ( dk_stat_t p,
char *  n 
)

Load information about a file into a dk_stat_t structure.

Parameters:
p Pointer to dk_stat_t structure.
n File name.
Returns:
Flag indicating success.

long dkstat_gid ( dk_stat_t p  ) 

Get owner GID.

Parameters:
p Pointer to dk_stat_t structure.
Returns:
Owner GID.

unsigned long dkstat_inode ( dk_stat_t p  ) 

Get inode number.

Parameters:
p Pointer to dk_stat_t structure.
Returns:
The inode number.

char* dkstat_mtime ( dk_stat_t p  ) 

Get last modification time.

Parameters:
p Pointer to dk_stat_t structure.
Returns:
Pointer to string containing last modification time as text.

dk_stat_t* dkstat_new ( void   ) 

Create a new empty dk_stat_t structure.

Memory for this structure is allocated dynamically, call dkstat_delete() to release the memory after usage. The structure only contains default values, use dkstat_get() to load information about a file into the structure.

Returns:
Pointer to the new structure, NULL on error.

unsigned long dkstat_nlinks ( dk_stat_t p  ) 

Get number of links.

Parameters:
p Pointer to dk_stat_t structure.
Returns:
The number of links.

dk_stat_t* dkstat_open ( char *  n  ) 

Create a dk_stat_t structure and collect information about a file.

The function collects information about the file n and stores it into a new dk_stat_t structure. Memory for this structure is allocated dynamically, call dkstat_close() to release the memory after usage.

Parameters:
n The file name.
Returns:
Pointer to the new structure, NULL on error.

int dkstat_permissions ( dk_stat_t p  ) 

Get permissions.

The permissions are an or-combination of DK_PERM_xxx constants.

Parameters:
p Pointer to dk_stat_t structure.
Returns:
Permissions to the file.

unsigned long dkstat_rdevice ( dk_stat_t p  ) 

Get relative device number.

Parameters:
p Pointer to dk_stat_t structure.
Returns:
The relative device number.

dk_long_long_unsigned_t dkstat_size ( dk_stat_t p  ) 

Get file size.

Parameters:
p Pointer to dk_stat_t structure.
Returns:
The file size.

dk_long_long_unsigned_t dkstat_size_ok ( dk_stat_t p,
int *  ok 
)

Get file size, indicate numeric overflow error if necessary.

Parameters:
p Pointer to dk_stat_t structure.
ok Pointer to variable to receive the error code. The variable is left untouched if no error occures. If there was an error while retrieving the file size the variable is set to DK_ERR_MATH_OOR.
Returns:
The file size.

long dkstat_uid ( dk_stat_t p  ) 

Get owner UID.

Parameters:
p Pointer to dk_stat_t structure.
Returns:
Owner UID.


Generated on Mon Jan 4 15:50:56 2010 for dklibs by  doxygen 1.5.8