Back to index

lightning-sunbird  0.9+nobinonly
Functions
nsFileSpecBeOS.cpp File Reference
#include <sys/stat.h>
#include <sys/param.h>
#include <errno.h>
#include <dirent.h>
#include <unistd.h>
#include <stdlib.h>
#include <limits.h>
#include "nsError.h"
#include "prio.h"
#include <Entry.h>
#include <Path.h>
#include <Volume.h>

Go to the source code of this file.

Functions

static int CrudeFileCopy (const char *in, const char *out)

Function Documentation

static int CrudeFileCopy ( const char *  in,
const char *  out 
) [static]

Definition at line 345 of file nsFileSpecBeOS.cpp.

{
       struct stat in_stat;
       int stat_result = -1;

       char   buf [1024];
       FILE   *ifp, *ofp;
       int    rbytes, wbytes;

       if (!in || !out)
              return -1;

       stat_result = stat (in, &in_stat);

       ifp = fopen (in, "r");
       if (!ifp) 
       {
              return -1;
       }

       ofp = fopen (out, "w");
       if (!ofp)
       {
              fclose (ifp);
              return -1;
       }

       while ((rbytes = fread (buf, 1, sizeof(buf), ifp)) > 0)
       {
              while (rbytes > 0)
              {
                     if ( (wbytes = fwrite (buf, 1, rbytes, ofp)) < 0 )
                     {
                            fclose (ofp);
                            fclose (ifp);
                            unlink(out);
                            return -1;
                     }
                     rbytes -= wbytes;
              }
       }
       fclose (ofp);
       fclose (ifp);

       if (stat_result == 0)
              chmod (out, in_stat.st_mode & 0777);

       return 0;
} // nsFileSpec::Rename

Here is the call graph for this function: