aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2005-09-02 18:55:32 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2005-09-02 18:55:32 +0000
commit962a4bb69f1dd70f1212e27ba2de7634cf91a80d (patch)
tree3a0c971ccaa2c8af8eccb6cce765a0c647a149b5
parentfad7e8edac3348ea14aca379e7b3b2d713746cd3 (diff)
downloadpostgresql-962a4bb69f1dd70f1212e27ba2de7634cf91a80d.tar.gz
postgresql-962a4bb69f1dd70f1212e27ba2de7634cf91a80d.zip
In copy_file, use a palloc'd buffer instead of just a local char array;
a local array isn't guaranteed to have any particular alignment, and so it could slow down the data transfer.
-rw-r--r--src/port/copydir.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/port/copydir.c b/src/port/copydir.c
index a9339e79f90..4820917cda4 100644
--- a/src/port/copydir.c
+++ b/src/port/copydir.c
@@ -11,7 +11,7 @@
* as a service.
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/port/copydir.c,v 1.12 2005/08/02 19:02:32 tgl Exp $
+ * $PostgreSQL: pgsql/src/port/copydir.c,v 1.13 2005/09/02 18:55:32 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -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);
}