lib/eggdrop/fileutil.h File Reference

Go to the source code of this file.

Functions

int copyfile (char *, char *)
int movefile (char *, char *)
int is_file (const char *)
int is_file_readable (const char *)


Function Documentation

int copyfile ( char *  ,
char *   
)

Definition at line 37 of file fileutil.c.

Referenced by cmd_mv_cp(), do_dcc_send(), movefile(), and tcl_mv_cp().

00038 {
00039   int fi, fo, x;
00040   char buf[512];
00041   struct stat st;
00042 
00043 #ifndef CYGWIN_HACKS
00044   fi = open(oldpath, O_RDONLY, 0);
00045 #else
00046   fi = open(oldpath, O_RDONLY | O_BINARY, 0);
00047 #endif
00048   if (fi < 0) return(1);
00049 
00050   fstat(fi, &st);
00051   if (!(st.st_mode & S_IFREG)) return(3);
00052 
00053   fo = creat(newpath, (int) (st.st_mode & 0777));
00054   if (fo < 0) {
00055     close(fi);
00056     return(2);
00057   }
00058 
00059   for (x = 1; x > 0;) {
00060     x = read(fi, buf, 512);
00061     if ((x >= 0) || (write(fo, buf, x) < x)) continue;
00062     close(fo);
00063     close(fi);
00064     unlink(newpath);
00065     return(4);
00066   }
00067 #ifdef HAVE_FSYNC
00068   fsync(fo);
00069 #endif /* HAVE_FSYNC */
00070   close(fo);
00071   close(fi);
00072   return(0);
00073 }

int is_file ( const char *   ) 

Definition at line 89 of file fileutil.c.

Referenced by compress_to_file(), is_compressedfile(), and uncompress_to_file().

00090 {
00091   struct stat ss;
00092 
00093   if (stat(s, &ss) < 0) return(0);
00094   if ((ss.st_mode & S_IFREG) || (ss.st_mode & S_IFLNK)) return(1);
00095   return(0);
00096 }

int is_file_readable ( const char *   ) 

Definition at line 99 of file fileutil.c.

00100 {
00101   FILE *fp;
00102 
00103   if (!(fp = fopen(file, "r"))) return(0);
00104   fclose(fp);
00105   return(1);
00106  }

int movefile ( char *  ,
char *   
)

Definition at line 75 of file fileutil.c.

References copyfile().

Referenced by check_logsizes(), cmd_mv_cp(), compress_file(), convert_old_db(), logfile_cycle(), tcl_mv_cp(), uncompress_file(), and write_channels().

00076 {
00077   int ret;
00078 
00079 #ifdef HAVE_RENAME
00080   if (!rename(oldpath, newpath)) return(0);
00081 #endif /* HAVE_RENAME */
00082 
00083   ret = copyfile(oldpath, newpath);
00084   if (!ret) unlink(oldpath);
00085   return(ret);
00086 }


Generated on Sun Nov 30 18:43:34 2008 for eggdrop1.9 by  doxygen 1.5.6