#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
+
#include <grub/util/misc.h>
#include <grub/emu/exec.h>
#include <sys/mount.h>
#endif
+#include "save-cwd.h"
+
#if !defined (__GNU__)
static void
strip_extra_slashes (char *dir)
grub_find_device (const char *dir, dev_t dev)
{
DIR *dp;
- char *saved_cwd;
+ struct saved_cwd saved_cwd;
struct dirent *ent;
if (! dir)
if (! dp)
return 0;
- saved_cwd = xgetcwd ();
+ if (save_cwd (&saved_cwd) < 0)
+ {
+ grub_util_error ("%s", _("cannot save the original directory"));
+ closedir (dp);
+ return 0;
+ }
grub_util_info ("changing current directory to %s", dir);
if (chdir (dir) < 0)
{
- free (saved_cwd);
+ free_cwd (&saved_cwd);
closedir (dp);
return 0;
}
if (res)
{
- if (chdir (saved_cwd) < 0)
+ if (restore_cwd (&saved_cwd) < 0)
grub_util_error ("%s",
_("cannot restore the original directory"));
- free (saved_cwd);
+ free_cwd (&saved_cwd);
closedir (dp);
return res;
}
continue;
}
- if (chdir (saved_cwd) < 0)
+ if (restore_cwd (&saved_cwd) < 0)
grub_util_error ("%s", _("cannot restore the original directory"));
- free (saved_cwd);
+ free_cwd (&saved_cwd);
closedir (dp);
return res;
}
}
- if (chdir (saved_cwd) < 0)
+ if (restore_cwd (&saved_cwd) < 0)
grub_util_error ("%s", _("cannot restore the original directory"));
- free (saved_cwd);
+ free_cwd (&saved_cwd);
closedir (dp);
return 0;
}