Changeset 5373:7f4711b9b61f for alias.c

Show
Ignore:
Timestamp:
2008-05-14 16:23:52 (6 months ago)
Author:
Brendan Cully <brendan@…>
Branch:
HEAD
Message:

Ensure alias file ends with \n before appending new aliases.
Closes #1580.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • alias.c

    r5019 r5373  
    332332    return; 
    333333  mutt_expand_path (buf, sizeof (buf)); 
    334   if ((rc = fopen (buf, "a"))) 
    335   { 
     334  if ((rc = fopen (buf, "a+"))) 
     335  { 
     336    /* terminate existing file with \n if necessary */ 
     337    if (fseek (rc, 0, SEEK_END)) 
     338      goto fseek_err; 
     339    if (ftell(rc) > 0) 
     340    { 
     341      if (fseek (rc, -1, SEEK_CUR) < 0) 
     342        goto fseek_err; 
     343      if (fread(buf, 1, 1, rc) < 0) 
     344      { 
     345        mutt_perror (_("Error reading alias file")); 
     346        return; 
     347      } 
     348      if (fseek (rc, 0, SEEK_END) < 0) 
     349        goto fseek_err; 
     350      if (buf[0] != '\n') 
     351        fputc ('\n', rc); 
     352    } 
     353 
    336354    if (mutt_check_alias_name (new->name, NULL)) 
    337355      mutt_quote_filename (buf, sizeof (buf), new->name); 
     
    348366  else 
    349367    mutt_perror (buf); 
     368 
     369  return; 
     370   
     371  fseek_err: 
     372  mutt_perror (_("Error seeking in alias file")); 
     373  fclose(rc); 
     374  return; 
    350375} 
    351376