~ubuntu-branches/ubuntu/lucid/man-db/lucid-updates

« back to all changes in this revision

Viewing changes to gnulib/lib/lstat.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson
  • Date: 2010-02-17 00:56:08 UTC
  • mfrom: (1.1.10 upstream) (5.2.10 sid)
  • Revision ID: james.westby@ubuntu.com-20100217005608-ko3mxv0qr29iaptz
Tags: 2.5.7-1
* New upstream release:
  - Make man(1) refer to the "Warnings" node in 'info groff' for a list of
    available warning names (closes: #545805).
  - Don't run tests if cross-compiling.
  - Add option to disable justification (closes: #440047).
  - Do what the user probably means when the full path to an executable is
    given as an argument (closes: #505465).
  - Search man<sec><ext> directories in the GNU layout (closes: #519807).
  - Prefer getting a page from the best manual section over getting a page
    in the correct language; I have my reservations about this, but it
    seems to be what people are requesting (closes: #519547).
  - 'man -f' and 'man -k' now pass through any -s option to apropos/whatis
    respectively.
  - All programs now support a MAN_DEBUG environment variable which can be
    used in place of the -d/--debug option. This is useful in some
    situations where a program is being called deep in a process tree.
  - Fix off-by-one error when write returns EAGAIN (thanks, Samuel
    Thibault; closes: #564818).
  - "%s: nothing appropriate." is an error; write it to stderr, not stdout
    (closes: #565255).
  - Don't bother printing error messages for SIGINT and SIGQUIT, since
    these correspond to explicit user actions (closes: #568000).
  - Fix sense of directory check while decompressing (closes: #537434).
  - Always save cat pages in UTF-8 (closes: #446741).
* Convert to source format 3.0 (quilt).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* Work around a bug of lstat on some systems
2
2
 
3
 
   Copyright (C) 1997-1999, 2000-2006, 2008 Free Software Foundation, Inc.
 
3
   Copyright (C) 1997-2006, 2008-2010 Free Software Foundation, Inc.
4
4
 
5
5
   This program is free software: you can redistribute it and/or modify
6
6
   it under the terms of the GNU General Public License as published by
19
19
 
20
20
#include <config.h>
21
21
 
22
 
/* Get the original definition of open.  It might be defined as a macro.  */
23
 
#define __need_system_sys_stat_h
24
 
#include <sys/types.h>
25
 
#include <sys/stat.h>
26
 
#undef __need_system_sys_stat_h
 
22
#if !HAVE_LSTAT
 
23
/* On systems that lack symlinks, our replacement <sys/stat.h> already
 
24
   defined lstat as stat, so there is nothing further to do other than
 
25
   avoid an empty file.  */
 
26
typedef int dummy;
 
27
#else /* HAVE_LSTAT */
 
28
 
 
29
/* Get the original definition of lstat.  It might be defined as a macro.  */
 
30
# define __need_system_sys_stat_h
 
31
# include <sys/types.h>
 
32
# include <sys/stat.h>
 
33
# undef __need_system_sys_stat_h
27
34
 
28
35
static inline int
29
36
orig_lstat (const char *filename, struct stat *buf)
32
39
}
33
40
 
34
41
/* Specification.  */
35
 
#include <sys/stat.h>
 
42
# include <sys/stat.h>
36
43
 
37
 
#include <string.h>
38
 
#include <errno.h>
 
44
# include <string.h>
 
45
# include <errno.h>
39
46
 
40
47
/* lstat works differently on Linux and Solaris systems.  POSIX (see
41
48
   `pathname resolution' in the glossary) requires that programs like
56
63
  size_t len;
57
64
  int lstat_result = orig_lstat (file, sbuf);
58
65
 
59
 
  if (lstat_result != 0 || !S_ISLNK (sbuf->st_mode))
 
66
  if (lstat_result != 0)
60
67
    return lstat_result;
61
68
 
 
69
  /* This replacement file can blindly check against '/' rather than
 
70
     using the ISSLASH macro, because all platforms with '\\' either
 
71
     lack symlinks (mingw) or have working lstat (cygwin) and thus do
 
72
     not compile this file.  0 len should have already been filtered
 
73
     out above, with a failure return of ENOENT.  */
62
74
  len = strlen (file);
63
 
  if (len == 0 || file[len - 1] != '/')
64
 
    return 0;
65
 
 
66
 
  /* FILE refers to a symbolic link and the name ends with a slash.
67
 
     Call stat() to get info about the link's referent.  */
68
 
 
69
 
  /* If stat fails, then we do the same.  */
70
 
  if (stat (file, sbuf) != 0)
71
 
    return -1;
72
 
 
73
 
  /* If FILE references a directory, return 0.  */
74
 
  if (S_ISDIR (sbuf->st_mode))
75
 
    return 0;
76
 
 
77
 
  /* Here, we know stat succeeded and FILE references a non-directory.
78
 
     But it was specified via a name including a trailing slash.
79
 
     Fail with errno set to ENOTDIR to indicate the contradiction.  */
80
 
  errno = ENOTDIR;
81
 
  return -1;
 
75
  if (file[len - 1] != '/' || S_ISDIR (sbuf->st_mode))
 
76
    return 0;
 
77
 
 
78
  /* At this point, a trailing slash is only permitted on
 
79
     symlink-to-dir; but it should have found information on the
 
80
     directory, not the symlink.  Call stat() to get info about the
 
81
     link's referent.  Our replacement stat guarantees valid results,
 
82
     even if the symlink is not pointing to a directory.  */
 
83
  if (!S_ISLNK (sbuf->st_mode))
 
84
    {
 
85
      errno = ENOTDIR;
 
86
      return -1;
 
87
    }
 
88
  return stat (file, sbuf);
82
89
}
 
90
 
 
91
#endif /* HAVE_LSTAT */