dir.h File Reference

Genericised directory functions. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef bool(* ctl_dircallback )(const char *, bool, void *)

Functions

 ppCPP (extern"C"{) char *ctl_cwd(char *buffer
bool ctl_chdir (const char *path)
 Change working directory.
void ctl_move (const char *src, const char *dst)
 Change an existing file's name and/or location.
void ctl_copy (const char *src, const char *dst)
 Copy a file.
void ctl_unlink (const char *path)
 Remove a file.
void ctl_mkdir (const char *path)
 Make a directory.
void ctl_rmdir (const char *path)
 Remove an EMPTY directory.


Detailed Description

Genericised directory functions.

Author:
David Mace

Definition in file dir.h.


Typedef Documentation

typedef bool(* ctl_dircallback)(const char *, bool, void *)

Callback for ctl_iterate; (path, flag for whether it's a directory, your instance)

Definition at line 20 of file dir.h.


Function Documentation

bool ctl_chdir ( const char *  path  ) 

Change working directory.

Parameters:
path New path to change app's working directory to

Definition at line 65 of file dir.c.

References assertconst.

00066 {
00067     assertconst(path,1);
00068 #ifdef WIN32
00069     return (bool)SetCurrentDirectory(path);
00070 #else
00071     return (bool)(0 != chdir(path));
00072 #endif
00073 }

void ctl_copy ( const char *  src,
const char *  dst 
)

Copy a file.

Parameters:
src Path to original file
dst Path to destination, including the file name

Definition at line 98 of file dir.c.

References assertconst.

00099 {
00100     assertconst(src,1);
00101     assertconst(dst,1);
00102 #ifdef WIN32
00103     CopyFile( src, dst, FALSE );
00104 #else
00105     int srcfd = open ( src, O_RDONLY|O_BINARY );
00106     if (srcfd >= 0)
00107     {
00108         int destfd = open( dst, O_CREAT|O_TRUNC|O_RDWR|O_BINARY, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH );
00109         if (destfd >= 0)
00110         {
00111             char buff[32768];
00112             ssize_t nread = read(srcfd, buff, sizeof (buff));
00113             ssize_t nwrote;
00114             while (nread > 0)
00115             {
00116                 nwrote = write(destfd, buff, nread);
00117                 if( nwrote != nread )
00118                     break;
00119                 nread = read(srcfd, buff, sizeof (buff));
00120             }
00121             close(destfd);
00122         }
00123         close(srcfd);
00124     }
00125 #endif
00126 }

void ctl_mkdir ( const char *  path  ) 

Make a directory.

Parameters:
path Path to create

Definition at line 163 of file dir.c.

References assertconst.

00164 {
00165     assertconst(path,1);
00166 #ifdef WIN32
00167     CreateDirectory(path,NULL);
00168 #else
00169     /* Let this user and his whole group play with it (assuming umask permits it) */
00170     mkdir( path, S_IRWXU | S_IRWXG );
00171 #endif
00172 }

void ctl_move ( const char *  src,
const char *  dst 
)

Change an existing file's name and/or location.

Parameters:
src Path to original file
dst Path to destination, including the file name

Definition at line 81 of file dir.c.

References assertconst.

00082 {
00083     assertconst(src,1);
00084     assertconst(dst,1);
00085 #ifdef WIN32
00086     MoveFileEx( src, dst, MOVEFILE_COPY_ALLOWED|MOVEFILE_REPLACE_EXISTING );
00087 #else
00088     rename( src, dst );
00089 #endif
00090 }

void ctl_rmdir ( const char *  path  ) 

Remove an EMPTY directory.

Parameters:
path Path to remove (won't remove it if path isn't empty)

Definition at line 148 of file dir.c.

References assertconst.

00149 {
00150     assertconst(path,1);
00151 #ifdef WIN32
00152     RemoveDirectory(path);
00153 #else
00154     rmdir(path);
00155 #endif
00156 }

void ctl_unlink ( const char *  path  ) 

Remove a file.

Parameters:
path Path to destroy

Definition at line 133 of file dir.c.

References assertconst.

00134 {
00135     assertconst(path,1);
00136 #ifdef WIN32
00137     DeleteFile( path );
00138 #else
00139     unlink( path );
00140 #endif
00141 }

ppCPP (  ) 

TODO: Make tchar templates of these

Referenced by ppCPP().


Generated on Fri Jan 2 15:28:35 2009 for Squat by  doxygen 1.5.6