Commit 022903f2 authored by Bruce Momjian's avatar Bruce Momjian

Reduce open() calls. Replace fopen() calls with calls to fd.c functions.

parent eaae21fb
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.24 1997/06/12 15:39:44 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.25 1997/08/18 02:14:34 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include <catalog/catname.h> #include <catalog/catname.h>
#include <catalog/pg_user.h> #include <catalog/pg_user.h>
#include <commands/copy.h> #include <commands/copy.h>
#include <storage/fd.h>
#define ISOCTAL(c) (((c) >= '0') && ((c) <= '7')) #define ISOCTAL(c) (((c) >= '0') && ((c) <= '7'))
#define VALUE(c) ((c) - '0') #define VALUE(c) ((c) - '0')
...@@ -127,7 +128,7 @@ DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe, ...@@ -127,7 +128,7 @@ DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe,
fp = Pfin; fp = Pfin;
} else fp = stdin; } else fp = stdin;
} else { } else {
fp = fopen(filename, "r"); fp = AllocateFile(filename, "r");
if (fp == NULL) if (fp == NULL)
elog(WARN, "COPY command, running in backend with " elog(WARN, "COPY command, running in backend with "
"effective uid %d, could not open file '%s' for " "effective uid %d, could not open file '%s' for "
...@@ -145,7 +146,7 @@ DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe, ...@@ -145,7 +146,7 @@ DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe,
} else { } else {
mode_t oumask; /* Pre-existing umask value */ mode_t oumask; /* Pre-existing umask value */
oumask = umask((mode_t) 0); oumask = umask((mode_t) 0);
fp = fopen(filename, "w"); fp = AllocateFile(filename, "w");
umask(oumask); umask(oumask);
if (fp == NULL) if (fp == NULL)
elog(WARN, "COPY command, running in backend with " elog(WARN, "COPY command, running in backend with "
...@@ -156,7 +157,8 @@ DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe, ...@@ -156,7 +157,8 @@ DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe,
} }
CopyTo(rel, binary, oids, fp, delim); CopyTo(rel, binary, oids, fp, delim);
} }
if (!pipe) fclose(fp); if (!pipe)
FreeFile(fp);
else if (!from && !binary) { else if (!from && !binary) {
fputs("\\.\n", fp); fputs("\\.\n", fp);
if (IsUnderPostmaster) fflush(Pfout); if (IsUnderPostmaster) fflush(Pfout);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/hba.c,v 1.17 1997/08/12 22:52:52 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/libpq/hba.c,v 1.18 1997/08/18 02:14:37 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
#include <libpq/pqcomm.h> #include <libpq/pqcomm.h>
#include <libpq/hba.h> #include <libpq/hba.h>
#include <port/inet_aton.h> /* For inet_aton() */ #include <port/inet_aton.h> /* For inet_aton() */
#include <storage/fd.h>
/* Some standard C libraries, including GNU, have an isblank() function. /* Some standard C libraries, including GNU, have an isblank() function.
Others, including Solaris, do not. So we have our own. Others, including Solaris, do not. So we have our own.
...@@ -334,8 +334,8 @@ find_hba_entry(const char DataDir[], const struct in_addr ip_addr, ...@@ -334,8 +334,8 @@ find_hba_entry(const char DataDir[], const struct in_addr ip_addr,
strlen(CONF_FILE)+2)*sizeof(char)); strlen(CONF_FILE)+2)*sizeof(char));
sprintf(conf_file, "%s/%s", DataDir, CONF_FILE); sprintf(conf_file, "%s/%s", DataDir, CONF_FILE);
file = fopen(conf_file, "r"); file = AllocateFile(conf_file, "r");
if (file == 0) { if (file == NULL) {
/* The open of the config file failed. */ /* The open of the config file failed. */
*host_ok_p = false; *host_ok_p = false;
...@@ -350,7 +350,7 @@ find_hba_entry(const char DataDir[], const struct in_addr ip_addr, ...@@ -350,7 +350,7 @@ find_hba_entry(const char DataDir[], const struct in_addr ip_addr,
} else { } else {
process_open_config_file(file, ip_addr, database, host_ok_p, userauth_p, process_open_config_file(file, ip_addr, database, host_ok_p, userauth_p,
usermap_name, find_password_entries); usermap_name, find_password_entries);
fclose(file); FreeFile(file);
} }
free(conf_file); free(conf_file);
} }
...@@ -636,8 +636,8 @@ verify_against_usermap(const char DataDir[], ...@@ -636,8 +636,8 @@ verify_against_usermap(const char DataDir[],
strlen(MAP_FILE)+2)*sizeof(char)); strlen(MAP_FILE)+2)*sizeof(char));
sprintf(map_file, "%s/%s", DataDir, MAP_FILE); sprintf(map_file, "%s/%s", DataDir, MAP_FILE);
file = fopen(map_file, "r"); file = AllocateFile(map_file, "r");
if (file == 0) { if (file == NULL) {
/* The open of the map file failed. */ /* The open of the map file failed. */
*checks_out_p = false; *checks_out_p = false;
...@@ -654,7 +654,7 @@ verify_against_usermap(const char DataDir[], ...@@ -654,7 +654,7 @@ verify_against_usermap(const char DataDir[],
verify_against_open_usermap(file, verify_against_open_usermap(file,
pguser, ident_username, usermap_name, pguser, ident_username, usermap_name,
checks_out_p); checks_out_p);
fclose(file); FreeFile(file);
} }
free(map_file); free(map_file);
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include <libpq/password.h> #include <libpq/password.h>
#include <libpq/hba.h> #include <libpq/hba.h>
#include <libpq/libpq.h> #include <libpq/libpq.h>
#include <storage/fd.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#ifdef HAVE_CRYPT_H #ifdef HAVE_CRYPT_H
...@@ -56,7 +57,7 @@ verify_password(char *user, char *password, Port *port, ...@@ -56,7 +57,7 @@ verify_password(char *user, char *password, Port *port,
strcat(pw_file_fullname, "/"); strcat(pw_file_fullname, "/");
strcat(pw_file_fullname, pw_file_name); strcat(pw_file_fullname, pw_file_name);
pw_file = fopen(pw_file_fullname, "r"); pw_file = AllocateFile(pw_file_fullname, "r");
if(!pw_file) { if(!pw_file) {
sprintf(PQerrormsg, sprintf(PQerrormsg,
"verify_password: couldn't open password file '%s'\n", "verify_password: couldn't open password file '%s'\n",
...@@ -84,7 +85,7 @@ verify_password(char *user, char *password, Port *port, ...@@ -84,7 +85,7 @@ verify_password(char *user, char *password, Port *port,
if(strcmp(user, test_user) == 0) { if(strcmp(user, test_user) == 0) {
/* we're outta here one way or the other. */ /* we're outta here one way or the other. */
fclose(pw_file); FreeFile(pw_file);
if(strcmp(crypt(password, salt), test_pw) == 0) { if(strcmp(crypt(password, salt), test_pw) == 0) {
/* it matched. */ /* it matched. */
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* $Id: geqo_params.c,v 1.4 1997/08/12 22:53:09 momjian Exp $ * $Id: geqo_params.c,v 1.5 1997/08/18 02:14:41 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -43,6 +43,8 @@ ...@@ -43,6 +43,8 @@
#include "optimizer/geqo_gene.h" #include "optimizer/geqo_gene.h"
#include "optimizer/geqo.h" #include "optimizer/geqo.h"
#include "storage/fd.h"
#define POOL_TAG "Pool_Size" #define POOL_TAG "Pool_Size"
#define TRIAL_TAG "Generations" #define TRIAL_TAG "Generations"
#define RAND_TAG "Random_Seed" #define RAND_TAG "Random_Seed"
...@@ -89,7 +91,7 @@ geqo_params(int string_length) ...@@ -89,7 +91,7 @@ geqo_params(int string_length)
sprintf(conf_file, "%s/%s", DataDir, GEQO_FILE); sprintf(conf_file, "%s/%s", DataDir, GEQO_FILE);
/* open the config file */ /* open the config file */
file = fopen(conf_file, "r"); file = AllocateFile(conf_file, "r");
if (file) if (file)
{ {
/* /*
...@@ -187,7 +189,7 @@ geqo_params(int string_length) ...@@ -187,7 +189,7 @@ geqo_params(int string_length)
} }
} }
fclose(file); FreeFile(file);
pfree(conf_file); pfree(conf_file);
} }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/Attic/dbcommands.c,v 1.3 1997/01/10 20:18:20 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/Attic/dbcommands.c,v 1.4 1997/08/18 02:14:44 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "tcop/tcopprot.h" #include "tcop/tcopprot.h"
#include "storage/bufmgr.h" #include "storage/bufmgr.h"
#include "storage/lmgr.h" #include "storage/lmgr.h"
#include "storage/fd.h"
/* non-export function prototypes */ /* non-export function prototypes */
...@@ -249,9 +250,9 @@ stop_vacuum(char *dbname) ...@@ -249,9 +250,9 @@ stop_vacuum(char *dbname)
sprintf(filename, "%s%cbase%c%s%c%s.vacuum", DataDir, SEP_CHAR, SEP_CHAR, sprintf(filename, "%s%cbase%c%s%c%s.vacuum", DataDir, SEP_CHAR, SEP_CHAR,
dbname, SEP_CHAR, dbname); dbname, SEP_CHAR, dbname);
if ((fp = fopen(filename, "r")) != (FILE *) NULL) { if ((fp = AllocateFile(filename, "r")) != NULL) {
fscanf(fp, "%d", &pid); fscanf(fp, "%d", &pid);
fclose(fp); FreeFile(fp);
if (kill(pid, SIGKILLDAEMON1) < 0) { if (kill(pid, SIGKILLDAEMON1) < 0) {
elog(WARN, "can't kill vacuum daemon (pid %d) on %s", elog(WARN, "can't kill vacuum daemon (pid %d) on %s",
pid, dbname); pid, dbname);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.16 1997/08/12 22:53:46 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.17 1997/08/18 02:14:49 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -1663,7 +1663,7 @@ _bm_die(Oid dbId, Oid relId, int blkNo, int bufNo, ...@@ -1663,7 +1663,7 @@ _bm_die(Oid dbId, Oid relId, int blkNo, int bufNo,
tb = &TraceBuf[cur]; tb = &TraceBuf[cur];
if ((fp = fopen("/tmp/death_notice", "w")) == (FILE *) NULL) if ((fp = AllocateFile("/tmp/death_notice", "w")) == NULL)
elog(FATAL, "buffer alloc trace error and can't open log file"); elog(FATAL, "buffer alloc trace error and can't open log file");
fprintf(fp, "buffer alloc trace detected the following error:\n\n"); fprintf(fp, "buffer alloc trace detected the following error:\n\n");
...@@ -1728,7 +1728,7 @@ _bm_die(Oid dbId, Oid relId, int blkNo, int bufNo, ...@@ -1728,7 +1728,7 @@ _bm_die(Oid dbId, Oid relId, int blkNo, int bufNo,
break; break;
} }
fclose(fp); FreeFile(fp);
kill(getpid(), SIGILL); kill(getpid(), SIGILL);
} }
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Id: fd.c,v 1.20 1997/08/12 22:53:51 momjian Exp $ * $Id: fd.c,v 1.21 1997/08/18 02:14:50 momjian Exp $
* *
* NOTES: * NOTES:
* *
...@@ -124,12 +124,6 @@ static Size SizeVfdCache = 0; ...@@ -124,12 +124,6 @@ static Size SizeVfdCache = 0;
*/ */
static int nfile = 0; static int nfile = 0;
/*
* we use the name of the null device in various places, mostly so
* that we can open it and find out if we really have any descriptors
* available or not.
*/
static char *Nulldev = "/dev/null";
static char Sep_char = '/'; static char Sep_char = '/';
/* /*
...@@ -312,7 +306,6 @@ LruInsert (File file) ...@@ -312,7 +306,6 @@ LruInsert (File file)
vfdP = &VfdCache[file]; vfdP = &VfdCache[file];
if (FileIsNotOpen(file)) { if (FileIsNotOpen(file)) {
int tmpfd;
if ( nfile >= pg_nofile() ) if ( nfile >= pg_nofile() )
AssertLruRoom(); AssertLruRoom();
...@@ -324,16 +317,13 @@ LruInsert (File file) ...@@ -324,16 +317,13 @@ LruInsert (File file)
* should be able to open all the time. If this fails, we * should be able to open all the time. If this fails, we
* assume this is because there's no free file descriptors. * assume this is because there's no free file descriptors.
*/ */
tryAgain: tryAgain:
tmpfd = open(Nulldev, O_CREAT|O_RDWR, 0666); vfdP->fd = open(vfdP->fileName,vfdP->fileFlags,vfdP->fileMode);
if (tmpfd < 0) { if (vfdP->fd < 0 && (errno == EMFILE || errno == ENFILE)) {
errno = 0; errno = 0;
AssertLruRoom(); AssertLruRoom();
goto tryAgain; goto tryAgain;
} else {
close(tmpfd);
} }
vfdP->fd = open(vfdP->fileName,vfdP->fileFlags,vfdP->fileMode);
if (vfdP->fd < 0) { if (vfdP->fd < 0) {
DO_DB(elog(DEBUG, "RE_OPEN FAILED: %d", DO_DB(elog(DEBUG, "RE_OPEN FAILED: %d",
...@@ -530,7 +520,6 @@ fileNameOpenFile(FileName fileName, ...@@ -530,7 +520,6 @@ fileNameOpenFile(FileName fileName,
{ {
File file; File file;
Vfd *vfdP; Vfd *vfdP;
int tmpfd;
DO_DB(elog(DEBUG, "fileNameOpenFile: %s %x %o", DO_DB(elog(DEBUG, "fileNameOpenFile: %s %x %o",
fileName, fileFlags, fileMode)); fileName, fileFlags, fileMode));
...@@ -542,18 +531,15 @@ fileNameOpenFile(FileName fileName, ...@@ -542,18 +531,15 @@ fileNameOpenFile(FileName fileName,
AssertLruRoom(); AssertLruRoom();
tryAgain: tryAgain:
tmpfd = open(Nulldev, O_CREAT|O_RDWR, 0666); vfdP->fd = open(fileName,fileFlags,fileMode);
if (tmpfd < 0) { if (vfdP->fd < 0 && (errno == EMFILE || errno == ENFILE)) {
DO_DB(elog(DEBUG, "fileNameOpenFile: not enough descs, retry, er= %d", DO_DB(elog(DEBUG, "fileNameOpenFile: not enough descs, retry, er= %d",
errno)); errno));
errno = 0; errno = 0;
AssertLruRoom(); AssertLruRoom();
goto tryAgain; goto tryAgain;
} else {
close(tmpfd);
} }
vfdP->fd = open(fileName,fileFlags,fileMode);
vfdP->fdstate = 0x0; vfdP->fdstate = 0x0;
if (vfdP->fd < 0) { if (vfdP->fd < 0) {
...@@ -816,30 +802,31 @@ FileNameUnlink(char *filename) ...@@ -816,30 +802,31 @@ FileNameUnlink(char *filename)
*/ */
static int allocatedFiles = 0; static int allocatedFiles = 0;
void FILE *
AllocateFile() AllocateFile(char *name, char *mode)
{ {
int fd; FILE *file;
int fdleft; int fdleft;
DO_DB(elog(DEBUG, "AllocateFile: Allocated %d.", allocatedFiles)); DO_DB(elog(DEBUG, "AllocateFile: Allocated %d.", allocatedFiles));
while ((fd = open(Nulldev,O_WRONLY,0)) < 0) { TryAgain:
if (errno == EMFILE) { if ((file = fopen(name, mode)) == NULL) {
errno = 0; if (errno == EMFILE || errno == ENFILE) {
AssertLruRoom(); DO_DB(elog(DEBUG, "AllocateFile: not enough descs, retry, er= %d",
} else { errno));
elog(WARN,"Open: %s in %s line %d, %s", Nulldev, errno = 0;
__FILE__, __LINE__, strerror(errno)); AssertLruRoom();
} goto TryAgain;
}
} }
close(fd); else {
++allocatedFiles; ++allocatedFiles;
fdleft = pg_nofile() - allocatedFiles; fdleft = pg_nofile() - allocatedFiles;
if (fdleft < 6) { if (fdleft < 6)
elog(NOTICE,"warning: few usable file descriptors left (%d)", fdleft); elog(NOTICE,"warning: few usable file descriptors left (%d)", fdleft);
} }
return file;
} }
/* /*
...@@ -847,11 +834,12 @@ AllocateFile() ...@@ -847,11 +834,12 @@ AllocateFile()
* AllocateFile()? * AllocateFile()?
*/ */
void void
FreeFile() FreeFile(FILE *file)
{ {
DO_DB(elog(DEBUG, "FreeFile: Allocated %d.", allocatedFiles)); DO_DB(elog(DEBUG, "FreeFile: Allocated %d.", allocatedFiles));
Assert(allocatedFiles > 0); Assert(allocatedFiles > 0);
fclose(file);
--allocatedFiles; --allocatedFiles;
} }
...@@ -865,15 +853,3 @@ closeAllVfds() ...@@ -865,15 +853,3 @@ closeAllVfds()
LruDelete(i); LruDelete(i);
} }
} }
void
closeOneVfd()
{
int tmpfd;
tmpfd = open(Nulldev, O_CREAT | O_RDWR, 0666);
if (tmpfd < 0)
AssertLruRoom();
else
close(tmpfd);
}
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.18 1997/07/24 20:15:18 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.19 1997/08/18 02:14:52 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
#include "tcop/variable.h" #include "tcop/variable.h"
#include "tcop/utility.h" #include "tcop/utility.h"
#include "fmgr.h" /* For load_file() */ #include "fmgr.h" /* For load_file() */
#include "storage/fd.h"
#ifndef NO_SECURITY #ifndef NO_SECURITY
#include "miscadmin.h" #include "miscadmin.h"
...@@ -218,9 +219,6 @@ ProcessUtility(Node *parsetree, ...@@ -218,9 +219,6 @@ ProcessUtility(Node *parsetree,
commandTag = "COPY"; commandTag = "COPY";
CHECK_IF_ABORTED(); CHECK_IF_ABORTED();
/* Free up file descriptors - going to do a read... */
closeOneVfd();
DoCopy(stmt->relname, DoCopy(stmt->relname,
stmt->binary, stmt->binary,
stmt->oids, stmt->oids,
...@@ -594,9 +592,9 @@ ProcessUtility(Node *parsetree, ...@@ -594,9 +592,9 @@ ProcessUtility(Node *parsetree,
filename = stmt->filename; filename = stmt->filename;
closeAllVfds(); closeAllVfds();
if ((fp = fopen(filename, "r")) == NULL) if ((fp = AllocateFile(filename, "r")) == NULL)
elog(WARN, "LOAD: could not open file %s", filename); elog(WARN, "LOAD: could not open file %s", filename);
fclose(fp); FreeFile(fp);
load_file(filename); load_file(filename);
} }
break; break;
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.13 1997/08/12 22:54:24 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.14 1997/08/18 02:14:54 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
#include "utils/syscache.h" #include "utils/syscache.h"
#include "utils/memutils.h" #include "utils/memutils.h"
#include "storage/fd.h" /* for SEEK_ */ #include "storage/fd.h"
#include "fmgr.h" #include "fmgr.h"
#include "utils/array.h" #include "utils/array.h"
...@@ -463,11 +463,12 @@ _ReadLOArray(char *str, ...@@ -463,11 +463,12 @@ _ReadLOArray(char *str,
if ( accessfile ) { if ( accessfile ) {
FILE *afd; FILE *afd;
if ((afd = fopen (accessfile, "r")) == NULL) if ((afd = AllocateFile(accessfile, "r")) == NULL)
elog(WARN, "unable to open access pattern file"); elog(WARN, "unable to open access pattern file");
*chunkFlag = true; *chunkFlag = true;
retStr = _ChunkArray(*fd, afd, ndim, dim, baseSize, nbytes, retStr = _ChunkArray(*fd, afd, ndim, dim, baseSize, nbytes,
chunkfile); chunkfile);
FreeFile(afd);
} }
return(retStr); return(retStr);
} }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/sort/Attic/psort.c,v 1.15 1997/08/14 16:11:28 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/sort/Attic/psort.c,v 1.16 1997/08/18 02:14:56 momjian Exp $
* *
* NOTES * NOTES
* Sorts the first relation into the second relation. * Sorts the first relation into the second relation.
...@@ -763,16 +763,10 @@ gettape() ...@@ -763,16 +763,10 @@ gettape()
memmove(tp->tl_name, uniqueName, strlen(uniqueName)); memmove(tp->tl_name, uniqueName, strlen(uniqueName));
AllocateFile(); file = AllocateFile(tp->tl_name, "w+");
file = fopen(tp->tl_name, "w+"); if (file == NULL)
if (file == NULL) { elog(WARN,"Open: %s in %s line %d, %s", tp->tl_name,
elog(NOTICE, "psort: gettape: fopen returned error code %i", errno); __FILE__, __LINE__, strerror(errno));
/* XXX this should not happen */
FreeFile();
FREE(tp->tl_name);
FREE(tp);
return(NULL);
}
tp->tl_fd = fileno(file); tp->tl_fd = fileno(file);
tp->tl_next = Tapes; tp->tl_next = Tapes;
...@@ -823,8 +817,7 @@ destroytape(FILE *file) ...@@ -823,8 +817,7 @@ destroytape(FILE *file)
if ((fd = fileno(file)) == tp->tl_fd) { if ((fd = fileno(file)) == tp->tl_fd) {
Tapes = tp->tl_next; Tapes = tp->tl_next;
fclose(file); FreeFile(file);
FreeFile();
unlink(tp->tl_name); unlink(tp->tl_name);
FREE(tp->tl_name); FREE(tp->tl_name);
FREE(tp); FREE(tp);
...@@ -833,8 +826,7 @@ destroytape(FILE *file) ...@@ -833,8 +826,7 @@ destroytape(FILE *file)
if (tp->tl_next == NULL) if (tp->tl_next == NULL)
elog(FATAL, "destroytape: tape not found"); elog(FATAL, "destroytape: tape not found");
if (tp->tl_next->tl_fd == fd) { if (tp->tl_next->tl_fd == fd) {
fclose(file); FreeFile(file);
FreeFile();
tq = tp->tl_next; tq = tp->tl_next;
tp->tl_next = tq->tl_next; tp->tl_next = tq->tl_next;
unlink(tq->tl_name); unlink(tq->tl_name);
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* $Id: fd.h,v 1.6 1997/02/14 04:18:42 momjian Exp $ * $Id: fd.h,v 1.7 1997/08/18 02:15:04 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -34,11 +34,7 @@ ...@@ -34,11 +34,7 @@
#ifndef FD_H #ifndef FD_H
#define FD_H #define FD_H
/* #include <stdio.h>
* FileOpen uses the standard UNIX open(2) flags.
*/
#ifndef O_RDONLY
#endif /* O_RDONLY */
/* /*
* FileSeek uses the standard UNIX lseek(2) flags. * FileSeek uses the standard UNIX lseek(2) flags.
...@@ -76,10 +72,9 @@ extern long FileTell(File file); ...@@ -76,10 +72,9 @@ extern long FileTell(File file);
extern int FileTruncate(File file, int offset); extern int FileTruncate(File file, int offset);
extern int FileSync(File file); extern int FileSync(File file);
extern int FileNameUnlink(char *filename); extern int FileNameUnlink(char *filename);
extern void AllocateFile(void); extern FILE *AllocateFile(char *name, char *mode);
extern void FreeFile(void); extern void FreeFile(FILE *);
extern void closeAllVfds(void); extern void closeAllVfds(void);
extern void closeOneVfd(void);
extern int pg_fsync(int fd); extern int pg_fsync(int fd);
#endif /* FD_H */ #endif /* FD_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment