diff options
| author | Bruce Momjian | 2004-08-29 05:07:03 +0000 |
|---|---|---|
| committer | Bruce Momjian | 2004-08-29 05:07:03 +0000 |
| commit | b6b71b85bc45b49005b5aec87cba2c33fc8baf49 (patch) | |
| tree | c23dbd1dbc43972a8e48327c8a771baf36952f3d /src/port | |
| parent | 90cb9c305140684b2b00c739b724f67915e11404 (diff) | |
Pgindent run for 8.0.
Diffstat (limited to 'src/port')
| -rw-r--r-- | src/port/dirmod.c | 114 | ||||
| -rw-r--r-- | src/port/exec.c | 124 | ||||
| -rw-r--r-- | src/port/fseeko.c | 4 | ||||
| -rw-r--r-- | src/port/kill.c | 3 | ||||
| -rw-r--r-- | src/port/noblock.c | 9 | ||||
| -rw-r--r-- | src/port/open.c | 84 | ||||
| -rw-r--r-- | src/port/path.c | 116 | ||||
| -rw-r--r-- | src/port/pgstrcasecmp.c | 10 | ||||
| -rw-r--r-- | src/port/pipe.c | 28 | ||||
| -rw-r--r-- | src/port/rand.c | 22 | ||||
| -rw-r--r-- | src/port/snprintf.c | 4 | ||||
| -rw-r--r-- | src/port/sprompt.c | 4 | ||||
| -rw-r--r-- | src/port/thread.c | 23 | ||||
| -rw-r--r-- | src/port/unsetenv.c | 27 |
14 files changed, 301 insertions, 271 deletions
diff --git a/src/port/dirmod.c b/src/port/dirmod.c index 23823b18a53..e7d0ef23c3f 100644 --- a/src/port/dirmod.c +++ b/src/port/dirmod.c @@ -10,7 +10,7 @@ * Win32 (NT, Win2k, XP). replace() doesn't work on Win95/98/Me. * * IDENTIFICATION - * $PostgreSQL: pgsql/src/port/dirmod.c,v 1.21 2004/08/29 04:13:12 momjian Exp $ + * $PostgreSQL: pgsql/src/port/dirmod.c,v 1.22 2004/08/29 05:07:02 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -70,28 +70,28 @@ pgrename(const char *from, const char *to) while (!MoveFileEx(from, to, MOVEFILE_REPLACE_EXISTING)) #endif #ifdef __CYGWIN__ - while (rename(from, to) < 0) + while (rename(from, to) < 0) #endif - { + { #ifdef WIN32 - if (GetLastError() != ERROR_ACCESS_DENIED) + if (GetLastError() != ERROR_ACCESS_DENIED) #endif #ifdef __CYGWIN__ - if (errno != EACCES) + if (errno != EACCES) #endif - /* set errno? */ - return -1; - pg_usleep(100000); /* us */ - if (loops == 30) + /* set errno? */ + return -1; + pg_usleep(100000); /* us */ + if (loops == 30) #ifndef FRONTEND - elog(LOG, "could not rename \"%s\" to \"%s\", continuing to try", - from, to); + elog(LOG, "could not rename \"%s\" to \"%s\", continuing to try", + from, to); #else - fprintf(stderr, "could not rename \"%s\" to \"%s\", continuing to try\n", - from, to); + fprintf(stderr, "could not rename \"%s\" to \"%s\", continuing to try\n", + from, to); #endif - loops++; - } + loops++; + } if (loops > 30) #ifndef FRONTEND @@ -147,17 +147,18 @@ pgunlink(const char *path) */ typedef struct { - DWORD ReparseTag; - WORD ReparseDataLength; - WORD Reserved; - /* SymbolicLinkReparseBuffer */ - WORD SubstituteNameOffset; - WORD SubstituteNameLength; - WORD PrintNameOffset; - WORD PrintNameLength; - WCHAR PathBuffer[1]; + DWORD ReparseTag; + WORD ReparseDataLength; + WORD Reserved; + /* SymbolicLinkReparseBuffer */ + WORD SubstituteNameOffset; + WORD SubstituteNameLength; + WORD PrintNameOffset; + WORD PrintNameLength; + WCHAR PathBuffer[1]; } -REPARSE_JUNCTION_DATA_BUFFER; + + REPARSE_JUNCTION_DATA_BUFFER; #define REPARSE_JUNCTION_DATA_BUFFER_HEADER_SIZE \ FIELD_OFFSET(REPARSE_JUNCTION_DATA_BUFFER, SubstituteNameOffset) @@ -171,27 +172,27 @@ REPARSE_JUNCTION_DATA_BUFFER; int pgsymlink(const char *oldpath, const char *newpath) { - HANDLE dirhandle; - DWORD len; - char buffer[MAX_PATH*sizeof(WCHAR) + sizeof(REPARSE_JUNCTION_DATA_BUFFER)]; - char nativeTarget[MAX_PATH]; - char *p = nativeTarget; - REPARSE_JUNCTION_DATA_BUFFER *reparseBuf = (REPARSE_JUNCTION_DATA_BUFFER*)buffer; - + HANDLE dirhandle; + DWORD len; + char buffer[MAX_PATH * sizeof(WCHAR) + sizeof(REPARSE_JUNCTION_DATA_BUFFER)]; + char nativeTarget[MAX_PATH]; + char *p = nativeTarget; + REPARSE_JUNCTION_DATA_BUFFER *reparseBuf = (REPARSE_JUNCTION_DATA_BUFFER *) buffer; + CreateDirectory(newpath, 0); - dirhandle = CreateFile(newpath, GENERIC_READ | GENERIC_WRITE, - 0, 0, OPEN_EXISTING, - FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS, 0); - + dirhandle = CreateFile(newpath, GENERIC_READ | GENERIC_WRITE, + 0, 0, OPEN_EXISTING, + FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS, 0); + if (dirhandle == INVALID_HANDLE_VALUE) return -1; - + /* make sure we have an unparsed native win32 path */ if (memcmp("\\??\\", oldpath, 4)) sprintf(nativeTarget, "\\??\\%s", oldpath); else strcpy(nativeTarget, oldpath); - + while ((p = strchr(p, '/')) != 0) *p++ = '\\'; @@ -201,36 +202,36 @@ pgsymlink(const char *oldpath, const char *newpath) reparseBuf->Reserved = 0; reparseBuf->SubstituteNameOffset = 0; reparseBuf->SubstituteNameLength = len; - reparseBuf->PrintNameOffset = len+sizeof(WCHAR); + reparseBuf->PrintNameOffset = len + sizeof(WCHAR); reparseBuf->PrintNameLength = 0; MultiByteToWideChar(CP_ACP, 0, nativeTarget, -1, reparseBuf->PathBuffer, MAX_PATH); - + /* - * FSCTL_SET_REPARSE_POINT is coded differently depending on SDK version; - * we use our own definition + * FSCTL_SET_REPARSE_POINT is coded differently depending on SDK + * version; we use our own definition */ - if (!DeviceIoControl(dirhandle, - CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 41, METHOD_BUFFERED, FILE_ANY_ACCESS), - reparseBuf, - reparseBuf->ReparseDataLength + REPARSE_JUNCTION_DATA_BUFFER_HEADER_SIZE, - 0, 0, &len, 0)) + if (!DeviceIoControl(dirhandle, + CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 41, METHOD_BUFFERED, FILE_ANY_ACCESS), + reparseBuf, + reparseBuf->ReparseDataLength + REPARSE_JUNCTION_DATA_BUFFER_HEADER_SIZE, + 0, 0, &len, 0)) { - LPSTR msg; + LPSTR msg; - errno=0; + errno = 0; FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, - NULL, GetLastError(), + NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPSTR)&msg, 0, NULL ); + (LPSTR) & msg, 0, NULL); #ifndef FRONTEND ereport(ERROR, (errcode_for_file_access(), - errmsg("Error setting junction for %s: %s", nativeTarget, msg))); + errmsg("Error setting junction for %s: %s", nativeTarget, msg))); #else fprintf(stderr, "Error setting junction for %s: %s", nativeTarget, msg); #endif LocalFree(msg); - + CloseHandle(dirhandle); RemoveDirectory(newpath); return -1; @@ -240,7 +241,6 @@ pgsymlink(const char *oldpath, const char *newpath) return 0; } - #endif @@ -255,9 +255,9 @@ pgsymlink(const char *oldpath, const char *newpath) * deallocate memory used for filenames */ static void -rmt_cleanup(char ** filenames) +rmt_cleanup(char **filenames) { - char ** fn; + char **fn; for (fn = filenames; *fn; fn++) #ifdef FRONTEND @@ -326,7 +326,7 @@ rmtree(char *path, bool rmtopdir) if (strcmp(file->d_name, ".") != 0 && strcmp(file->d_name, "..") != 0) #ifdef FRONTEND if ((filenames[numnames++] = strdup(file->d_name)) == NULL) - { + { fprintf(stderr, _("out of memory\n")); exit(1); } diff --git a/src/port/exec.c b/src/port/exec.c index 9981fce7d13..5e624759753 100644 --- a/src/port/exec.c +++ b/src/port/exec.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/port/exec.c,v 1.24 2004/08/29 04:13:12 momjian Exp $ + * $PostgreSQL: pgsql/src/port/exec.c,v 1.25 2004/08/29 05:07:02 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -69,6 +69,7 @@ validate_exec(const char *path) struct passwd *pwp; int i; int in_grp = 0; + #else char path_exe[MAXPGPATH + 2 + strlen(".exe")]; #endif @@ -122,8 +123,8 @@ validate_exec(const char *path) } /* OK, check group bits */ - - pwp = getpwuid(euid); /* not thread-safe */ + + pwp = getpwuid(euid); /* not thread-safe */ if (pwp) { if (pwp->pw_gid == buf.st_gid) /* my primary group? */ @@ -131,7 +132,7 @@ validate_exec(const char *path) else if (pwp->pw_name && (gp = getgrgid(buf.st_gid)) != NULL && /* not thread-safe */ gp->gr_mem != NULL) - { /* try list of member groups */ + { /* try list of member groups */ for (i = 0; gp->gr_mem[i]; ++i) { if (!strcmp(gp->gr_mem[i], pwp->pw_name)) @@ -153,7 +154,6 @@ validate_exec(const char *path) is_r = buf.st_mode & S_IROTH; is_x = buf.st_mode & S_IXOTH; return is_x ? (is_r ? 0 : -2) : -1; - #endif } @@ -166,23 +166,24 @@ validate_exec(const char *path) * path because we will later change working directory. * * This function is not thread-safe because of it calls validate_exec(), - * which calls getgrgid(). This function should be used only in + * which calls getgrgid(). This function should be used only in * non-threaded binaries, not in library routines. */ int find_my_exec(const char *argv0, char *retpath) { - char cwd[MAXPGPATH], test_path[MAXPGPATH]; - char *path; + char cwd[MAXPGPATH], + test_path[MAXPGPATH]; + char *path; if (!getcwd(cwd, MAXPGPATH)) cwd[0] = '\0'; /* - * First try: use the binary that's located in the - * same directory if it was invoked with an explicit path. - * Presumably the user used an explicit path because it - * wasn't in PATH, and we don't want to use incompatible executables. + * First try: use the binary that's located in the same directory if + * it was invoked with an explicit path. Presumably the user used an + * explicit path because it wasn't in PATH, and we don't want to use + * incompatible executables. * * For the binary: First try: if we're given some kind of path, use it * (making sure that a relative path is made absolute before returning @@ -201,7 +202,7 @@ find_my_exec(const char *argv0, char *retpath) StrNCpy(retpath, argv0, MAXPGPATH); else snprintf(retpath, MAXPGPATH, "%s/%s", cwd, argv0); - + canonicalize_path(retpath); if (validate_exec(retpath) == 0) { @@ -231,7 +232,8 @@ find_my_exec(const char *argv0, char *retpath) */ if ((path = getenv("PATH")) && *path) { - char *startp = NULL, *endp = NULL; + char *startp = NULL, + *endp = NULL; do { @@ -242,7 +244,7 @@ find_my_exec(const char *argv0, char *retpath) endp = first_path_separator(startp); if (!endp) - endp = startp + strlen(startp); /* point to end */ + endp = startp + strlen(startp); /* point to end */ StrNCpy(test_path, startp, Min(endp - startp + 1, MAXPGPATH)); @@ -270,12 +272,13 @@ find_my_exec(const char *argv0, char *retpath) return -1; #if 0 + /* - * Win32 has a native way to find the executable name, but the above - * method works too. + * Win32 has a native way to find the executable name, but the above + * method works too. */ if (GetModuleFileName(NULL, retpath, MAXPGPATH) == 0) - log_error("GetModuleFileName failed (%i)",(int)GetLastError()); + log_error("GetModuleFileName failed (%i)", (int) GetLastError()); #endif } @@ -287,11 +290,12 @@ find_my_exec(const char *argv0, char *retpath) * Executing a command in a pipe and reading the first line from it * is all we need. */ - -static char *pipe_read_line(char *cmd, char *line, int maxsize) + +static char * +pipe_read_line(char *cmd, char *line, int maxsize) { #ifndef WIN32 - FILE *pgver; + FILE *pgver; /* flush output buffers in case popen does not... */ fflush(stdout); @@ -299,7 +303,7 @@ static char *pipe_read_line(char *cmd, char *line, int maxsize) if ((pgver = popen(cmd, "r")) == NULL) return NULL; - + if (fgets(line, maxsize, pgver) == NULL) { perror("fgets failure"); @@ -308,15 +312,17 @@ static char *pipe_read_line(char *cmd, char *line, int maxsize) if (pclose_check(pgver)) return NULL; - + return line; #else /* Win32 */ SECURITY_ATTRIBUTES sattr; - HANDLE childstdoutrd, childstdoutwr, childstdoutrddup; + HANDLE childstdoutrd, + childstdoutwr, + childstdoutrddup; PROCESS_INFORMATION pi; STARTUPINFO si; - char *retval = NULL; + char *retval = NULL; sattr.nLength = sizeof(SECURITY_ATTRIBUTES); sattr.bInheritHandle = TRUE; @@ -324,7 +330,7 @@ static char *pipe_read_line(char *cmd, char *line, int maxsize) if (!CreatePipe(&childstdoutrd, &childstdoutwr, &sattr, 0)) return NULL; - + if (!DuplicateHandle(GetCurrentProcess(), childstdoutrd, GetCurrentProcess(), @@ -339,15 +345,15 @@ static char *pipe_read_line(char *cmd, char *line, int maxsize) } CloseHandle(childstdoutrd); - - ZeroMemory(&pi,sizeof(pi)); - ZeroMemory(&si,sizeof(si)); + + ZeroMemory(&pi, sizeof(pi)); + ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); si.dwFlags = STARTF_USESTDHANDLES; si.hStdError = childstdoutwr; si.hStdOutput = childstdoutwr; si.hStdInput = INVALID_HANDLE_VALUE; - + if (CreateProcess(NULL, cmd, NULL, @@ -359,13 +365,14 @@ static char *pipe_read_line(char *cmd, char *line, int maxsize) &si, &pi)) { - DWORD bytesread = 0; + DWORD bytesread = 0; + /* Successfully started the process */ - ZeroMemory(line,maxsize); - + ZeroMemory(line, maxsize); + /* Let's see if we can read */ - if (WaitForSingleObject(childstdoutrddup, 10000) != WAIT_OBJECT_0) + if (WaitForSingleObject(childstdoutrddup, 10000) != WAIT_OBJECT_0) { /* Got timeout */ CloseHandle(pi.hProcess); @@ -381,42 +388,41 @@ static char *pipe_read_line(char *cmd, char *line, int maxsize) { /* So we read some data */ retval = line; - int len = strlen(line); + int len = strlen(line); /* - * If EOL is \r\n, convert to just \n. - * Because stdout is a text-mode stream, the \n output by - * the child process is received as \r\n, so we convert it - * to \n. The server main.c sets - * setvbuf(stdout, NULL, _IONBF, 0) which has the effect - * of disabling \n to \r\n expansion for stdout. + * If EOL is \r\n, convert to just \n. Because stdout is a + * text-mode stream, the \n output by the child process is + * received as \r\n, so we convert it to \n. The server + * main.c sets setvbuf(stdout, NULL, _IONBF, 0) which has the + * effect of disabling \n to \r\n expansion for stdout. */ - if (len >= 2 && line[len-2] == '\r' && line[len-1] == '\n') + if (len >= 2 && line[len - 2] == '\r' && line[len - 1] == '\n') { - line[len-2] = '\n'; - line[len-1] = '\0'; + line[len - 2] = '\n'; + line[len - 1] = '\0'; len--; } /* - * We emulate fgets() behaviour. So if there is no newline - * at the end, we add one... + * We emulate fgets() behaviour. So if there is no newline at + * the end, we add one... */ - if (len == 0 || line[len-1] != '\n') - strcat(line,"\n"); + if (len == 0 || line[len - 1] != '\n') + strcat(line, "\n"); } CloseHandle(pi.hProcess); CloseHandle(pi.hThread); } - + CloseHandle(childstdoutwr); CloseHandle(childstdoutrddup); return retval; #endif } - + /* @@ -429,11 +435,11 @@ find_other_exec(const char *argv0, const char *target, { char cmd[MAXPGPATH]; char line[100]; - + if (find_my_exec(argv0, retpath) < 0) return -1; - /* Trim off program name and keep just directory */ + /* Trim off program name and keep just directory */ *last_dir_separator(retpath) = '\0'; canonicalize_path(retpath); @@ -443,12 +449,12 @@ find_other_exec(const char *argv0, const char *target, if (validate_exec(retpath)) return -1; - + snprintf(cmd, sizeof(cmd), "\"%s\" -V 2>%s", retpath, DEVNULL); if (!pipe_read_line(cmd, line, sizeof(line))) return -1; - + if (strcmp(line, versionstr) != 0) return -2; @@ -464,12 +470,12 @@ find_other_exec(const char *argv0, const char *target, int pclose_check(FILE *stream) { - int exitstatus; + int exitstatus; exitstatus = pclose(stream); if (exitstatus == 0) - return 0; /* all is well */ + return 0; /* all is well */ if (exitstatus == -1) { @@ -479,17 +485,17 @@ pclose_check(FILE *stream) else if (WIFEXITED(exitstatus)) { log_error(_("child process exited with exit code %d\n"), - WEXITSTATUS(exitstatus)); + WEXITSTATUS(exitstatus)); } else if (WIFSIGNALED(exitstatus)) { log_error(_("child process was terminated by signal %d\n"), - WTERMSIG(exitstatus)); + WTERMSIG(exitstatus)); } else { log_error(_("child process exited with unrecognized status %d\n"), - exitstatus); + exitstatus); } return -1; diff --git a/src/port/fseeko.c b/src/port/fseeko.c index 1dff8363d4e..00aa15298fe 100644 --- a/src/port/fseeko.c +++ b/src/port/fseeko.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/port/fseeko.c,v 1.15 2004/08/29 04:13:12 momjian Exp $ + * $PostgreSQL: pgsql/src/port/fseeko.c,v 1.16 2004/08/29 05:07:02 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -68,7 +68,7 @@ fseeko(FILE *stream, off_t offset, int whence) #ifdef bsdi flockfile(stream); #endif - fflush(stream); /* force writes to fd for stat() */ + fflush(stream); /* force writes to fd for stat() */ if (fstat(fileno(stream), &filestat) != 0) goto failure; floc = filestat.st_size; diff --git a/src/port/kill.c b/src/port/kill.c index 0536ce758ec..8baf19c4c01 100644 --- a/src/port/kill.c +++ b/src/port/kill.c @@ -9,7 +9,7 @@ * signals that the backend can recognize. * * IDENTIFICATION - * $PostgreSQL: pgsql/src/port/kill.c,v 1.4 2004/08/29 04:13:12 momjian Exp $ + * $PostgreSQL: pgsql/src/port/kill.c,v 1.5 2004/08/29 05:07:02 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -57,4 +57,5 @@ pgkill(int pid, int sig) return 0; } + #endif diff --git a/src/port/noblock.c b/src/port/noblock.c index 01be8524a85..ca05141cf55 100644 --- a/src/port/noblock.c +++ b/src/port/noblock.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/port/noblock.c,v 1.3 2004/08/29 04:13:12 momjian Exp $ + * $PostgreSQL: pgsql/src/port/noblock.c,v 1.4 2004/08/29 05:07:02 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -17,13 +17,14 @@ #include <sys/types.h> #include <fcntl.h> -bool set_noblock(int sock) +bool +set_noblock(int sock) { #if !defined(WIN32) && !defined(__BEOS__) return (fcntl(sock, F_SETFL, O_NONBLOCK) != -1); #else - long ioctlsocket_ret = 1; - + long ioctlsocket_ret = 1; + /* Returns non-0 on failure, while fcntl() returns -1 on failure */ #ifdef WIN32 return (ioctlsocket(sock, FIONBIO, &ioctlsocket_ret) == 0); diff --git a/src/port/open.c b/src/port/open.c index 4c11f3dfda3..3304d443c6e 100644 --- a/src/port/open.c +++ b/src/port/open.c @@ -6,7 +6,7 @@ * * Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/port/open.c,v 1.3 2004/08/29 04:13:12 momjian Exp $ + * $PostgreSQL: pgsql/src/port/open.c,v 1.4 2004/08/29 05:07:02 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -21,20 +21,25 @@ static int openFlagsToCreateFileFlags(int openFlags) { - switch (openFlags & (O_CREAT|O_TRUNC|O_EXCL)) + switch (openFlags & (O_CREAT | O_TRUNC | O_EXCL)) { case 0: - case O_EXCL: return OPEN_EXISTING; + case O_EXCL: + return OPEN_EXISTING; - case O_CREAT: return OPEN_ALWAYS; + case O_CREAT: + return OPEN_ALWAYS; case O_TRUNC: - case O_TRUNC|O_EXCL: return TRUNCATE_EXISTING; + case O_TRUNC | O_EXCL: + return TRUNCATE_EXISTING; - case O_CREAT|O_TRUNC: return CREATE_ALWAYS; + case O_CREAT | O_TRUNC: + return CREATE_ALWAYS; - case O_CREAT|O_EXCL: - case O_CREAT|O_TRUNC|O_EXCL: return CREATE_NEW; + case O_CREAT | O_EXCL: + case O_CREAT | O_TRUNC | O_EXCL: + return CREATE_NEW; } /* will never get here */ @@ -42,46 +47,53 @@ openFlagsToCreateFileFlags(int openFlags) } /* - * - file attribute setting, based on fileMode? - * - handle other flags? (eg FILE_FLAG_NO_BUFFERING/FILE_FLAG_WRITE_THROUGH) + * - file attribute setting, based on fileMode? + * - handle other flags? (eg FILE_FLAG_NO_BUFFERING/FILE_FLAG_WRITE_THROUGH) */ -int win32_open(const char* fileName, int fileFlags, ...) +int +win32_open(const char *fileName, int fileFlags,...) { - int fd; - HANDLE h; + int fd; + HANDLE h; SECURITY_ATTRIBUTES sa; /* Check that we can handle the request */ - assert((fileFlags & ((O_RDONLY|O_WRONLY|O_RDWR) | O_APPEND | - (O_RANDOM|O_SEQUENTIAL|O_TEMPORARY) | - _O_SHORT_LIVED | - (O_CREAT|O_TRUNC|O_EXCL) | (O_TEXT|O_BINARY))) == fileFlags); + assert((fileFlags & ((O_RDONLY | O_WRONLY | O_RDWR) | O_APPEND | + (O_RANDOM | O_SEQUENTIAL | O_TEMPORARY) | + _O_SHORT_LIVED | + (O_CREAT | O_TRUNC | O_EXCL) | (O_TEXT | O_BINARY))) == fileFlags); - sa.nLength=sizeof(sa); - sa.bInheritHandle=TRUE; - sa.lpSecurityDescriptor=NULL; + sa.nLength = sizeof(sa); + sa.bInheritHandle = TRUE; + sa.lpSecurityDescriptor = NULL; if ((h = CreateFile(fileName, - /* cannot use O_RDONLY, as it == 0 */ - (fileFlags & O_RDWR) ? (GENERIC_WRITE | GENERIC_READ) : - ((fileFlags & O_WRONLY) ? GENERIC_WRITE : GENERIC_READ), - (FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE), + /* cannot use O_RDONLY, as it == 0 */ + (fileFlags & O_RDWR) ? (GENERIC_WRITE | GENERIC_READ) : + ((fileFlags & O_WRONLY) ? GENERIC_WRITE : GENERIC_READ), + (FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE), &sa, openFlagsToCreateFileFlags(fileFlags), - FILE_ATTRIBUTE_NORMAL | - ((fileFlags & O_RANDOM) ? FILE_FLAG_RANDOM_ACCESS : 0) | - ((fileFlags & O_SEQUENTIAL) ? FILE_FLAG_SEQUENTIAL_SCAN : 0) | - ((fileFlags & _O_SHORT_LIVED) ? FILE_ATTRIBUTE_TEMPORARY : 0) | - ((fileFlags & O_TEMPORARY) ? FILE_FLAG_DELETE_ON_CLOSE : 0), + FILE_ATTRIBUTE_NORMAL | + ((fileFlags & O_RANDOM) ? FILE_FLAG_RANDOM_ACCESS : 0) | + ((fileFlags & O_SEQUENTIAL) ? FILE_FLAG_SEQUENTIAL_SCAN : 0) | + ((fileFlags & _O_SHORT_LIVED) ? FILE_ATTRIBUTE_TEMPORARY : 0) | + ((fileFlags & O_TEMPORARY) ? FILE_FLAG_DELETE_ON_CLOSE : 0), NULL)) == INVALID_HANDLE_VALUE) { switch (GetLastError()) { - /* EMFILE, ENFILE should not occur from CreateFile. */ + /* EMFILE, ENFILE should not occur from CreateFile. */ case ERROR_PATH_NOT_FOUND: - case ERROR_FILE_NOT_FOUND: errno = ENOENT; break; - case ERROR_FILE_EXISTS: errno = EEXIST; break; - case ERROR_ACCESS_DENIED: errno = EACCES; break; + case ERROR_FILE_NOT_FOUND: + errno = ENOENT; + break; + case ERROR_FILE_EXISTS: + errno = EEXIST; + break; + case ERROR_ACCESS_DENIED: + errno = EACCES; + break; default: errno = EINVAL; } @@ -89,9 +101,9 @@ int win32_open(const char* fileName, int fileFlags, ...) } /* _open_osfhandle will, on error, set errno accordingly */ - if ((fd = _open_osfhandle((long)h,fileFlags&O_APPEND)) < 0 || - (fileFlags&(O_TEXT|O_BINARY) && (_setmode(fd,fileFlags&(O_TEXT|O_BINARY)) < 0))) - CloseHandle(h); /* will not affect errno */ + if ((fd = _open_osfhandle((long) h, fileFlags & O_APPEND)) < 0 || + (fileFlags & (O_TEXT | O_BINARY) && (_setmode(fd, fileFlags & (O_TEXT | O_BINARY)) < 0))) + CloseHandle(h); /* will not affect errno */ return fd; } diff --git a/src/port/path.c b/src/port/path.c index 6a4efa14b88..dae4eeab099 100644 --- a/src/port/path.c +++ b/src/port/path.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/port/path.c,v 1.32 2004/08/29 04:13:12 momjian Exp $ + * $PostgreSQL: pgsql/src/port/path.c,v 1.33 2004/08/29 05:07:02 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -21,15 +21,15 @@ #ifndef WIN32 -#define IS_DIR_SEP(ch) ((ch) == '/') +#define IS_DIR_SEP(ch) ((ch) == '/') #else -#define IS_DIR_SEP(ch) ((ch) == '/' || (ch) == '\\') +#define IS_DIR_SEP(ch) ((ch) == '/' || (ch) == '\\') #endif #ifndef WIN32 -#define IS_PATH_SEP(ch) ((ch) == ':') +#define IS_PATH_SEP(ch) ((ch) == ':') #else -#define IS_PATH_SEP(ch) ((ch) == ';') +#define IS_PATH_SEP(ch) ((ch) == ';') #endif const static char *relative_path(const char *bin_path, const char *other_path); @@ -52,7 +52,7 @@ first_dir_separator(const char *filename) { char *p; - for (p = (char *)filename; *p; p++) + for (p = (char *) filename; *p; p++) if (IS_DIR_SEP(*p)) return p; return NULL; @@ -66,7 +66,7 @@ first_path_separator(const char *filename) { char *p; - for (p = (char *)filename; *p; p++) + for (p = (char *) filename; *p; p++) if (IS_PATH_SEP(*p)) return p; return NULL; @@ -78,9 +78,10 @@ first_path_separator(const char *filename) char * last_dir_separator(const char *filename) { - char *p, *ret = NULL; + char *p, + *ret = NULL; - for (p = (char *)filename; *p; p++) + for (p = (char *) filename; *p; p++) if (IS_DIR_SEP(*p)) ret = p; return ret; @@ -104,8 +105,8 @@ void make_native_path(char *filename) { #ifdef WIN32 - char *p; - + char *p; + for (p = filename; *p; p++) if (*p == '/') *p = '\\'; @@ -120,6 +121,7 @@ void canonicalize_path(char *path) { #ifdef WIN32 + /* * The Windows command processor will accept suitably quoted paths * with forward slashes, but barfs badly with mixed forward and back @@ -133,18 +135,18 @@ canonicalize_path(char *path) *p = '/'; } - /* In Win32, if you do: - * prog.exe "a b" "\c\d\" - * the system will pass \c\d" as argv[2]. + /* + * In Win32, if you do: prog.exe "a b" "\c\d\" the system will pass + * \c\d" as argv[2]. */ - if (p > path && *(p-1) == '"') - *(p-1) = '/'; + if (p > path && *(p - 1) == '"') + *(p - 1) = '/'; #endif /* - * Removing the trailing slash on a path means we never get ugly double - * slashes. Also, Win32 can't stat() a directory with a trailing slash. - * Don't remove a leading slash, though. + * Removing the trailing slash on a path means we never get ugly + * double slashes. Also, Win32 can't stat() a directory with a + * trailing slash. Don't remove a leading slash, though. */ trim_trailing_separator(path); @@ -153,7 +155,7 @@ canonicalize_path(char *path) */ for (;;) { - int len = strlen(path); + int len = strlen(path); if (len >= 2 && strcmp(path + len - 2, "/.") == 0) { @@ -192,7 +194,7 @@ void get_share_path(const char *my_exec_path, char *ret_path) { const char *p; - + if ((p = relative_path(PGBINDIR, PGSHAREDIR))) make_relative(my_exec_path, p, ret_path); else @@ -209,7 +211,7 @@ void get_etc_path(const char *my_exec_path, char *ret_path) { const char *p; - + if ((p = relative_path(PGBINDIR, SYSCONFDIR))) make_relative(my_exec_path, p, ret_path); else @@ -226,7 +228,7 @@ void get_include_path(const char *my_exec_path, char *ret_path) { const char *p; - + if ((p = relative_path(PGBINDIR, INCLUDEDIR))) make_relative(my_exec_path, p, ret_path); else @@ -243,7 +245,7 @@ void get_pkginclude_path(const char *my_exec_path, char *ret_path) { const char *p; - + if ((p = relative_path(PGBINDIR, PKGINCLUDEDIR))) make_relative(my_exec_path, p, ret_path); else @@ -260,7 +262,7 @@ void get_includeserver_path(const char *my_exec_path, char *ret_path) { const char *p; - + if ((p = relative_path(PGBINDIR, INCLUDEDIRSERVER))) make_relative(my_exec_path, p, ret_path); else @@ -277,7 +279,7 @@ void get_lib_path(const char *my_exec_path, char *ret_path) { const char *p; - + if ((p = relative_path(PGBINDIR, LIBDIR))) make_relative(my_exec_path, p, ret_path); else @@ -294,7 +296,7 @@ void get_pkglib_path(const char *my_exec_path, char *ret_path) { const char *p; - + if ((p = relative_path(PGBINDIR, PKGLIBDIR))) make_relative(my_exec_path, p, ret_path); else @@ -313,7 +315,7 @@ void get_locale_path(const char *my_exec_path, char *ret_path) { const char *p; - + if ((p = relative_path(PGBINDIR, LOCALEDIR))) make_relative(my_exec_path, p, ret_path); else @@ -333,9 +335,10 @@ get_locale_path(const char *my_exec_path, char *ret_path) void set_pglocale_pgservice(const char *argv0, const char *app) { - char path[MAXPGPATH]; - char my_exec_path[MAXPGPATH]; - char env_path[MAXPGPATH + sizeof("PGSYSCONFDIR=")]; /* longer than PGLOCALEDIR */ + char path[MAXPGPATH]; + char my_exec_path[MAXPGPATH]; + char env_path[MAXPGPATH + sizeof("PGSYSCONFDIR=")]; /* longer than + * PGLOCALEDIR */ /* don't set LC_ALL in the backend */ if (strcmp(app, "postgres") != 0) @@ -343,7 +346,7 @@ set_pglocale_pgservice(const char *argv0, const char *app) if (find_my_exec(argv0, my_exec_path) < 0) return; - + #ifdef ENABLE_NLS get_locale_path(my_exec_path, path); bindtextdomain(app, path); @@ -361,7 +364,7 @@ set_pglocale_pgservice(const char *argv0, const char *app) if (getenv("PGSYSCONFDIR") == NULL) { get_etc_path(my_exec_path, path); - + /* set for libpq to use */ snprintf(env_path, sizeof(env_path), "PGSYSCONFDIR=%s", path); canonicalize_path(env_path + 13); @@ -397,7 +400,7 @@ get_home_path(char *ret_path) static void make_relative(const char *my_exec_path, const char *p, char *ret_path) { - char path[MAXPGPATH]; + char path[MAXPGPATH]; StrNCpy(path, my_exec_path, MAXPGPATH); trim_directory(path); @@ -415,7 +418,7 @@ static const char * relative_path(const char *bin_path, const char *other_path) { const char *other_sep = other_path; - + #ifdef WIN32 /* Driver letters match? */ if (isalpha(*bin_path) && bin_path[1] == ':' && @@ -450,14 +453,14 @@ relative_path(const char *bin_path, const char *other_path) #ifndef WIN32 *bin_path != *other_path #else - toupper((unsigned char) *bin_path) != toupper((unsigned char)*other_path) + toupper((unsigned char) *bin_path) != toupper((unsigned char) *other_path) #endif ) break; if (IS_DIR_SEP(*other_path)) - other_sep = other_path + 1; /* past separator */ - + other_sep = other_path + 1; /* past separator */ + bin_path++; other_path++; } @@ -466,7 +469,7 @@ relative_path(const char *bin_path, const char *other_path) if (!*bin_path && !*other_path) return NULL; - /* advance past directory name */ + /* advance past directory name */ while (!IS_DIR_SEP(*bin_path) && *bin_path) bin_path++; @@ -488,8 +491,8 @@ relative_path(const char *bin_path, const char *other_path) static void trim_directory(char *path) { - char *p; - + char *p; + if (path[0] == '\0') return; @@ -508,28 +511,29 @@ trim_directory(char *path) static void trim_trailing_separator(char *path) { - char *p = path + strlen(path); + char *p = path + strlen(path); #ifdef WIN32 + /* - * Skip over network and drive specifiers for win32. - * Set 'path' to point to the last character we must keep. + * Skip over network and drive specifiers for win32. Set 'path' to + * point to the last character we must keep. */ - if (strlen(path) >= 2) - { - if (IS_DIR_SEP(path[0]) && IS_DIR_SEP(path[1])) - { - path += 2; + if (strlen(path) >= 2) + { + if (IS_DIR_SEP(path[0]) && IS_DIR_SEP(path[1])) + { + path += 2; while (*path && !IS_DIR_SEP(*path)) path++; } - else if (isalpha(path[0]) && path[1] == ':') - { - path++; - if (IS_DIR_SEP(path[1])) - path++; - } - } + else if (isalpha(path[0]) && path[1] == ':') + { + path++; + if (IS_DIR_SEP(path[1])) + path++; + } + } #endif /* trim off trailing slashes */ diff --git a/src/port/pgstrcasecmp.c b/src/port/pgstrcasecmp.c index ef3fe0f35ec..a416987bf3d 100644 --- a/src/port/pgstrcasecmp.c +++ b/src/port/pgstrcasecmp.c @@ -16,7 +16,7 @@ * * Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/port/pgstrcasecmp.c,v 1.3 2004/08/29 04:13:12 momjian Exp $ + * $PostgreSQL: pgsql/src/port/pgstrcasecmp.c,v 1.4 2004/08/29 05:07:02 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -33,8 +33,8 @@ pg_strcasecmp(const char *s1, const char *s2) { for (;;) { - unsigned char ch1 = (unsigned char) *s1++; - unsigned char ch2 = (unsigned char) *s2++; + unsigned char ch1 = (unsigned char) *s1++; + unsigned char ch2 = (unsigned char) *s2++; if (ch1 != ch2) { @@ -66,8 +66,8 @@ pg_strncasecmp(const char *s1, const char *s2, size_t n) { while (n-- > 0) { - unsigned char ch1 = (unsigned char) *s1++; - unsigned char ch2 = (unsigned char) *s2++; + unsigned char ch1 = (unsigned char) *s1++; + unsigned char ch2 = (unsigned char) *s2++; if (ch1 != ch2) { diff --git a/src/port/pipe.c b/src/port/pipe.c index d1e2f71ea53..7af1b2afb38 100644 --- a/src/port/pipe.c +++ b/src/port/pipe.c @@ -10,7 +10,7 @@ * must be replaced with recv/send. * * IDENTIFICATION - * $PostgreSQL: pgsql/src/port/pipe.c,v 1.8 2004/08/29 04:13:12 momjian Exp $ + * $PostgreSQL: pgsql/src/port/pipe.c,v 1.9 2004/08/29 05:07:02 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -29,7 +29,7 @@ pgpipe(int handles[2]) if ((s = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) { - ereport(LOG,(errmsg_internal("pgpipe failed to create socket: %ui",WSAGetLastError()))); + ereport(LOG, (errmsg_internal("pgpipe failed to create socket: %ui", WSAGetLastError()))); return -1; } @@ -37,40 +37,40 @@ pgpipe(int handles[2]) serv_addr.sin_family = AF_INET; serv_addr.sin_port = htons(0); serv_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); - if (bind(s, (SOCKADDR *) & serv_addr, len) == SOCKET_ERROR) + if (bind(s, (SOCKADDR *) & serv_addr, len) == SOCKET_ERROR) { - ereport(LOG,(errmsg_internal("pgpipe failed to bind: %ui",WSAGetLastError()))); + ereport(LOG, (errmsg_internal("pgpipe failed to bind: %ui", WSAGetLastError()))); closesocket(s); return -1; } if (listen(s, 1) == SOCKET_ERROR) { - ereport(LOG,(errmsg_internal("pgpipe failed to listen: %ui",WSAGetLastError()))); + ereport(LOG, (errmsg_internal("pgpipe failed to listen: %ui", WSAGetLastError()))); closesocket(s); return -1; } - if (getsockname(s, (SOCKADDR *) & serv_addr, &len) == SOCKET_ERROR) + if (getsockname(s, (SOCKADDR *) & serv_addr, &len) == SOCKET_ERROR) { - ereport(LOG,(errmsg_internal("pgpipe failed to getsockname: %ui",WSAGetLastError()))); + ereport(LOG, (errmsg_internal("pgpipe failed to getsockname: %ui", WSAGetLastError()))); closesocket(s); return -1; } if ((handles[1] = socket(PF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) { - ereport(LOG,(errmsg_internal("pgpipe failed to create socket 2: %ui",WSAGetLastError()))); + ereport(LOG, (errmsg_internal("pgpipe failed to create socket 2: %ui", WSAGetLastError()))); closesocket(s); return -1; } if (connect(handles[1], (SOCKADDR *) & serv_addr, len) == SOCKET_ERROR) { - ereport(LOG,(errmsg_internal("pgpipe failed to connect socket: %ui",WSAGetLastError()))); + ereport(LOG, (errmsg_internal("pgpipe failed to connect socket: %ui", WSAGetLastError()))); closesocket(s); return -1; } if ((handles[0] = accept(s, (SOCKADDR *) & serv_addr, &len)) == INVALID_SOCKET) { - ereport(LOG,(errmsg_internal("pgpipe failed to accept socket: %ui",WSAGetLastError()))); + ereport(LOG, (errmsg_internal("pgpipe failed to accept socket: %ui", WSAGetLastError()))); closesocket(handles[1]); handles[1] = INVALID_SOCKET; closesocket(s); @@ -81,13 +81,15 @@ pgpipe(int handles[2]) } -int piperead(int s, char* buf, int len) +int +piperead(int s, char *buf, int len) { - int ret = recv(s,buf,len,0); + int ret = recv(s, buf, len, 0); + if (ret < 0 && WSAGetLastError() == WSAECONNRESET) /* EOF on the pipe! (win32 socket based implementation) */ ret = 0; return ret; } -#endif +#endif diff --git a/src/port/rand.c b/src/port/rand.c index 7fc3094decb..ca1d621fca7 100644 --- a/src/port/rand.c +++ b/src/port/rand.c @@ -19,13 +19,13 @@ * of any kind. I shall in no event be liable for anything that happens * to anyone/anything when using this software. */ -#define RAND48_SEED_0 (0x330e) -#define RAND48_SEED_1 (0xabcd) -#define RAND48_SEED_2 (0x1234) -#define RAND48_MULT_0 (0xe66d) -#define RAND48_MULT_1 (0xdeec) -#define RAND48_MULT_2 (0x0005) -#define RAND48_ADD (0x000b) +#define RAND48_SEED_0 (0x330e) +#define RAND48_SEED_1 (0xabcd) +#define RAND48_SEED_2 (0x1234) +#define RAND48_MULT_0 (0xe66d) +#define RAND48_MULT_1 (0xdeec) +#define RAND48_MULT_2 (0x0005) +#define RAND48_ADD (0x000b) unsigned short _rand48_seed[3] = { RAND48_SEED_0, @@ -46,11 +46,11 @@ _dorand48(unsigned short xseed[3]) unsigned short temp[2]; accu = (unsigned long) _rand48_mult[0] * (unsigned long) xseed[0] + - (unsigned long) _rand48_add; + (unsigned long) _rand48_add; temp[0] = (unsigned short) accu; /* lower 16 bits */ accu >>= sizeof(unsigned short) * 8; accu += (unsigned long) _rand48_mult[0] * (unsigned long) xseed[1] + - (unsigned long) _rand48_mult[1] * (unsigned long) xseed[0]; + (unsigned long) _rand48_mult[1] * (unsigned long) xseed[0]; temp[1] = (unsigned short) accu; /* middle 16 bits */ accu >>= sizeof(unsigned short) * 8; accu += _rand48_mult[0] * xseed[2] + _rand48_mult[1] * xseed[1] + _rand48_mult[2] * xseed[0]; @@ -63,7 +63,7 @@ long lrand48(void) { _dorand48(_rand48_seed); - return ((long) _rand48_seed[2] << 15) + ((long) _rand48_seed[1] >1); + return ((long) _rand48_seed[2] << 15) + ((long) _rand48_seed[1] > 1); } void @@ -71,7 +71,7 @@ srand48(long seed) { _rand48_seed[0] = RAND48_SEED_0; _rand48_seed[1] = (unsigned short) seed; - _rand48_seed[2] = (unsigned short) (seed >16); + _rand48_seed[2] = (unsigned short) (seed > 16); _rand48_mult[0] = RAND48_MULT_0; _rand48_mult[1] = RAND48_MULT_1; _rand48_mult[2] = RAND48_MULT_2; diff --git a/src/port/snprintf.c b/src/port/snprintf.c index 83f7b5886c7..9f3baec7dca 100644 --- a/src/port/snprintf.c +++ b/src/port/snprintf.c @@ -36,7 +36,7 @@ #include "postgres_fe.h" #ifdef ENABLE_THREAD_SAFETY -#error The replacement snprintf() is not thread-safe. \ +#error The replacement snprintf() is not thread-safe. \ Your platform must have a thread-safe snprintf() to compile with threads. #endif @@ -79,7 +79,7 @@ typedef unsigned long ulong_long; * causing nast effects. **************************************************************/ -/*static char _id[] = "$PostgreSQL: pgsql/src/port/snprintf.c,v 1.3 2004/01/08 17:15:54 momjian Exp $";*/ +/*static char _id[] = "$PostgreSQL: pgsql/src/port/snprintf.c,v 1.4 2004/08/29 05:07:02 momjian Exp $";*/ static char *end; static int SnprfOverflow; diff --git a/src/port/sprompt.c b/src/port/sprompt.c index 25ba313552d..d6b0a71e96c 100644 --- a/src/port/sprompt.c +++ b/src/port/sprompt.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/port/sprompt.c,v 1.7 2004/08/29 04:13:12 momjian Exp $ + * $PostgreSQL: pgsql/src/port/sprompt.c,v 1.8 2004/08/29 05:07:02 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -55,7 +55,7 @@ simple_prompt(const char *prompt, int maxlen, bool echo) #else #ifdef WIN32 HANDLE t = NULL; - LPDWORD t_orig = NULL; + LPDWORD t_orig = NULL; #endif #endif diff --git a/src/port/thread.c b/src/port/thread.c index d5bd47df4bb..96610f9f5a0 100644 --- a/src/port/thread.c +++ b/src/port/thread.c @@ -7,7 +7,7 @@ * * Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/port/thread.c,v 1.24 2004/08/29 04:13:12 momjian Exp $ + * $PostgreSQL: pgsql/src/port/thread.c,v 1.25 2004/08/29 05:07:02 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -36,12 +36,12 @@ * Additional confusion exists because many operating systems that * use pthread_setspecific/pthread_getspecific() also have *_r versions * of standard library functions for compatibility with operating systems - * that require them. However, internally, these *_r functions merely + * that require them. However, internally, these *_r functions merely * call the thread-safe standard library functions. * * For example, BSD/OS 4.3 uses Bind 8.2.3 for getpwuid(). Internally, * getpwuid() calls pthread_setspecific/pthread_getspecific() to return - * static data to the caller in a thread-safe manner. However, BSD/OS + * static data to the caller in a thread-safe manner. However, BSD/OS * also has getpwuid_r(), which merely calls getpwuid() and shifts * around the arguments to match the getpwuid_r() function declaration. * Therefore, while BSD/OS has getpwuid_r(), it isn't required. It also @@ -59,7 +59,7 @@ * Run src/tools/thread to see if your operating system has thread-safe * non-*_r functions. */ - + /* * Wrapper around strerror and strerror_r to use the former if it is @@ -94,8 +94,8 @@ pqStrerror(int errnum, char *strerrbuf, size_t buflen) */ #ifndef WIN32 int -pqGetpwuid(uid_t uid, struct passwd *resultbuf, char *buffer, - size_t buflen, struct passwd **result) +pqGetpwuid(uid_t uid, struct passwd * resultbuf, char *buffer, + size_t buflen, struct passwd ** result) { #if defined(FRONTEND) && defined(ENABLE_THREAD_SAFETY) && defined(HAVE_GETPWUID_R) @@ -103,9 +103,10 @@ pqGetpwuid(uid_t uid, struct passwd *resultbuf, char *buffer, /* POSIX version */ getpwuid_r(uid, resultbuf, buffer, buflen, result); #else + /* * Early POSIX draft of getpwuid_r() returns 'struct passwd *'. - * getpwuid_r(uid, resultbuf, buffer, buflen) + * getpwuid_r(uid, resultbuf, buffer, buflen) */ *result = getpwuid_r(uid, resultbuf, buffer, buflen); #endif @@ -127,12 +128,13 @@ pqGetpwuid(uid_t uid, struct passwd *resultbuf, char *buffer, #ifndef HAVE_GETADDRINFO int pqGethostbyname(const char *name, - struct hostent *resultbuf, + struct hostent * resultbuf, char *buffer, size_t buflen, - struct hostent **result, + struct hostent ** result, int *herrno) { #if defined(FRONTEND) && defined(ENABLE_THREAD_SAFETY) && defined(HAVE_GETHOSTBYNAME_R) + /* * broken (well early POSIX draft) gethostbyname_r() which returns * 'struct hostent *' @@ -147,11 +149,12 @@ pqGethostbyname(const char *name, if (*result != NULL) *herrno = h_errno; - + if (*result != NULL) return 0; else return -1; #endif } + #endif diff --git a/src/port/unsetenv.c b/src/port/unsetenv.c index 1f57c515349..2f29f57521b 100644 --- a/src/port/unsetenv.c +++ b/src/port/unsetenv.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/port/unsetenv.c,v 1.2 2004/08/29 04:13:12 momjian Exp $ + * $PostgreSQL: pgsql/src/port/unsetenv.c,v 1.3 2004/08/29 05:07:02 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -19,22 +19,23 @@ void unsetenv(const char *name) { - char *envstr; + char *envstr; if (getenv(name) == NULL) return; /* no work */ /* - * The technique embodied here works if libc follows the Single Unix Spec - * and actually uses the storage passed to putenv() to hold the environ - * entry. When we clobber the entry in the second step we are ensuring - * that we zap the actual environ member. However, there are some libc - * implementations (notably recent BSDs) that do not obey SUS but copy - * the presented string. This method fails on such platforms. Hopefully - * all such platforms have unsetenv() and thus won't be using this hack. + * The technique embodied here works if libc follows the Single Unix + * Spec and actually uses the storage passed to putenv() to hold the + * environ entry. When we clobber the entry in the second step we are + * ensuring that we zap the actual environ member. However, there are + * some libc implementations (notably recent BSDs) that do not obey + * SUS but copy the presented string. This method fails on such + * platforms. Hopefully all such platforms have unsetenv() and thus + * won't be using this hack. * - * Note that repeatedly setting and unsetting a var using this code - * will leak memory. + * Note that repeatedly setting and unsetting a var using this code will + * leak memory. */ envstr = (char *) malloc(strlen(name) + 2); @@ -49,8 +50,8 @@ unsetenv(const char *name) strcpy(envstr, "="); /* - * This last putenv cleans up if we have multiple zero-length names - * as a result of unsetting multiple things. + * This last putenv cleans up if we have multiple zero-length names as + * a result of unsetting multiple things. */ putenv(envstr); } |
