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

Diff for /src/usr.bin/cvs/util.c between version 1.29 and 1.30

version 1.29, 2005/05/26 22:25:31 version 1.30, 2005/05/27 17:04:59
Line 139 
Line 139 
         char buf[32], ms[4], *sp, *ep;          char buf[32], ms[4], *sp, *ep;
   
         m = 0;          m = 0;
         strlcpy(buf, str, sizeof(buf));          if (strlcpy(buf, str, sizeof(buf)) >= sizeof(buf)) {
                   return (-1);
           }
         sp = buf;          sp = buf;
         ep = sp;          ep = sp;
   
Line 185 
Line 187 
 /*  /*
  * cvs_modetostr()   * cvs_modetostr()
  *   *
    * Generate a CVS-format string to represent the permissions mask on a file
    * from the mode <mode> and store the result in <buf>, which can accept up to
    * <len> bytes (including the terminating NUL byte).  The result is guaranteed
    * to be NUL-terminated.
  * Returns 0 on success, or -1 on failure.   * Returns 0 on success, or -1 on failure.
  */   */
 int  int
Line 222 
Line 228 
         return (0);          return (0);
 }  }
   
   
 /*  /*
  * cvs_cksum()   * cvs_cksum()
  *   *
Line 246 
Line 251 
         return (0);          return (0);
 }  }
   
   
 /*  /*
  * cvs_splitpath()   * cvs_splitpath()
  *   *
Line 368 
Line 372 
  * Allocate an argument vector large enough to accommodate for all the   * Allocate an argument vector large enough to accommodate for all the
  * arguments found in <line> and return it.   * arguments found in <line> and return it.
  */   */
   
 char**  char**
 cvs_makeargv(const char *line, int *argc)  cvs_makeargv(const char *line, int *argc)
 {  {
Line 511 
Line 514 
 }  }
   
 /*  /*
  * remove a directory tree from disk.   * cvs_remove_dir()
    *
    * Remove a directory tree from disk.
    * Returns 0 on success, or -1 on failure.
  */   */
 int  int
 cvs_remove_dir(const char *path)  cvs_remove_dir(const char *path)
 {  {
         int l, ret;          size_t len;
         DIR *dirp;          DIR *dirp;
         struct dirent *ent;          struct dirent *ent;
         char fpath[MAXPATHLEN];          char fpath[MAXPATHLEN];
   
         if ((dirp = opendir(path)) == NULL) {          if ((dirp = opendir(path)) == NULL) {
                 cvs_log(LP_ERRNO, "failed to open '%s'", path);                  cvs_log(LP_ERRNO, "failed to open '%s'", path);
                 return (CVS_EX_FILE);                  return (-1);
         }          }
   
         while ((ent = readdir(dirp)) != NULL) {          while ((ent = readdir(dirp)) != NULL) {
Line 531 
Line 537 
                     !strcmp(ent->d_name, ".."))                      !strcmp(ent->d_name, ".."))
                         continue;                          continue;
   
                 l = snprintf(fpath, sizeof(fpath), "%s/%s", path, ent->d_name);                  len = cvs_path_cat(path, ent->d_name, fpath, sizeof(fpath));
                 if (l == -1 || l >= (int)sizeof(fpath)) {                  if (len >= sizeof(fpath)) {
                         errno = ENAMETOOLONG;                          errno = ENAMETOOLONG;
                         cvs_log(LP_ERRNO, "%s", fpath);                          cvs_log(LP_ERRNO, "%s", fpath);
                         closedir(dirp);                          closedir(dirp);
                         return (CVS_EX_FILE);                          return (-1);
                 }                  }
   
                 if (ent->d_type == DT_DIR) {                  if (ent->d_type == DT_DIR) {
                         if ((ret = cvs_remove_dir(fpath)) != CVS_EX_OK) {                          if (cvs_remove_dir(fpath) == -1) {
                                 closedir(dirp);                                  closedir(dirp);
                                 return (ret);                                  return (-1);
                         }                          }
                 } else {                  } else if ((unlink(fpath) == -1) && (errno != ENOENT)) {
                         if ((unlink(fpath) == -1) && (errno != ENOENT))                          cvs_log(LP_ERRNO, "failed to remove '%s'", fpath);
                                 cvs_log(LP_ERRNO, "failed to remove '%s'",                          return (-1);
                                     fpath);  
                 }                  }
         }          }
   
         closedir(dirp);          closedir(dirp);
   
         if ((rmdir(path) == -1) && (errno != ENOENT))          if ((rmdir(path) == -1) && (errno != ENOENT)) {
                 cvs_log(LP_ERRNO, "failed to remove '%s'", path);                  cvs_log(LP_ERRNO, "failed to remove '%s'", path);
                   return (-1);
           }
   
         return (CVS_EX_OK);          return (0);
 }  }
   
   /*
    * cvs_path_cat()
    *
    * Concatenate the two paths <base> and <end> and store the generated path
    * into the buffer <dst>, which can accept up to <dlen> bytes, including the
    * NUL byte.  The result is guaranteed to be NUL-terminated.
    * Returns the number of bytes necessary to store the full resulting path,
    * not including the NUL byte (a value equal to or larger than <dlen>
    * indicates truncation).
    */
 size_t  size_t
 cvs_path_cat(const char *base, const char *end, char *dst, size_t dlen)  cvs_path_cat(const char *base, const char *end, char *dst, size_t dlen)
 {  {

Legend:
Removed from v.1.29  
changed lines
  Added in v.1.30