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

Diff for /src/usr.bin/cvs/Attic/proto.c between version 1.51 and 1.52

version 1.51, 2005/05/12 23:01:35 version 1.52, 2005/05/23 20:13:39
Line 50 
Line 50 
 #include <stdlib.h>  #include <stdlib.h>
 #include <unistd.h>  #include <unistd.h>
 #include <string.h>  #include <string.h>
   #include <pwd.h>
   
 #include "buf.h"  #include "buf.h"
 #include "cvs.h"  #include "cvs.h"
Line 1059 
Line 1060 
 static int  static int
 cvs_initlog(void)  cvs_initlog(void)
 {  {
         char *env, fpath[MAXPATHLEN];          int l;
           u_int i;
           char *env, *envdup, buf[MAXPATHLEN], fpath[MAXPATHLEN];
           char rpath[MAXPATHLEN], *s;
           struct stat st;
           time_t now;
           struct passwd *pwd;
   
         /* avoid doing it more than once */          /* avoid doing it more than once */
         if (cvs_server_logon)          if (cvs_server_logon)
Line 1069 
Line 1076 
         if (env == NULL)          if (env == NULL)
                 return (0);                  return (0);
   
         strlcpy(fpath, env, sizeof(fpath));          if ((envdup = strdup(env)) == NULL)
         strlcat(fpath, ".in", sizeof(fpath));                  return (-1);
   
           if ((s = strchr(envdup, '%')) != NULL)
                   *s = '\0';
   
           strlcpy(buf, env, sizeof(buf));
           strlcpy(rpath, envdup, sizeof(rpath));
   
           s = buf;
           while ((s = strchr(s, '%')) != NULL) {
                   *s++;
                   switch (*s) {
                   case 'c':
                           strlcpy(fpath, cvs_command, sizeof(fpath));
                           break;
                   case 'd':
                           time(&now);
                           snprintf(fpath, sizeof(fpath), "%s", ctime(&now));
                           break;
                   case 'p':
                           snprintf(fpath, sizeof(fpath), "%d", getpid());
                           break;
                   case 'u':
                           if ((pwd = getpwuid(getuid())) != NULL)
                                   strlcpy(fpath, pwd->pw_name, sizeof(fpath));
                           else
                                   fpath[0] = '\0';
                           endpwent();
                           break;
                   default:
                           fpath[0] = '\0';
                           break;
                   }
   
                   if (fpath[0] != '\0') {
                           strlcat(rpath, "-", sizeof(rpath));
                           strlcat(rpath, fpath, sizeof(rpath));
                   }
           }
   
           for (i = 0; i < UINT_MAX; i++) {
                   l = snprintf(fpath, sizeof(fpath), "%s-%d.in", rpath, i);
                   if (l == -1 || l >= (int)sizeof(fpath)) {
                           errno = ENAMETOOLONG;
                           cvs_log(LP_ERRNO, "%s", fpath);
                           return (-1);
                   }
   
                   if (stat(fpath, &st) != -1)
                           continue;
   
                   if (errno != ENOENT)
                           return (-1);
   
                   break;
           }
   
         cvs_server_inlog = fopen(fpath, "w");          cvs_server_inlog = fopen(fpath, "w");
         if (cvs_server_inlog == NULL) {          if (cvs_server_inlog == NULL) {
                 cvs_log(LP_ERRNO, "failed to open server input log `%s'",                  cvs_log(LP_ERRNO, "failed to open server input log `%s'",
Line 1078 
Line 1141 
                 return (-1);                  return (-1);
         }          }
   
         strlcpy(fpath, env, sizeof(fpath));          for (i = 0; i < UINT_MAX; i++) {
         strlcat(fpath, ".out", sizeof(fpath));                  l = snprintf(fpath, sizeof(fpath), "%s-%d.out", rpath, i);
                   if (l == -1 || l >= (int)sizeof(fpath)) {
                           errno = ENAMETOOLONG;
                           cvs_log(LP_ERRNO, "%s", fpath);
                           return (-1);
                   }
   
                   if (stat(fpath, &st) != -1)
                           continue;
   
                   if (errno != ENOENT)
                           return (-1);
   
                   break;
           }
   
         cvs_server_outlog = fopen(fpath, "w");          cvs_server_outlog = fopen(fpath, "w");
         if (cvs_server_outlog == NULL) {          if (cvs_server_outlog == NULL) {
                 cvs_log(LP_ERRNO, "failed to open server output log `%s'",                  cvs_log(LP_ERRNO, "failed to open server output log `%s'",

Legend:
Removed from v.1.51  
changed lines
  Added in v.1.52