On 2013-11-18 15:01:42 +0000, Haribabu kommi wrote: > > /* > + * Returns the malloced string of containing current working directory. > + * The caller has to take care of freeing the memory. > + * On failure exits with error code. > + */ > +static char * > +get_current_working_dir() > +{ > + char *buf; > + size_t buflen; > + > + buflen = MAXPGPATH; > + for (;;) > + { > + buf = pg_malloc(buflen); > + if (getcwd(buf, buflen)) > + break; > + else if (errno == ERANGE) > + { > + pg_free(buf); > + buflen *= 2; > + continue; > + } > + else > + { > + pg_free(buf); > + fprintf(stderr, > + _("%s: could not get current working > directory: %s\n"), > + progname, strerror(errno)); > + exit(1); > + } > + } > + > + return buf; > +} > + > +/* > + * calculates the absolute path for the given path. The output absolute path > + * is a malloced string. The caller needs to take care of freeing the memory. > + */ > +static char * > +get_absolute_path(const char *input_path) > +{ > + char *pwd = NULL; > + char *abspath = NULL; > + > + /* Getting the present working directory */ > + pwd = get_current_working_dir(); > + > + if (chdir(input_path) < 0) > + { > + /* Directory doesn't exist */ > + if (errno == ENOENT) > + return NULL; > + > + fprintf(stderr, _("%s: could not change directory to \"%s\": > %s\n"), > + progname, input_path, strerror(errno)); > + exit(1); > + } > + > + abspath = get_current_working_dir(); > + > + /* Returning back to old working directory */ > + if (chdir(pwd) < 0) > + { > + fprintf(stderr, _("%s: could not change directory to \"%s\": > %s\n"), > + progname, pwd, strerror(errno)); > + exit(1); > + } > + > + pg_free(pwd); > + return abspath; > +}
This looks like it should be replaced by moving make_absolute_path from pg_regress.c to path.[ch] and then use that. Greetings, Andres Freund -- Andres Freund http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers