int i, n;
char **origenv;
char **newenv;
+ char *cwd;
FILE *log = fopen(abs_builddir "/commandhelper.log", "w");
if (!log)
}
fprintf(log, "DAEMON:%s\n", getpgrp() == getsid(0) ? "yes" : "no");
- char cwd[1024];
- if (!getcwd(cwd, sizeof(cwd)))
+ if (!(cwd = getcwd(NULL, 0)))
return EXIT_FAILURE;
- if (strlen(cwd) > strlen("/commanddata") &&
+ if (strlen(cwd) > strlen(".../commanddata") &&
STREQ(cwd + strlen(cwd) - strlen("/commanddata"), "/commanddata"))
strcpy(cwd, ".../commanddata");
fprintf(log, "CWD:%s\n", cwd);
+ VIR_FREE(cwd);
VIR_FORCE_FCLOSE(log);
static int checkoutput(const char *testname)
{
int ret = -1;
- char cwd[1024];
char *expectname = NULL;
char *expectlog = NULL;
char *actualname = NULL;
char *actuallog = NULL;
- if (!getcwd(cwd, sizeof(cwd)))
- return -1;
-
if (virAsprintf(&expectname, "%s/commanddata/%s.log", abs_srcdir,
testname) < 0)
goto cleanup;
int (*func)(void))
{
int ret;
- char cwd[PATH_MAX];
+ bool abs_srcdir_cleanup = false;
#if TEST_OOM
int approxAlloc = 0;
int n;
#endif
abs_srcdir = getenv("abs_srcdir");
- if (!abs_srcdir)
- abs_srcdir = getcwd(cwd, sizeof(cwd));
+ if (!abs_srcdir) {
+ abs_srcdir = getcwd(NULL, 0);
+ abs_srcdir_cleanup = true;
+ }
if (!abs_srcdir)
exit(EXIT_AM_HARDFAIL);
ret = (func)();
#endif
+ if (abs_srcdir_cleanup)
+ VIR_FREE(abs_srcdir);
virResetLastError();
if (!virTestGetVerbose()) {
int i;
}
-#ifndef WIN32
/*
* "cd" command
*/
return ret;
}
-#endif
-
-#ifndef WIN32
/*
* "pwd" command
*/
cmdPwd(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
{
char *cwd;
- size_t path_max;
- bool err = true;
-
- path_max = (size_t) PATH_MAX + 2;
- cwd = vshMalloc (ctl, path_max);
- while (cwd) {
- err = getcwd (cwd, path_max) == NULL;
- if (!err || errno != ERANGE)
- break;
-
- path_max *= 2;
- cwd = vshRealloc (ctl, cwd, path_max);
- }
+ bool ret = true;
- if (err)
+ cwd = getcwd(NULL, 0);
+ if (!cwd) {
vshError(ctl, _("pwd: cannot get current directory: %s"),
strerror(errno));
- else
+ ret = false;
+ } else {
vshPrint (ctl, _("%s\n"), cwd);
+ VIR_FREE(cwd);
+ }
- VIR_FREE(cwd);
- return !err;
+ return ret;
}
-#endif
/*
* "echo" command
};
static const vshCmdDef virshCmds[] = {
-#ifndef WIN32
{"cd", cmdCd, opts_cd, info_cd},
-#endif
{"echo", cmdEcho, opts_echo, info_echo},
{"exit", cmdQuit, NULL, info_quit},
{"help", cmdHelp, opts_help, info_help},
-#ifndef WIN32
{"pwd", cmdPwd, NULL, info_pwd},
-#endif
{"quit", cmdQuit, NULL, info_quit},
{NULL, NULL, NULL, NULL}
};