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

Diff for /src/usr.bin/cvs/entries.c between version 1.2 and 1.3

version 1.2, 2004/07/14 04:32:42 version 1.3, 2004/07/14 05:16:04
Line 41 
Line 41 
 #define CVS_ENTRIES_DELIM   '/'  #define CVS_ENTRIES_DELIM   '/'
   
   
   
   static struct cvs_ent*  cvs_ent_clone (const struct cvs_ent *);
   
   
   
 /*  /*
  * cvs_ent_open()   * cvs_ent_open()
  *   *
Line 53 
Line 58 
 cvs_ent_open(const char *dir, int flags)  cvs_ent_open(const char *dir, int flags)
 {  {
         size_t len;          size_t len;
         char entpath[MAXPATHLEN], ebuf[128];          char entpath[MAXPATHLEN], ebuf[128], mode[4];
         FILE *fp;          FILE *fp;
         struct cvs_ent *ent;          struct cvs_ent *ent;
         CVSENTRIES *ep;          CVSENTRIES *ep;
   
           memset(mode, 0, sizeof(mode));
           if (flags & O_RDONLY)
                   mode[0] = 'r';
           else if (flags & O_WRONLY)
                   mode[0] = 'w';
           else if (flags & O_RDWR) {
                   mode[0] = 'r';
                   mode[1] = '+';
           }
   
         snprintf(entpath, sizeof(entpath), "%s/" CVS_PATH_ENTRIES, dir);          snprintf(entpath, sizeof(entpath), "%s/" CVS_PATH_ENTRIES, dir);
         fp = fopen(entpath, "r");          fp = fopen(entpath, mode);
         if (fp == NULL) {          if (fp == NULL) {
                 cvs_log(LP_ERRNO, "cannot open CVS/Entries for reading",                  cvs_log(LP_ERRNO, "cannot open CVS/Entries for reading",
                     entpath);                      entpath);
Line 84 
Line 99 
         ep->cef_entries = NULL;          ep->cef_entries = NULL;
         ep->cef_nbent = 0;          ep->cef_nbent = 0;
   
           /* only keep a pointer to the open file if we're in writing mode */
           if ((flags & O_WRONLY) || (flags & O_RDWR))
                   ep->cef_file = fp;
   
         while (fgets(ebuf, sizeof(ebuf), fp) != NULL) {          while (fgets(ebuf, sizeof(ebuf), fp) != NULL) {
                 len = strlen(ebuf);                  len = strlen(ebuf);
                 if ((len > 0) && (ebuf[len - 1] == '\n'))                  if ((len > 0) && (ebuf[len - 1] == '\n'))
Line 120 
Line 139 
 /*  /*
  * cvs_ent_add()   * cvs_ent_add()
  *   *
  * Add the entry <ent>   * Add the entry <ent> to the Entries file <ef>.
  */   */
   
 int  int
 cvs_ent_add(CVSENTRIES *ef, struct cvs_ent *ent)  cvs_ent_add(CVSENTRIES *ef, struct cvs_ent *ent)
 {  {
         void *tmp;          void *tmp;
         struct cvs_ent *entp;  
   
           if (ef->cef_file == NULL) {
                   cvs_log(LP_ERR, "Entries file is opened in read-only mode");
                   return (-1);
           }
   
         if (cvs_ent_get(ef, ent->ce_name) != NULL)          if (cvs_ent_get(ef, ent->ce_name) != NULL)
                 return (-1);                  return (-1);
   
         entp = cvs_ent_parse(ent->ce_line);          if (fseek(ef->cef_file, (long)0, SEEK_END) == -1) {
         if (entp == NULL) {                  cvs_log(LP_ERRNO, "failed to seek to end of CVS/Entries file");
                 return (-1);                  return (-1);
         }          }
           fprintf(ef->cef_file, "%s\n", ent->ce_line);
   
         tmp = realloc(ef->cef_entries, (ef->cef_nbent + 1) * sizeof(entp));          tmp = realloc(ef->cef_entries, (ef->cef_nbent + 1) * sizeof(ent));
         if (tmp == NULL) {          if (tmp == NULL) {
                 cvs_log(LP_ERRNO, "failed to resize entries buffer");                  cvs_log(LP_ERRNO, "failed to resize entries buffer");
                 return (-1);                  return (-1);
         }          }
   
         ef->cef_entries = (struct cvs_ent **)tmp;          ef->cef_entries = (struct cvs_ent **)tmp;
         ef->cef_entries[ef->cef_nbent++] = entp;          ef->cef_entries[ef->cef_nbent++] = ent;
   
           return (0);
   }
   
   
   /*
    * cvs_ent_addln()
    *
    * Add a line to the Entries file.
    */
   
   int
   cvs_ent_addln(CVSENTRIES *ef, const char *line)
   {
           void *tmp;
           struct cvs_ent *ent;
   
           if (ef->cef_file == NULL) {
                   cvs_log(LP_ERR, "Entries file is opened in read-only mode");
                   return (-1);
           }
   
           ent = cvs_ent_parse(line);
           if (ent == NULL)
                   return (-1);
   
           if (cvs_ent_get(ef, ent->ce_name) != NULL)
                   return (-1);
   
           tmp = realloc(ef->cef_entries, (ef->cef_nbent + 1) * sizeof(ent));
           if (tmp == NULL) {
                   cvs_log(LP_ERRNO, "failed to resize entries buffer");
                   return (-1);
           }
   
           ef->cef_entries = (struct cvs_ent **)tmp;
           ef->cef_entries[ef->cef_nbent++] = ent;
   
         return (0);          return (0);
 }  }

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3