[slack-ru] /bin/pwd

  • From: Koval Valery <vkoval@xxxxxxxxxxxx>
  • To: slack-ru@xxxxxxxxxxxxx
  • Date: Tue, 23 Mar 2004 08:58:45 +0200

Добрый день.

Замечена некоторая странность в работе pwd при использовании slacktrack
для сборки ПО из исходников (в частности, alsa 0.98).
Суть: при выполнении сборки alsa из под slacktrack 1.17 и ниже при
выполнении configure и далее, где вызывается pwd, ею выдается сообщение
о том, что мол, немогу взять текущий каталог. Выяснил я, что это
сообщение точно ей принадлежит открыв /bin/pwd и найдя эту строку.

Мои действия: для теста на время сборки alsa я делаю простой скрипт на
python, который тоже выдает тек. путь (os.getcwd()) - для замены
/bin/pwd и кладу его _вместо_ pwd.

Результат: всё компилиться нормально и работает!

Прошу высказываться. У кого какие есть соображения?

P.S.
  Полная строка ошибки pwd: cannot get current directory

Кроме того привожу исходник из slackware/source
coreutils/pwd:

>pwd.c:
/* pwd - print current directory
[skip]  */

/* Jim Meyering <meyering@xxxxxxxxx> */

#include <config.h>
#include <stdio.h>
#include <sys/types.h>

#include "system.h"
#include "long-options.h"
#include "error.h"
#include "xgetcwd.h"

/* The official name of this program (e.g., no `g' prefix).  */
#define PROGRAM_NAME "pwd"

#define AUTHORS "Jim Meyering"

/* The name this program was run with. */
char *program_name;

void
usage (int status)
{
  if (status != EXIT_SUCCESS)
    fprintf (stderr, _("Try `%s --help' for more information.\n"),
             program_name);
  else
    {
      printf (_("Usage: %s [OPTION]\n"), program_name);
      fputs (_("\
Print the full filename of the current working directory.\n\
\n\
"), stdout);
      fputs (HELP_OPTION_DESCRIPTION, stdout);
      fputs (VERSION_OPTION_DESCRIPTION, stdout);
      printf (_("\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT);
    }
  exit (status);
}

int
main (int argc, char **argv)
{
  char *wd;

  initialize_main (&argc, &argv);
  program_name = argv[0];
  setlocale (LC_ALL, "");
  bindtextdomain (PACKAGE, LOCALEDIR);
  textdomain (PACKAGE);

  atexit (close_stdout);

  parse_long_options (argc, argv, PROGRAM_NAME, GNU_PACKAGE, VERSION,
                      usage, AUTHORS, (char const *) NULL);

  if (1 < argc)
    error (0, 0, _("ignoring non-option arguments"));

  wd = xgetcwd ();
  if (wd == NULL)
    error (EXIT_FAILURE, errno, _("cannot get current directory"));
  printf ("%s\n", wd);

  exit (EXIT_SUCCESS);
}







>xgetcwd.c:
/* xgetcwd.c -- return current directory with unlimited length
[skip] */

/* Written by David MacKenzie <djm@xxxxxxxxxxxxxx>.  */

#if HAVE_CONFIG_H
# include <config.h>
#endif

#include <stdio.h>
#include <errno.h>
#ifndef errno
extern int errno;
#endif

#include <sys/types.h>
#include <stdlib.h>

#if HAVE_UNISTD_H
# include <unistd.h>
#endif

#if HAVE_GETCWD
char *getcwd ();
#else
# include "pathmax.h"
# define INITIAL_BUFFER_SIZE (PATH_MAX + 1)
char *getwd ();
# define getcwd(Buf, Max) getwd (Buf)
#endif

#include "xalloc.h"
#include "xgetcwd.h"

/* Return the current directory, newly allocated, assuming it fits
   within PATH_MAX bytes -- this is a common system-imposed limit
   on how getcwd works.
   Upon an out-of-memory error, call xalloc_die.
   Upon any other type of error, return NULL.  */

char *
xgetcwd (void)
{
#if HAVE_GETCWD_NULL
  char *cwd = getcwd (NULL, 0);
  if (! cwd && errno == ENOMEM)
    xalloc_die ();
  return cwd;
#else

  /* The initial buffer size for the working directory.  A power of 2
     detects arithmetic overflow earlier, but is not required.  */
# ifndef INITIAL_BUFFER_SIZE
#  define INITIAL_BUFFER_SIZE 128
# endif

  size_t buf_size = INITIAL_BUFFER_SIZE;

  while (1)
    {
      char *buf = xmalloc (buf_size);
      char *cwd = getcwd (buf, buf_size);
      int saved_errno;
      if (cwd)
        return cwd;
      saved_errno = errno;
      free (buf);
      if (saved_errno != ERANGE)
        return NULL;
      buf_size *= 2;
      if (buf_size == 0)
        xalloc_die ();
    }
#endif
}


Other related posts:

  • » [slack-ru] /bin/pwd