In copy_file, use a palloc'd buffer instead of just a local char array;
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 2 Sep 2005 18:55:32 +0000 (18:55 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 2 Sep 2005 18:55:32 +0000 (18:55 +0000)
a local array isn't guaranteed to have any particular alignment, and
so it could slow down the data transfer.

src/port/copydir.c

index 0392f0d43e8437cfc1815ee78bb5586bfaf64d61..cc54be216b1af6209132771875103ee95fff3e80 100644 (file)
@@ -88,11 +88,16 @@ copydir(char *fromdir, char *todir, bool recurse)
 static void
 copy_file(char *fromfile, char *tofile)
 {
-       char            buffer[8 * BLCKSZ];
+       char       *buffer;
        int                     srcfd;
        int                     dstfd;
        int                     nbytes;
 
+       /* Use palloc to ensure we get a maxaligned buffer */
+#define COPY_BUF_SIZE (8 * BLCKSZ)
+
+       buffer = palloc(COPY_BUF_SIZE);
+
        /*
         * Open the files
         */
@@ -114,7 +119,7 @@ copy_file(char *fromfile, char *tofile)
         */
        for (;;)
        {
-               nbytes = read(srcfd, buffer, sizeof(buffer));
+               nbytes = read(srcfd, buffer, COPY_BUF_SIZE);
                if (nbytes < 0)
                        ereport(ERROR,
                                        (errcode_for_file_access(),
@@ -147,4 +152,6 @@ copy_file(char *fromfile, char *tofile)
                                 errmsg("could not close file \"%s\": %m", tofile)));
 
        close(srcfd);
+
+       pfree(buffer);
 }