src/mime.c
changeset 63 f5b2641f4ae7
parent 62 ad5e484720e1
child 70 c0382670c294
     1.1 --- a/src/mime.c	Sat Feb 21 16:55:43 2015 +0100
     1.2 +++ b/src/mime.c	Sun Feb 22 13:40:25 2015 +0100
     1.3 @@ -8,6 +8,7 @@
     1.4  #include <unistd.h>
     1.5  
     1.6  #include "etpan_mime.h"
     1.7 +#include "wrappers.h"
     1.8  
     1.9  DYNAMIC_API PEP_STATUS mime_encode_text(
    1.10          const char *plaintext,
    1.11 @@ -127,10 +128,7 @@
    1.12      if (template == NULL)
    1.13          goto enomem;
    1.14  
    1.15 -    do {
    1.16 -        fd = mkstemp(template);
    1.17 -    } while (fd == -1 && errno == EINTR);
    1.18 -
    1.19 +    fd = Mkstemp(template);
    1.20      assert(fd != -1);
    1.21      if (fd == -1)
    1.22          goto err_file;
    1.23 @@ -143,10 +141,7 @@
    1.24      free(template);
    1.25      template = NULL;
    1.26  
    1.27 -    do {
    1.28 -        file = fdopen(fd, "w+");
    1.29 -    } while (file == NULL && errno == EINTR);
    1.30 -
    1.31 +    file = Fdopen(fd, "w+");
    1.32      assert(file);
    1.33      if (file == NULL) {
    1.34          switch (errno) {
    1.35 @@ -179,38 +174,28 @@
    1.36  
    1.37      errno = 0;
    1.38      rewind(file);
    1.39 -
    1.40      assert(errno == 0);
    1.41 +#ifdef NDEBUG
    1.42      switch (errno) {
    1.43 +        case 0:
    1.44 +            break;
    1.45          case ENOMEM:
    1.46              goto enomem;
    1.47          default:
    1.48              goto err_file;
    1.49      }
    1.50 +#endif
    1.51  
    1.52      buf = calloc(1, size + 1);
    1.53      assert(buf);
    1.54      if (buf == NULL)
    1.55          goto enomem;
    1.56 -    
    1.57 -    char *_buf = buf;
    1.58 -    size_t rest = size;
    1.59 -    for (size_t bytes_read = 0; rest > 0; rest -= bytes_read, _buf += rest) {
    1.60 -        clearerr(file);
    1.61 -        bytes_read = rest * fread(_buf, rest, 1, file);
    1.62 + 
    1.63 +    size_t _read;
    1.64 +    _read = Fread1(buf, size, file);
    1.65 +    assert(_read == size);
    1.66  
    1.67 -        assert(ferror(file) == 0 || ferror(file) == EINTR);
    1.68 -        if (ferror(file) != 0 && ferror(file) != EINTR)
    1.69 -            goto err_file;
    1.70 -
    1.71 -        assert(!feof(file));
    1.72 -        if (feof(file))
    1.73 -            goto err_file;
    1.74 -    }
    1.75 -
    1.76 -    do {
    1.77 -        r = fclose(file);
    1.78 -    } while (r == -1 && errno == EINTR);
    1.79 +    r = Fclose(file);
    1.80      assert(r == 0);
    1.81  
    1.82      mailmime_free(mime);
    1.83 @@ -233,15 +218,11 @@
    1.84      free(template);
    1.85  
    1.86      if (file) {
    1.87 -        do {
    1.88 -            r = fclose(file);
    1.89 -        } while (r == -1 && errno == EINTR);
    1.90 +        r = Fclose(file);
    1.91          assert(r == 0);
    1.92      }
    1.93      else if (fd != -1) {
    1.94 -        do {
    1.95 -            r = close(fd);
    1.96 -        } while (r == -1 && errno == EINTR);
    1.97 +        r = Close(fd);
    1.98          assert(r == 0);
    1.99      }
   1.100