[BACK]Return to util.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / patch

Diff for /src/usr.bin/patch/util.c between version 1.19 and 1.20

version 1.19, 2003/07/28 16:13:53 version 1.20, 2003/07/28 18:35:36
Line 14 
Line 14 
 #include <paths.h>  #include <paths.h>
 #include <stdarg.h>  #include <stdarg.h>
 #include <stdlib.h>  #include <stdlib.h>
   #include <stdio.h>
 #include <string.h>  #include <string.h>
 #include <unistd.h>  #include <unistd.h>
   
 #include "EXTERN.h"  
 #include "common.h"  #include "common.h"
 #include "INTERN.h"  
 #include "util.h"  #include "util.h"
 #include "backupfile.h"  #include "backupfile.h"
   
Line 27 
Line 26 
 /* Rename a file, copying it if necessary. */  /* Rename a file, copying it if necessary. */
   
 int  int
 move_file(char *from, char *to)  move_file(const char *from, const char *to)
 {  {
         int     i, fromfd;          int     fromfd;
           ssize_t i;
   
         /* to stdout? */          /* to stdout? */
   
Line 69 
Line 69 
 /* Backup the original file.  */  /* Backup the original file.  */
   
 int  int
 backup_file(char *orig)  backup_file(const char *orig)
 {  {
         char    bakname[MAXPATHLEN], *s, *simplename;          struct stat     filestat;
         dev_t   orig_device;          char            bakname[MAXPATHLEN], *s, *simplename;
         ino_t   orig_inode;          dev_t           orig_device;
           ino_t           orig_inode;
   
         if (backup_type == none || stat(orig, &filestat) != 0)          if (backup_type == none || stat(orig, &filestat) != 0)
                 return 0;                       /* nothing to do */                  return 0;                       /* nothing to do */
Line 128 
Line 129 
  * Copy a file.   * Copy a file.
  */   */
 int  int
 copy_file(char *from, char *to)  copy_file(const char *from, const char *to)
 {  {
         int     tofd, fromfd, i;          int     tofd, fromfd;
           ssize_t i;
   
         tofd = open(to, O_CREAT|O_TRUNC|O_WRONLY, 0666);          tofd = open(to, O_CREAT|O_TRUNC|O_WRONLY, 0666);
         if (tofd < 0)          if (tofd < 0)
Line 150 
Line 152 
  * Allocate a unique area for a string.   * Allocate a unique area for a string.
  */   */
 char *  char *
 savestr(char *s)  savestr(const char *s)
 {  {
         char    *rv, *t;          char    *rv;
   
         if (!s)          if (!s)
                 s = "Oops";                  s = "Oops";
         t = s;          rv = strdup(s);
         while (*t++)  
                 ;  
         rv = malloc((size_t) (t - s));  
         if (rv == NULL) {          if (rv == NULL) {
                 if (using_plan_a)                  if (using_plan_a)
                         out_of_mem = TRUE;                          out_of_mem = TRUE;
                 else                  else
                         fatal("out of memory\n");                          fatal("out of memory\n");
         } else {  
                 t = rv;  
                 while ((*t++ = *s++))  
                         ;  
         }          }
         return rv;          return rv;
 }  }
Line 177 
Line 172 
  * Vanilla terminal output (buffered).   * Vanilla terminal output (buffered).
  */   */
 void  void
 say(char *fmt, ...)  say(const char *fmt, ...)
 {  {
         va_list ap;          va_list ap;
   
Line 191 
Line 186 
  * Terminal output, pun intended.   * Terminal output, pun intended.
  */   */
 void  void
 fatal(char *fmt, ...)  fatal(const char *fmt, ...)
 {  {
         va_list ap;          va_list ap;
   
Line 206 
Line 201 
  * Say something from patch, something from the system, then silence . . .   * Say something from patch, something from the system, then silence . . .
  */   */
 void  void
 pfatal(char *fmt, ...)  pfatal(const char *fmt, ...)
 {  {
         va_list ap;          va_list ap;
         int     errnum = errno;          int     errnum = errno;
Line 223 
Line 218 
  * Get a response from the user, somehow or other.   * Get a response from the user, somehow or other.
  */   */
 void  void
 ask(char *fmt, ...)  ask(const char *fmt, ...)
 {  {
         va_list ap;          va_list ap;
         int     ttyfd, r;          int     ttyfd;
           ssize_t r;
         bool    tty2 = isatty(2);          bool    tty2 = isatty(2);
   
         va_start(ap, fmt);          va_start(ap, fmt);
Line 298 
Line 294 
  */   */
   
 void  void
 makedirs(char *filename, bool striplast)  makedirs(const char *filename, bool striplast)
 {  {
         char    *tmpbuf;          char    *tmpbuf;
   
Line 323 
Line 319 
  * Make filenames more reasonable.   * Make filenames more reasonable.
  */   */
 char *  char *
 fetchname(char *at, int strip_leading, int assume_exists)  fetchname(const char *at, int strip_leading, int assume_exists)
 {  {
         char    *fullname, *name, *t, tmpbuf[200];          char            *fullname, *name, *t, tmpbuf[200];
         int     sleading = strip_leading;          int             sleading = strip_leading;
           struct stat     filestat;
   
         if (!at || *at == '\0')          if (at == NULL || *at == '\0')
                 return NULL;                  return NULL;
         while (isspace(*at))          while (isspace(*at))
                 at++;                  at++;

Legend:
Removed from v.1.19  
changed lines
  Added in v.1.20