/[mailutils]/mailutils/mh/mh_init.c
ViewVC logotype

Diff of /mailutils/mh/mh_init.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.21 by gray, Thu Jan 16 13:45:11 2003 UTC revision 1.22 by gray, Sat Jan 18 21:58:47 2003 UTC
# Line 109  mh_read_formfile (char *name, char **pfo Line 109  mh_read_formfile (char *name, char **pfo
109    return 0;    return 0;
110  }  }
111    
112    void
113    mh_err_memory (int fatal)
114    {
115      mh_error (_("not enough memory"));
116      if (fatal)
117        abort ();
118    }
119    
120  static char *my_name;  static char *my_name;
121  static char *my_email;  static char *my_email;
122    
# Line 412  mh_spawnp (const char *prog, const char Line 420  mh_spawnp (const char *prog, const char
420    xargv = calloc (argc + 2, sizeof (*xargv));    xargv = calloc (argc + 2, sizeof (*xargv));
421    if (!xargv)    if (!xargv)
422      {      {
423        mh_error (_("not enough memory"));        mh_err_memory (0);
424        argcv_free (argc, argv);        argcv_free (argc, argv);
425        return 1;        return 1;
426      }      }
# Line 429  mh_spawnp (const char *prog, const char Line 437  mh_spawnp (const char *prog, const char
437    
438    return rc;    return rc;
439  }  }
440    
441    int
442    mh_file_copy (const char *from, const char *to)
443    {
444      char *buffer;
445      size_t bufsize, rdsize;
446      struct stat st;
447      stream_t in;
448      stream_t out;
449      int rc;
450      
451      if (stat (from, &st))
452        {
453          mh_error ("mh_copy: %s", mu_errstring (errno));
454          return -1;
455        }
456    
457      for (bufsize = st.st_size; bufsize > 0 && (buffer = malloc (bufsize)) == 0;
458           bufsize /= 2)
459        ;
460    
461      if (!bufsize)
462        mh_err_memory (1);
463    
464      if ((rc = file_stream_create (&in, from, MU_STREAM_READ)) != 0
465          || (rc = stream_open (in)))
466        {
467          mh_error (_("cannot open input file \"%s\": %s"),
468                    from, mu_errstring (rc));
469          free (buffer);
470          return 1;
471        }
472    
473      if ((rc = file_stream_create (&out, to, MU_STREAM_RDWR|MU_STREAM_CREAT)) != 0
474          || (rc = stream_open (out)))
475        {
476          mh_error (_("cannot open output file \"%s\": %s"),
477                    to, mu_errstring (rc));
478          free (buffer);
479          stream_close (in);
480          stream_destroy (&in, stream_get_owner (in));
481          return 1;
482        }
483    
484      while (st.st_size > 0
485             && (rc = stream_sequential_read (in, buffer, bufsize, &rdsize)) == 0
486             && rdsize > 0)
487        {
488          if ((rc = stream_sequential_write (out, buffer, rdsize)) != 0)
489            {
490              mh_error (_("write error on \"%s\": %s"),
491                        to, mu_errstring (rc));
492              break;
493            }
494          st.st_size -= rdsize;
495        }
496    
497      free (buffer);
498    
499      stream_close (in);
500      stream_close (out);
501      stream_destroy (&in, stream_get_owner (in));
502      stream_destroy (&out, stream_get_owner (out));
503      
504      return rc;
505    }

Legend:
Removed from v.1.21  
changed lines
  Added in v.1.22

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26