~ubuntu-branches/ubuntu/precise/wget/precise-proposed

« back to all changes in this revision

Viewing changes to lib/stdio-write.c

  • Committer: Bazaar Package Importer
  • Author(s): Steve Langasek
  • Date: 2011-10-19 00:00:09 UTC
  • mfrom: (2.1.13 sid)
  • Revision ID: james.westby@ubuntu.com-20111019000009-8p33w3wz4b1rdri0
Tags: 1.13-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - Add wget-udeb to ship wget.gnu as alternative to busybox wget
    implementation.
  - Depend on libssl-dev 0.9.8k-7ubuntu4 (LP: #503339)
* Dropped changes, superseded in Debian:
  - Keep build dependencies in main:
    + debian/control: remove info2man build-dep
    + debian/patches/series: disable wget-infopod_generated_manpage
  - Mark wget Multi-Arch: foreign, so packages that aren't of the same arch
    can depend on it.
* Pass --with-ssl=openssl; we don't want to use gnutls, there's no udeb for
  it.
* Add a second build pass for the udeb, so we can build without libidn.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* POSIX compatible FILE stream write function.
2
 
   Copyright (C) 2008-2009 Free Software Foundation, Inc.
 
2
   Copyright (C) 2008-2011 Free Software Foundation, Inc.
3
3
   Written by Bruno Haible <bruno@clisp.org>, 2008.
4
4
 
5
5
   This program is free software: you can redistribute it and/or modify
20
20
/* Specification.  */
21
21
#include <stdio.h>
22
22
 
23
 
/* Replace these functions only if module 'sigpipe' is requested.  */
24
 
#if GNULIB_SIGPIPE
 
23
/* Replace these functions only if module 'nonblocking' or module 'sigpipe' is
 
24
   requested.  */
 
25
#if GNULIB_NONBLOCKING || GNULIB_SIGPIPE
25
26
 
26
27
/* On native Windows platforms, SIGPIPE does not exist.  When write() is
27
28
   called on a pipe with no readers, WriteFile() fails with error
38
39
#  define WIN32_LEAN_AND_MEAN  /* avoid including junk */
39
40
#  include <windows.h>
40
41
 
 
42
#  if GNULIB_NONBLOCKING
 
43
#   define CLEAR_ERRNO \
 
44
      errno = 0;
 
45
#   define HANDLE_ENOSPC \
 
46
          if (errno == ENOSPC && ferror (stream))                             \
 
47
            {                                                                 \
 
48
              int fd = fileno (stream);                                       \
 
49
              if (fd >= 0)                                                    \
 
50
                {                                                             \
 
51
                  HANDLE h = (HANDLE) _get_osfhandle (fd);                    \
 
52
                  if (GetFileType (h) == FILE_TYPE_PIPE)                      \
 
53
                    {                                                         \
 
54
                      /* h is a pipe or socket.  */                           \
 
55
                      DWORD state;                                            \
 
56
                      if (GetNamedPipeHandleState (h, &state, NULL, NULL,     \
 
57
                                                   NULL, NULL, 0)             \
 
58
                          && (state & PIPE_NOWAIT) != 0)                      \
 
59
                        /* h is a pipe in non-blocking mode.                  \
 
60
                           Change errno from ENOSPC to EAGAIN.  */            \
 
61
                        errno = EAGAIN;                                       \
 
62
                    }                                                         \
 
63
                }                                                             \
 
64
            }                                                                 \
 
65
          else
 
66
#  else
 
67
#   define CLEAR_ERRNO
 
68
#   define HANDLE_ENOSPC
 
69
#  endif
 
70
 
 
71
#  if GNULIB_SIGPIPE
 
72
#   define CLEAR_LastError \
 
73
      SetLastError (0);
 
74
#   define HANDLE_ERROR_NO_DATA \
 
75
          if (GetLastError () == ERROR_NO_DATA && ferror (stream))            \
 
76
            {                                                                 \
 
77
              int fd = fileno (stream);                                       \
 
78
              if (fd >= 0                                                     \
 
79
                  && GetFileType ((HANDLE) _get_osfhandle (fd))               \
 
80
                     == FILE_TYPE_PIPE)                                       \
 
81
                {                                                             \
 
82
                  /* Try to raise signal SIGPIPE.  */                         \
 
83
                  raise (SIGPIPE);                                            \
 
84
                  /* If it is currently blocked or ignored, change errno from \
 
85
                     EINVAL to EPIPE.  */                                     \
 
86
                  errno = EPIPE;                                              \
 
87
                }                                                             \
 
88
            }                                                                 \
 
89
          else
 
90
#  else
 
91
#   define CLEAR_LastError
 
92
#   define HANDLE_ERROR_NO_DATA
 
93
#  endif
 
94
 
41
95
#  define CALL_WITH_SIGPIPE_EMULATION(RETTYPE, EXPRESSION, FAILED) \
42
 
  if (ferror (stream))                                                        \
43
 
    return (EXPRESSION);                                                      \
44
 
  else                                                                        \
45
 
    {                                                                         \
46
 
      RETTYPE ret;                                                            \
47
 
      SetLastError (0);                                                       \
48
 
      ret = (EXPRESSION);                                                     \
49
 
      if (FAILED && GetLastError () == ERROR_NO_DATA && ferror (stream))      \
50
 
        {                                                                     \
51
 
          int fd = fileno (stream);                                           \
52
 
          if (fd >= 0                                                         \
53
 
              && GetFileType ((HANDLE) _get_osfhandle (fd)) == FILE_TYPE_PIPE)\
54
 
            {                                                                 \
55
 
              /* Try to raise signal SIGPIPE.  */                             \
56
 
              raise (SIGPIPE);                                                \
57
 
              /* If it is currently blocked or ignored, change errno from     \
58
 
                 EINVAL to EPIPE.  */                                         \
59
 
              errno = EPIPE;                                                  \
60
 
            }                                                                 \
61
 
        }                                                                     \
62
 
      return ret;                                                             \
 
96
  if (ferror (stream))                                                        \
 
97
    return (EXPRESSION);                                                      \
 
98
  else                                                                        \
 
99
    {                                                                         \
 
100
      RETTYPE ret;                                                            \
 
101
      CLEAR_ERRNO                                                             \
 
102
      CLEAR_LastError                                                         \
 
103
      ret = (EXPRESSION);                                                     \
 
104
      if (FAILED)                                                             \
 
105
        {                                                                     \
 
106
          HANDLE_ENOSPC                                                       \
 
107
          HANDLE_ERROR_NO_DATA                                                \
 
108
          ;                                                                   \
 
109
        }                                                                     \
 
110
      return ret;                                                             \
63
111
    }
64
112
 
65
113
#  if !REPLACE_PRINTF_POSIX /* avoid collision with printf.c */
66
 
#   if !DEPENDS_ON_LIBINTL /* avoid collision with intl/printf.c */
67
114
int
68
115
printf (const char *format, ...)
69
116
{
76
123
 
77
124
  return retval;
78
125
}
79
 
#   endif
80
126
#  endif
81
127
 
82
128
#  if !REPLACE_FPRINTF_POSIX /* avoid collision with fprintf.c */