Comments for EXPORTed regression models
[pspp] / src / casefile.c
index 706a6b93916dc727e5e5711bdf579a730e69a852..a49db99d6fcfdedb3b79e16afe758f8699afc824 100644 (file)
 #include "alloc.h"
 #include "case.h"
 #include "error.h"
+#include "full-read.h"
+#include "full-write.h"
 #include "misc.h"
 #include "mkfile.h"
 #include "settings.h"
 #include "var.h"
 
+#include "gettext.h"
+#define _(msgid) gettext (msgid)
+
 #define IO_BUF_SIZE (8192 / sizeof (union value))
 
 /* A casefile represents a sequentially accessible stream of
@@ -173,8 +178,6 @@ static void fill_buffer (struct casereader *reader);
 
 static int safe_open (const char *filename, int flags);
 static int safe_close (int fd);
-static int full_read (int fd, void *buffer, size_t size);
-static int full_write (int fd, const void *buffer, size_t size);
 
 /* Creates and returns a casefile to store cases of VALUE_CNT
    `union value's each. */
@@ -328,7 +331,7 @@ casefile_append (struct casefile *cf, const struct ccase *c)
   /* Try memory first. */
   if (cf->storage == MEMORY) 
     {
-      if (case_bytes < get_max_workspace ())
+      if (case_bytes < get_workspace ())
         {
           size_t block_idx = cf->case_cnt / CASES_PER_BLOCK;
           size_t case_idx = cf->case_cnt % CASES_PER_BLOCK;
@@ -341,12 +344,12 @@ casefile_append (struct casefile *cf, const struct ccase *c)
               if ((block_idx & (block_idx - 1)) == 0) 
                 {
                   size_t block_cap = block_idx == 0 ? 1 : block_idx * 2;
-                  cf->cases = xrealloc (cf->cases,
-                                        sizeof *cf->cases * block_cap);
+                  cf->cases = xnrealloc (cf->cases,
+                                         block_cap, sizeof *cf->cases);
                 }
 
-              cf->cases[block_idx] = xmalloc (sizeof **cf->cases
-                                              * CASES_PER_BLOCK);
+              cf->cases[block_idx] = xnmalloc (CASES_PER_BLOCK,
+                                               sizeof **cf->cases);
             }
 
           case_move (&cf->cases[block_idx][case_idx], &new_case);
@@ -421,7 +424,7 @@ casefile_to_disk (const struct casefile *cf_)
       cf->storage = DISK;
       if (!make_temp_file (&cf->fd, &cf->filename))
         err_failure ();
-      cf->buffer = xmalloc (cf->buffer_size * sizeof *cf->buffer);
+      cf->buffer = xnmalloc (cf->buffer_size, sizeof *cf->buffer);
       memset (cf->buffer, 0, cf->buffer_size * sizeof *cf->buffer);
 
       case_bytes -= cf->case_cnt * cf->case_acct_size;
@@ -546,7 +549,7 @@ reader_open_file (struct casereader *reader)
     }
   else 
     {
-      reader->buffer = xmalloc (cf->buffer_size * sizeof *cf->buffer);
+      reader->buffer = xnmalloc (cf->buffer_size, sizeof *cf->buffer);
       memset (reader->buffer, 0, cf->buffer_size * sizeof *cf->buffer); 
     }
 
@@ -727,49 +730,6 @@ static int safe_close (int fd)
   return retval;
 }
 
-/* Calls read(), passing FD, BUFFER, and SIZE, repeating as
-   necessary to deal with interrupted calls. */
-static int
-full_read (int fd, void *buffer_, size_t size) 
-{
-  char *buffer = buffer_;
-  size_t bytes_read = 0;
-  
-  while (bytes_read < size)
-    {
-      int retval = read (fd, buffer + bytes_read, size - bytes_read);
-      if (retval > 0) 
-        bytes_read += retval; 
-      else if (retval == 0) 
-        return bytes_read;
-      else if (errno != EINTR)
-        return -1;
-    }
-
-  return bytes_read;
-}
-
-/* Calls write(), passing FD, BUFFER, and SIZE, repeating as
-   necessary to deal with interrupted calls. */
-static int
-full_write (int fd, const void *buffer_, size_t size) 
-{
-  const char *buffer = buffer_;
-  size_t bytes_written = 0;
-  
-  while (bytes_written < size)
-    {
-      int retval = write (fd, buffer + bytes_written, size - bytes_written);
-      if (retval >= 0) 
-        bytes_written += retval; 
-      else if (errno != EINTR)
-        return -1;
-    }
-
-  return bytes_written;
-}
-
-
 /* Registers our exit handler with atexit() if it has not already
    been registered. */
 static void