X-Git-Url: http://git.marmaro.de/?a=blobdiff_plain;f=uip%2Fannosbr.c;h=7f1bdde70977daf06a3a84df3395d6d7a7372b18;hb=2f689a1cb907a5de04e6d39ffd217a69af3216c7;hp=337a01bc76144f566c3de54a87921251927f1540;hpb=81a21a9a97d8633f6d6231e31fdb6e328d0d3ff2;p=mmh diff --git a/uip/annosbr.c b/uip/annosbr.c index 337a01b..7f1bdde 100644 --- a/uip/annosbr.c +++ b/uip/annosbr.c @@ -120,8 +120,7 @@ annolist(char *file, char *comp, char *text, int number) } if (++n >= field_size - 1) { - if ((field = (char *)realloc((void *)field, field_size += 256)) == (char *)0) - adios(NULL, "can't grow field buffer."); + field = (char *) mh_xrealloc((void *)field, field_size += 256); cp = field + n - 1; } @@ -180,20 +179,15 @@ annosbr (int fd, char *file, char *comp, char *text, int inplace, int datesw, in FILE *tmp; int c; /* current character */ int count; /* header field (annotation) counter */ - char *field; /* buffer for header field */ - int field_size; /* size of field buffer */ - FILE *fp; /* file pointer made from locked file descriptor */ + char *field = NULL; /* buffer for header field */ + int field_size = 0; /* size of field buffer */ + FILE *fp = NULL; /* file pointer made from locked file descriptor */ int length; /* length of field name */ int n; /* number of bytes written */ mode = fstat (fd, &st) != NOTOK ? (st.st_mode & 0777) : m_gmprot (); - strncpy (tmpfil, m_scratch (file, "annotate"), sizeof(tmpfil)); - - if ((tmp = fopen (tmpfil, "w")) == NULL) { - admonish (tmpfil, "unable to create"); - return 1; - } + strncpy (tmpfil, m_mktemp2(file, "annotate", NULL, &tmp), sizeof(tmpfil)); chmod (tmpfil, mode); /* @@ -262,8 +256,7 @@ annosbr (int fd, char *file, char *comp, char *text, int inplace, int datesw, in } if (++n >= field_size - 1) { - if ((field = (char *)realloc((void *)field, field_size *= 2)) == (char *)0) - adios(NULL, "can't grow field buffer."); + field = (char *) mh_xrealloc((void *)field, field_size *= 2); cp = field + n - 1; } @@ -383,7 +376,7 @@ annosbr (int fd, char *file, char *comp, char *text, int inplace, int datesw, in while (*cp && *cp++ != '\n') continue; if (cp - sp) - fprintf (tmp, "%s: %*.*s", comp, cp - sp, cp - sp, sp); + fprintf (tmp, "%s: %*.*s", comp, (int)(cp - sp), (int)(cp - sp), sp); } while (*cp); if (cp[-1] != '\n' && cp != text) putc ('\n', tmp);