Ejemplo n.º 1
0
Archivo: task_copy.C Proyecto: gnb/cant
/* TODO: preserve mod times */
static gboolean
do_copy_file(const char *fromfile, const char *tofile)
{
    FILE *fromfp, *tofp;
    mode_t mode;
    string_var todir;
    int n;
    char buf[1024];
    
    todir = file_dirname(fromfile);
    if ((mode = file_mode(todir)) < 0)
    	mode = 0755;
    
    todir = file_dirname(tofile);
    if (file_build_tree(todir, mode) < 0)
	return FALSE;
    
    if ((fromfp = fopen(fromfile, "r")) == 0)
    {
    	log::perror(fromfile);
	return FALSE;
    }

    if ((mode = file_mode(fromfile)) == 0)
    	mode = 0644;	    /* should never happen */
    if ((tofp = file_open_mode(tofile, "w", mode)) == 0)
    {
    	log::perror(tofile);
	fclose(fromfp);
	return FALSE;
    }
    
    while ((n = fread(buf, 1, sizeof(buf), fromfp)) > 0)
    	fwrite(buf, 1, n, tofp);
	
    fclose(fromfp);
    fclose(tofp);
    
    return TRUE;
}
Ejemplo n.º 2
0
Archivo: helpers.c Proyecto: csm/arrow
int
file_mkdirs (const char *path, int mode)
{
  char dir[1024];
  char *p;

  if (file_isdir (path))
	return 0;
  if (file_isfile (path))
	{
	  errno = EEXIST;
	  return -1;
	}
  file_dirname (path, dir, sizeof (dir));
  if (strcmp (dir, ".") != 0)
	file_mkdirs (dir, mode);
  if (mkdir (path, mode) != 0)
	return -1;
  return 0;
}