~ubuntu-dev/ubuntu/lucid/mutt/lucid-201002110857

« back to all changes in this revision

Viewing changes to lib.c

  • Committer: Bazaar Package Importer
  • Author(s): أحمد المحمودي (Ahmed El-Mahmoudy)
  • Date: 2009-06-17 17:17:28 UTC
  • mfrom: (1.3.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: james.westby@ubuntu.com-20090617171728-61dkl7w5fgn7ybdq
Tags: upstream-1.5.20
Import upstream version 1.5.20

Show diffs side-by-side

added added

removed removed

Lines of Context:
220
220
    if (fflush (*f) || fsync (fileno (*f)))
221
221
    {
222
222
      r = -1;
223
 
      fclose (*f);
 
223
      safe_fclose (f);
224
224
    }
225
225
    else
226
 
      r = fclose(*f);
227
 
    *f = NULL;
 
226
      r = safe_fclose (f);
228
227
  }
229
228
 
230
229
  return r;
345
344
        fwrite (buf, 1, MIN (sizeof (buf), sb.st_size), f);
346
345
        sb.st_size -= MIN (sizeof (buf), sb.st_size);
347
346
      }
348
 
      fclose (f);
 
347
      safe_fclose (&f);
349
348
    }
350
349
  }
351
350
}
739
738
 * If a line ends with "\", this char and the linefeed is removed,
740
739
 * and the next line is read too.
741
740
 */
742
 
char *mutt_read_line (char *s, size_t *size, FILE *fp, int *line)
 
741
char *mutt_read_line (char *s, size_t *size, FILE *fp, int *line, int flags)
743
742
{
744
743
  size_t offset = 0;
745
744
  char *ch;
760
759
    if ((ch = strchr (s + offset, '\n')) != NULL)
761
760
    {
762
761
      (*line)++;
 
762
      if (flags & M_EOL)
 
763
        return s;
763
764
      *ch = 0;
764
765
      if (ch > s && *(ch - 1) == '\r')
765
766
        *--ch = 0;
766
 
      if (ch == s || *(ch - 1) != '\\')
 
767
      if (!(flags & M_CONT) || ch == s || *(ch - 1) != '\\')
767
768
        return s;
768
769
      offset = ch - s - 1;
769
770
    }
1005
1006
  
1006
1007
  return sysexits_h[i].str;
1007
1008
}
 
1009
 
 
1010
int mutt_atos (const char *str, short *dst)
 
1011
{
 
1012
  int rc;
 
1013
  long res;
 
1014
  short tmp;
 
1015
  short *t = dst ? dst : &tmp;
 
1016
 
 
1017
  *t = 0;
 
1018
 
 
1019
  if ((rc = mutt_atol (str, &res)) < 0)
 
1020
    return rc;
 
1021
  if ((short) res != res)
 
1022
    return -2;
 
1023
 
 
1024
  *t = (short) res;
 
1025
  return 0;
 
1026
}
 
1027
 
 
1028
int mutt_atoi (const char *str, int *dst)
 
1029
{
 
1030
  int rc;
 
1031
  long res;
 
1032
  int tmp;
 
1033
  int *t = dst ? dst : &tmp;
 
1034
 
 
1035
  *t = 0;
 
1036
 
 
1037
  if ((rc = mutt_atol (str, &res)) < 0)
 
1038
    return rc;
 
1039
  if ((int) res != res)
 
1040
    return -2;
 
1041
 
 
1042
  *t = (int) res;
 
1043
  return 0;
 
1044
}
 
1045
 
 
1046
int mutt_atol (const char *str, long *dst)
 
1047
{
 
1048
  long r;
 
1049
  long *res = dst ? dst : &r;
 
1050
  char *e = NULL;
 
1051
 
 
1052
  /* no input: 0 */
 
1053
  if (!str || !*str)
 
1054
  {
 
1055
    *res = 0;
 
1056
    return 0;
 
1057
  }
 
1058
 
 
1059
  *res = strtol (str, &e, 10);
 
1060
  if (e && *e != '\0')
 
1061
    return -1;
 
1062
  return 0;
 
1063
}